scottrippey / next-router-mock

Mock implementation of the Next.js Router

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fails on next 12.1.6

karl-run opened this issue · comments

I'm upgrading my app from 12.1.2 to 12.1.6 and it seems some internal next paths have changed, causing the patching to fail.

When I run my tests:

    Cannot find module 'next/dist/server/normalize-page-path' from 'node_modules/next-router-mock/dist/dynamic-routes/extensions-11.1.js'

    Require stack:
      node_modules/next-router-mock/dist/dynamic-routes/extensions-11.1.js
      jest.setup.js

      at Resolver.resolveModule (node_modules/jest-resolve/build/resolver.js:324:11)
      at Object.<anonymous> (node_modules/next-router-mock/src/dynamic-routes/extensions-11.1.ts:9:1)

Edit: I narrowed it down a bit, with next 12.1.5 still works as expected.

After comparing the changes between 12.1.5 and 12.1.6 I can see that the file in question has been moved.

From:
packages/next/server/normalize-page-path.ts
To:
packages/next/shared/lib/page-path/normalize-page-path.ts

Ah, this was a case of me not reading the docs.

In my jest.setup.js, changing

- import 'next-router-mock/dynamic-routes';
+ import 'next-router-mock/dynamic-routes/next-12';

fixes my issue. Sorry!

FWIW, with the latest publish 0.7.0, you don't need the /next-12 path. You can import like:

import { createDynamicRouteParser } from "next-router-mock/dynamic-routes";

See the newly updated docs, to see how to upgrade.