next-test-api-route-handler

⚡ Confidently unit and integration test your Next.js API routes/handlers in an isolated Next.js-like environment

MIT License

Downloads
150.8K
Stars
255
Committers
10

Bot releases are visible (Hide)

next-test-api-route-handler - v4.0.8 Latest Release

Published by Xunnamius 4 months ago

4.0.8 (2024-06-10)

⚙️ Build system

  • Revert conventional-changelog-cli update (9967120)
  • Update documentation generator (43eec53)
next-test-api-route-handler - v4.0.7

Published by Xunnamius 6 months ago

4.0.7 (2024-04-17)

⚙️ Build system

  • babel: update core-js to 3.37 (b6b5164)
  • readme: add section on jsdom support (a48555f)
next-test-api-route-handler - v4.0.6

Published by Xunnamius 6 months ago

4.0.6 (2024-04-12)

🪄 Fixes

  • src: extend backwards compatibility to msw@1; remove optional msw peer dependency (347d7ef)
next-test-api-route-handler - v4.0.5

Published by Xunnamius 8 months ago

4.0.5 (2024-03-03)

🪄 Fixes

  • src: replace request spread with explicit options (633a046) closes #1011, #983
next-test-api-route-handler - v4.0.4

Published by Xunnamius 8 months ago

4.0.4 (2024-03-02)

🪄 Fixes

  • src: allow relative url strings passed via url shorthand for App Router (01b86b6) closes #1000
  • src: prevent recursive redirection with undici/whatwg fetch (22bb716) closes #993
  • src: replace AppRouteUserlandModule with looser type (502e666) closes #1006, #1005
next-test-api-route-handler - v4.0.3

Published by Xunnamius 9 months ago

4.0.3 (2024-01-18)

🪄 Fixes

  • src: ensure ephemeral test servers only listen on localhost (d7774b3)
  • src: forcefully close all connections after closing test server (fixes #962) (d03ca21)
next-test-api-route-handler - v4.0.2

Published by Xunnamius 9 months ago

4.0.2 (2024-01-16)

🪄 Fixes

  • src: add missing metadata not revealed by type information (90ff665)
  • src: force normalization of request URLs passed to app handler (8400a19)
next-test-api-route-handler - v4.0.1

Published by Xunnamius 9 months ago

4.0.1 (2024-01-16)

🪄 Fixes

  • src: pass Next.js more accurate app route metadata (09389fe)
next-test-api-route-handler - v4.0.0

Published by Xunnamius 9 months ago

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 by NtarhInit,
    NtarhInitAppRouter, and NtarhInitPagesRouter.

  • The handler option of testApiHandler (i.e.
    testApiHandler({ handler })) has been renamed to pagesHandler. It is
    otherwise functionally equivalent.

    Those migrating from NTARH@<4, the process should be as simple as renaming
    handler to pagesHandler in your tests and getting on with your life.

  • requestPatcher, reponsePatcher, and paramsPatcher options
    of testApiHandler({ ... }) can now be asynchronous and return Promises.
    paramsPatcher can additionally return a brand new params object that will
    overwrite the old one rather than merely augmenting it.

  • testApiHandler({ ... }) now accepts the appHandler option.
    When this option is provided, the function signatures of the following options
    shift to support standard Request/Response parameters and return types where
    appropriate: requestPatcher, responsePatcher, and paramsPatcher. See the
    docs, or intellisense, for more details.

  • requestPatcher, reponsePatcher, and paramsPatcher options
    of testApiHandler({ ... }) 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
    [email protected]. Therefore, versions of Next.js older than 14.0.4 explicitly
    unsupported
    when using the appHandler 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 of testApiHandler (i.e.
    testApiHandler({ pagesHandler })) will not accept edge runtime routes. To
    test your edge runtime routes, use the appHandler 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 NextApiHandlers (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)
next-test-api-route-handler - v3.2.0

Published by Xunnamius 10 months ago

3.2.0 (2024-01-04)

✨ Features

  • Update headers for msw@2 compatibility (93b8a3c) closes #916
next-test-api-route-handler - v3.1.10

Published by Xunnamius 12 months ago

3.1.10 (2023-11-04)

⚙️ Build system

  • Add core-js polyfills and have mercy on aging node versions (a9d136b)
  • Modernize tooling (db0223e)
  • Upgrade typescript-babel toolchain to nodenext (e457064) closes #908
next-test-api-route-handler - v4.0.0-canary.2

Published by Xunnamius 12 months ago

4.0.0-canary.2 (2023-11-04)

⚙️ Build system

  • Add core-js polyfills and have mercy on aging node versions (a9d136b)
  • Modernize tooling (db0223e)
  • Upgrade typescript-babel toolchain to nodenext (e457064) closes #908
next-test-api-route-handler - v3.1.9

Published by Xunnamius about 1 year ago

3.1.9 (2023-10-03)

🪄 Fixes

next-test-api-route-handler - v3.1.8

Published by Xunnamius almost 2 years ago

3.1.8 (2023-01-03)

⚙️ Build system

  • readme: update maintainence badge and audit dependencies (2a4ae05)
next-test-api-route-handler - v3.1.7

Published by Xunnamius about 2 years ago

3.1.7 (2022-07-27)

⚙️ Build system

  • package: update dependencies (4af52f4)
next-test-api-route-handler - v3.1.6

Published by Xunnamius over 2 years ago

3.1.6 (2022-06-30)

🪄 Fixes

  • Ensure non-object "headers" fetch argument is not mangled when mixing in default headers (6e94142)
next-test-api-route-handler - v3.1.5

Published by Xunnamius over 2 years ago

3.1.5 (2022-06-26)

🪄 Fixes

  • Fix MSW bypass override instructions and unit test (405f84d)
next-test-api-route-handler - v3.1.4

Published by Xunnamius over 2 years ago

3.1.4 (2022-06-26)

⚙️ Build system

  • readme: update MSW bypass override instructions under "test" entry in README (b05e112)
next-test-api-route-handler - v3.1.3

Published by Xunnamius over 2 years ago

3.1.3 (2022-05-21)

⚙️ Build system

  • package: update dev-dependencies (36a2c44)
next-test-api-route-handler - v3.1.2

Published by Xunnamius over 2 years ago

3.1.2 (2022-03-23)

⚙️ Build system

  • package: update dependencies (065b445)