Releases: Xunnamius/next-test-api-route-handler
v4.0.4
v4.0.3
v4.0.2
v4.0.1
v4.0.0
4.0.0 (2024-01-15)
💥 BREAKING CHANGES 💥
-
Request URLs (e.g.
req.url
) default to
"ntarh://testApiHandler/"
.This is instead of the old localhost string with the random port number, which
is an implementation detail that should not have been exposed to end developers. -
NtarhParameters
has been superseded byNtarhInit
,
NtarhInitAppRouter
, andNtarhInitPagesRouter
. -
The
handler
option oftestApiHandler
(i.e.
testApiHandler({ handler })
) has been renamed topagesHandler
. It is
otherwise functionally equivalent.Those migrating from NTARH@<4, the process should be as simple as renaming
handler
topagesHandler
in your tests and getting on with your life. -
requestPatcher
,reponsePatcher
, andparamsPatcher
options
oftestApiHandler({ ... })
can now be asynchronous and return Promises.
paramsPatcher
can additionally return a brand newparams
object that will
overwrite the old one rather than merely augmenting it. -
testApiHandler({ ... })
now accepts theappHandler
option.
When this option is provided, the function signatures of the following options
shift to support standardRequest
/Response
parameters and return types where
appropriate:requestPatcher
,responsePatcher
, andparamsPatcher
. See the
docs, or intellisense, for more details. -
requestPatcher
,reponsePatcher
, andparamsPatcher
options
oftestApiHandler({ ... })
no longer support parenthetical shorthand notation.
For example, the following will cause a type error:
testApiHandler({ paramsPatcher: (params) => (params.id = "some-id") })
. -
This version of NTARH is now actively tracking a second Next.js
internal export, one that is not guaranteed to be available before
next@14.0.4
. Therefore, versions of Next.js older than 14.0.4 explicitly
unsupported when using theappHandler
option. On the other hand,
pagesHandler
will always work regardless of Next.js version until Vercel
eventually removes the Pages Router functionality entirely. -
The
pagesHandler
option oftestApiHandler
(i.e.
testApiHandler({ pagesHandler })
) will not accept edge runtime routes. To
test your edge runtime routes, use theappHandler
option instead. -
Minimum supported Node.js version is now 18.18.2
-
Node-fetch has been replaced by Node's native fetch
function. There may be subtle API changes between the two.
✨ Features
- Land initial App Router support (e2d8865) closes #938, #773
- Retire use of node-fetch (5574831) closes #946
- src: warn when invoking testApiHandler with invalid property combos (db599ac)
🪄 Fixes
- Loosen type checking for
NextApiHandler
s (fdfec8c) - src: ensure all results of calling ::json on Requests and Responses are summoned into our realm (5c5f9a4)
- src: ensure AsyncLocalStorage is available globally (might fix #875) (43680d9)
src: ensure global fetch is restored after testApiHandler terminates (75d4e1f)- src: forcefully coerce request.body into a ReadableStream (f715331)
- src: hoist globalThis.AsyncLocalStorage initialization to be as soon as possible (85bb8fa)
- src: normalize pagesHandler into NextApiHandler (esm<->cjs interop) (0133e11)
- Use more accurate return type for app router patchers (62f1d0b)
⚙️ Build system
- husky: ensure hooks do not run on rebase (913cbd0)
- package: bump minimum supported node versions to maintained (702cb44)
- package: remove outdated properties (dc23723)
🧙🏿 Refactored
- src: ensure request url is consistent across router types (d72ae87)