{"id":13454945,"url":"https://github.com/Xunnamius/next-test-api-route-handler","last_synced_at":"2025-03-24T07:32:15.555Z","repository":{"id":36980846,"uuid":"301281706","full_name":"Xunnamius/next-test-api-route-handler","owner":"Xunnamius","description":"🔧 Confidently unit and integration test your Next.js API routes/handlers in an isolated Next.js-like environment with buttery-smooth DX","archived":false,"fork":false,"pushed_at":"2025-03-21T19:24:38.000Z","size":25406,"stargazers_count":305,"open_issues_count":3,"forks_count":15,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-23T13:08:27.643Z","etag":null,"topics":["api","async","handler","next","next-js","nextapirequest","nextapiresponse","resolver","route","route-handler"],"latest_commit_sha":null,"homepage":"https://npm.im/next-test-api-route-handler","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Xunnamius.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.md","support":".github/SUPPORT.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["Xunnamius"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2020-10-05T03:17:09.000Z","updated_at":"2025-03-21T01:36:49.000Z","dependencies_parsed_at":"2023-10-03T13:57:49.399Z","dependency_job_id":"5f906365-86e1-4f61-96db-3cbd97e4751c","html_url":"https://github.com/Xunnamius/next-test-api-route-handler","commit_stats":{"total_commits":1157,"total_committers":11,"mean_commits":"105.18181818181819","dds":0.2065687121866897,"last_synced_commit":"b9adb3bd738ca058679e776bd955c97b4cc22140"},"previous_names":[],"tags_count":175,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xunnamius%2Fnext-test-api-route-handler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xunnamius%2Fnext-test-api-route-handler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xunnamius%2Fnext-test-api-route-handler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xunnamius%2Fnext-test-api-route-handler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Xunnamius","download_url":"https://codeload.github.com/Xunnamius/next-test-api-route-handler/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245227549,"owners_count":20580898,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","async","handler","next","next-js","nextapirequest","nextapiresponse","resolver","route","route-handler"],"created_at":"2024-07-31T08:00:59.676Z","updated_at":"2025-03-24T07:32:15.539Z","avatar_url":"https://github.com/Xunnamius.png","language":"TypeScript","readme":"\u003c!-- symbiote-template-region-start 1 --\u003e\n\n\u003cp align=\"center\" width=\"100%\"\u003e\n  \u003cimg width=\"300\" src=\"https://raw.githubusercontent.com/Xunnamius/next-test-api-route-handler/refs/heads/main/logo.png\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\" width=\"100%\"\u003e\n\u003c!-- symbiote-template-region-end --\u003e\nConfidently test your Next.js API routes in an isolated Next-like environment\n\u003c!-- symbiote-template-region-start 2 --\u003e\n\u003c/p\u003e\n\n\u003chr /\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n[![Black Lives Matter!][x-badge-blm-image]][x-badge-blm-link]\n[![Last commit timestamp][x-badge-lastcommit-image]][x-badge-repo-link]\n[![Codecov][x-badge-codecov-image]][x-badge-codecov-link]\n[![Source license][x-badge-license-image]][x-badge-license-link]\n[![Uses Semantic Release!][x-badge-semanticrelease-image]][x-badge-semanticrelease-link]\n\n[![NPM version][x-badge-npm-image]][x-badge-npm-link]\n[![Monthly Downloads][x-badge-downloads-image]][x-badge-downloads-link]\n\n\u003c/div\u003e\n\n\u003cbr /\u003e\n\n# next-test-api-route-handler\n\n\u003c!-- symbiote-template-region-end --\u003e\n\n**Trying to unit test your Next.js API routes?** Tired of hacking something\ntogether with express or node-mocks-http or writing a bunch of boring dummy\ninfra just to get some passing tests? And what does a \"passing test\" mean anyway\nwhen your handlers aren't receiving _actual_ [`NextRequest`][1] objects and\naren't being run by Next.js itself?\n\n\u003e Next.js patches the global `fetch` function, for instance. If your tests\n\u003e aren't doing the same, you're making space for bugs!\n\nIs it vexing that everything explodes when your [App Router][2] handlers call\n`headers()` or `cookies()` or any of the other route-specific [helper\nfunctions][3]? Or maybe you want your [Pages Router][4] handlers to receive\n_actual_ [`NextApiRequest`][5] and [`NextApiResponse`][5] objects?\n\nSound interesting? Then want no longer! 🤩\n\n[`next-test-api-route-handler`][x-badge-repo-link] (NTARH) uses Next.js's\ninternal resolvers to precisely emulate route handling. To guarantee stability,\nthis package is [automatically tested][6] against [each release of Next.js][7]\nand Node.js. Go forth and test confidently!\n\n\u003cbr /\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n✨ \u003ca href=\"https://github.com/vercel/next.js\"\u003e\u003cimg\nsrc=\"https://xunn.at/ntarh-compat\" /\u003e\u003c/a\u003e ✨\n\n\u003csub\u003eNote that App Router support begins with `next@14.0.4` ([why?][8])\u003c/sub\u003e\n\n\u003c/div\u003e\n\n\u003cbr /\u003e\n\n\u003c!-- symbiote-template-region-start 3 --\u003e\n\n---\n\n\u003c!-- remark-ignore-start --\u003e\n\u003c!-- symbiote-template-region-end --\u003e\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\n- [Install](#install)\n- [Usage](#usage)\n  - [Quick Start: App Router](#quick-start-app-router)\n  - [Quick Start: Edge Runtime](#quick-start-edge-runtime)\n  - [Quick Start: Pages Router](#quick-start-pages-router)\n- [API](#api)\n  - [`appHandler`](#apphandler)\n  - [`pagesHandler`](#pageshandler)\n  - [`test`](#test)\n  - [`rejectOnHandlerError`](#rejectonhandlererror)\n  - [`requestPatcher` (`url`)](#requestpatcher-url)\n  - [`responsePatcher`](#responsepatcher)\n  - [`paramsPatcher` (`params`)](#paramspatcher-params)\n- [Examples](#examples)\n  - [Using the App Router](#using-the-app-router)\n  - [Using the Pages Router](#using-the-pages-router)\n- [Appendix](#appendix)\n  - [Limitations with App Router and Edge Runtime Emulation](#limitations-with-app-router-and-edge-runtime-emulation)\n  - [Legacy Runtime Support](#legacy-runtime-support)\n  - [Jsdom Support](#jsdom-support)\n  - [Inspiration](#inspiration)\n  - [Published Package Details](#published-package-details)\n  - [License](#license)\n- [Contributing and Support](#contributing-and-support)\n  - [Contributors](#contributors)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- symbiote-template-region-start 4 --\u003e\n\u003c!-- remark-ignore-end --\u003e\n\n\u003cbr /\u003e\n\n## Install\n\n\u003c!-- symbiote-template-region-end --\u003e\n\nTo install:\n\n```shell\nnpm install --save-dev next-test-api-route-handler\n```\n\n\u003e See [the appendix][9] for legacy Next.js support options.\n\n\u003e Also see [the appendix][10] if you're using `jest` and\n\u003e `jest-environment-jsdom`.\n\n\u003cbr /\u003e\n\n## Usage\n\n\u003e [!IMPORTANT]\n\u003e\n\u003e **NTARH must always be the first import in your test file.** This is due to\n\u003e the way Next.js is written and distributed. See [the appendix][11] for\n\u003e technical details.\n\n```typescript\n// ESM\nimport { testApiHandler } from 'next-test-api-route-handler'; // ◄ Must be first\n\n... all other imports ...\n```\n\n```javascript\n// CJS\nconst { testApiHandler } = require('next-test-api-route-handler'); // ◄ Must be first\n\n... all other imports ...\n```\n\nIf you're using fancy import sorting like [eslint-plugin-import's \"order\"\nrule][102], import NTARH as a [side-effect][x-pkg-side-effects-key] first, then\nperform the real import later:\n\n```javascript\nimport 'next-test-api-route-handler';\n\n... all other imports ordered before NTARH ...\nimport { testApiHandler } from 'next-test-api-route-handler';\n... all other imports ordered after NTARH ...\n```\n\n### Quick Start: App Router\n\n```typescript\n/* File: test/unit.test.ts */\n\nimport { testApiHandler } from 'next-test-api-route-handler'; // ◄ Must be first import\n// Import the handler under test from the app directory\nimport * as appHandler from '../app/your-endpoint/route';\n\nit('does what I want', async () =\u003e {\n  await testApiHandler({\n    appHandler,\n    // requestPatcher is optional\n    requestPatcher(request) {\n      request.headers.set('key', process.env.SPECIAL_TOKEN);\n    },\n    // responsePatcher is optional\n    async responsePatcher(response) {\n      const json = await response.json();\n      return Response.json(\n        json.apiSuccess ? { hello: 'world!' } : { goodbye: 'cruel world' }\n      );\n    },\n    async test({ fetch }) {\n      const res = await fetch({ method: 'POST', body: 'dummy-data' });\n      await expect(res.json()).resolves.toStrictEqual({ hello: 'world!' }); // ◄ Passes!\n    }\n  });\n});\n```\n\n### Quick Start: Edge Runtime\n\n```typescript\n/* File: test/unit.test.ts */\n\nimport { testApiHandler } from 'next-test-api-route-handler'; // ◄ Must be first import\n// Import the handler under test from the app directory\nimport * as edgeHandler from '../app/your-edge-endpoint/route';\n\nit('does what I want', async function () {\n  // NTARH supports optionally typed response data via TypeScript generics:\n  await testApiHandler\u003c{ success: boolean }\u003e({\n    // Only appHandler supports edge functions. The pagesHandler prop does not!\n    appHandler: edgeHandler,\n    // requestPatcher is optional\n    requestPatcher(request) {\n      return new Request(request, {\n        body: dummyReadableStream,\n        duplex: 'half'\n      });\n    },\n    async test({ fetch }) {\n      // The next line would cause TypeScript to complain:\n      // const { luck: success } = await (await fetch()).json();\n      await expect((await fetch()).json()).resolves.toStrictEqual({\n        success: true // ◄ Passes!\n      });\n    }\n  });\n});\n```\n\n### Quick Start: Pages Router\n\n```typescript\n/* File: test/unit.test.ts */\n\nimport { testApiHandler } from 'next-test-api-route-handler'; // ◄ Must be first import\n// Import the handler under test and its config from the pages/api directory\nimport * as pagesHandler from '../pages/api/your-endpoint';\n\nit('does what I want', async () =\u003e {\n  // NTARH supports optionally typed response data via TypeScript generics:\n  await testApiHandler\u003c{ hello: string }\u003e({\n    pagesHandler,\n    requestPatcher: (req) =\u003e {\n      req.headers = { key: process.env.SPECIAL_TOKEN };\n    },\n    test: async ({ fetch }) =\u003e {\n      const res = await fetch({ method: 'POST', body: 'data' });\n      // The next line would cause TypeScript to complain:\n      // const { goodbye: hello } = await res.json();\n      const { hello } = await res.json();\n      expect(hello).toBe('world'); // ◄ Passes!\n    }\n  });\n});\n```\n\n\u003cbr /\u003e\n\n## API\n\nNTARH exports a single function, `testApiHandler(options)`, that accepts an\n`options` object as its only parameter.\n\nAt minimum, `options` must contain the following properties:\n\n- At least one of the `appHandler` or `pagesHandler` options, but not both.\n- The `test` option.\n\nFor example:\n\n\u003e [!CAUTION]\n\u003e\n\u003e Ensuring `testApiHandler` is imported [_before_][12] any Next.js package (like\n\u003e `'next/headers'` below) is crucial to the proper function of NTARH. Doing\n\u003e otherwise will result in undefined behavior.\n\n```typescript\nimport { testApiHandler } from 'next-test-api-route-handler';\nimport { headers } from 'next/headers';\n\nawait testApiHandler({\n  appHandler: {\n    dynamic: 'force-dynamic',\n    async GET(_request) {\n      return Response.json(\n        {\n          // Yep, those fancy helper functions work too!\n          hello: (await headers()).get('x-hello')\n        },\n        { status: 200 }\n      );\n    }\n  },\n  async test({ fetch }) {\n    await expect(\n      (await fetch({ headers: { 'x-hello': 'world' } })).json()\n    ).resolves.toStrictEqual({\n      hello: 'world'\n    });\n  }\n});\n```\n\n\u003cbr /\u003e\n\n### `appHandler`\n\n\u003e ⪢ API reference: [`appHandler`][13]\n\nThe actual route handler under test (usually imported from `app/*`). It should\nbe an object and/or exported module containing one or more [valid uppercase HTTP\nmethod names][14] as keys, each with an [async handling function][15] that\naccepts a [`NextRequest`][1] and [\"segment data\"][16] (i.e. `{ params }`) as its\ntwo parameters. The object or module can also export [other configuration\nsettings recognized by Next.js][17].\n\n```typescript\nawait testApiHandler({\n  params: { id: 5 },\n  appHandler: {\n    async POST(request, { params: { id } }) {\n      return Response.json(\n        { special: request.headers.get('x-special-header'), id },\n        { status: 200 }\n      );\n    }\n  },\n  async test({ fetch }) {\n    expect((await fetch({ method: 'POST' })).status).toBe(200);\n\n    const result2 = await fetch({\n      method: 'POST',\n      headers: { 'x-special-header': 'x' }\n    });\n\n    expect(result2.json()).toStrictEqual({ special: 'x', id: 5 });\n  }\n});\n```\n\nSee also: [`rejectOnHandlerError`][18] and the section [Working Around Next.js\n`fetch` Patching][19].\n\n\u003cbr /\u003e\n\n### `pagesHandler`\n\n\u003e ⪢ API reference: [`pagesHandler`][20]\n\nThe actual route handler under test (usually imported from `pages/api/*`). It\nshould be an async function that accepts [`NextApiRequest`][5] and\n[`NextApiResponse`][5] objects as its two parameters.\n\n```typescript\nawait testApiHandler({\n  params: { id: 5 },\n  pagesHandler: (req, res) =\u003e res.status(200).send({ id: req.query.id }),\n  test: async ({ fetch }) =\u003e\n    expect((await fetch({ method: 'POST' })).json()).resolves.toStrictEqual({\n      id: 5\n    })\n});\n```\n\nSee also: [`rejectOnHandlerError`][18].\n\n\u003cbr /\u003e\n\n### `test`\n\n\u003e ⪢ API reference: [`test`][21]\n\nAn async or promise-returning function wherein test assertions can be run. This\nfunction receives one destructured parameter: `fetch`, which is a wrapper around\nNode's [global fetch][22] function. Use this to send HTTP requests to the\nhandler under test.\n\n\u003e [!CAUTION]\n\u003e\n\u003e Note that `fetch`'s `resource` parameter, _i.e. [the first parameter in\n\u003e `fetch(...)`][23]_, is omitted.\n\n#### ⚙ Handling Redirections\n\nStarting with version `4.0.4`, NTARH sets the [`fetch(...)` `options`][24]\nparameter's [`redirect` property to `'manual'`][25] by default. This prevents\nthe WHATWG/undici `fetch` function from throwing a\n`fetch failed`/`redirect count exceeded` error.\n\nIf you want to change this value, call `fetch` with your own custom `options`\nparameter, e.g. `fetch({ redirect: 'error' })`.\n\n#### ⚙ Compatibility with Mock Service Worker\n\nStarting with version `4.0.0`, NTARH ships with [Mock Service Worker (msw)][26]\nsupport by adding the [`x-msw-intention: \"bypass\"`][27] and\n`x-msw-bypass: \"true\"` headers to all requests.\n\nIf necessary, you can override this behavior by setting the appropriate headers\nto some other value (e.g. `\"none\"`) via `fetch`'s `customInit` parameter (not\n`requestPatcher`). This comes in handy when testing functionality like\n[arbitrary response redirection][28] (or via the [Pages Router][29]).\n\nFor example:\n\n```typescript\nimport { testApiHandler } from 'next-test-api-route-handler';\nimport { http, passthrough, HttpResponse } from 'msw';\nimport { setupServer } from 'msw/node';\n\nconst server = setupServer(/* ... */);\n\nbeforeAll(() =\u003e server.listen({ onUnhandledRequest: 'error' }));\n\nafterEach(() =\u003e {\n  server.resetHandlers();\n});\n\nafterAll(() =\u003e server.close());\n\nit('redirects a shortened URL to the real URL', async () =\u003e {\n  expect.hasAssertions();\n\n  // e.g. https://xunn.at/gg =\u003e https://www.google.com/search?q=next-test-api-route-handler\n  // shortId would be \"gg\"\n  // realLink would be https://www.google.com/search?q=next-test-api-route-handler\n\n  const { shortId, realLink } = getUriEntry();\n  const realUrl = new URL(realLink);\n\n  await testApiHandler({\n    appHandler,\n    params: { shortId },\n    test: async ({ fetch }) =\u003e {\n      server.use(\n        http.get('*', async ({ request }) =\u003e {\n          return request.url === realUrl.href\n            ? HttpResponse.json({ it: 'worked' }, { status: 200 })\n            : passthrough();\n        })\n      );\n\n      const res = await fetch({\n        headers: { 'x-msw-intention': 'none' } // \u003c==\n      });\n\n      await expect(res.json()).resolves.toMatchObject({ it: 'worked' });\n      expect(res.status).toBe(200);\n    }\n  });\n});\n```\n\n#### ⚙ `response.cookies`\n\nAs of version `2.3.0`, the response object returned by `fetch()` includes a\nnon-standard _cookies_ field containing an array of objects representing\n[`set-cookie` response header(s)][30] parsed by [the `cookie` package][31]. Use\nthe _cookies_ field to easily access a response's cookie data in your tests.\n\nHere's an example taken straight from the [unit tests][32]:\n\n```typescript\nimport { testApiHandler } from 'next-test-api-route-handler';\n\nit('handles multiple set-cookie headers', async () =\u003e {\n  expect.hasAssertions();\n\n  await testApiHandler({\n    pagesHandler: (_, res) =\u003e {\n      // Multiple calls to setHeader('Set-Cookie', ...) overwrite previous, so\n      // we have to set the Set-Cookie header properly\n      res\n        .setHeader('Set-Cookie', [\n          serializeCookieHeader('access_token', '1234', {\n            expires: new Date()\n          }),\n          serializeCookieHeader('REFRESH_TOKEN', '5678')\n        ])\n        .status(200)\n        .send({});\n    },\n    test: async ({ fetch }) =\u003e {\n      expect((await fetch()).status).toBe(200);\n      await expect((await fetch()).json()).resolves.toStrictEqual({});\n      expect((await fetch()).cookies).toStrictEqual([\n        {\n          access_token: '1234',\n          // Lowercased cookie property keys are available\n          expires: expect.any(String),\n          // Raw cookie property keys are also available\n          Expires: expect.any(String)\n        },\n        { refresh_token: '5678', REFRESH_TOKEN: '5678' }\n      ]);\n    }\n  });\n});\n```\n\n\u003cbr /\u003e\n\n### `rejectOnHandlerError`\n\n\u003e ⪢ API reference: [`rejectOnHandlerError`][33]\n\nAs of version `2.3.0`, unhandled errors in the `pagesHandler`/`appHandler`\nfunction are kicked up to Next.js to handle.\n\n\u003e [!IMPORTANT]\n\u003e\n\u003e **This means `testApiHandler` will NOT reject or throw if an unhandled error\n\u003e occurs in `pagesHandler`/`appHandler`, which typically includes failing\n\u003e `expect()` assertions.**\n\nInstead, the response returned by `fetch()` in your `test` function will have a\n`HTTP 500` status [thanks to how Next.js deals with unhandled errors in\nproduction][34]. Prior to `2.3.0`, NTARH's behavior on unhandled errors and\nelsewhere was inconsistent. Version `3.0.0` further improved error handling,\nensuring no errors slip by uncaught.\n\nTo guard against false negatives, you can do either of the following:\n\n1. Make sure the status of the `fetch()` response is what you're expecting:\n\n```typescript\nconst res = await fetch();\n...\n// For this test, a 403 status is what we wanted\nexpect(res.status).toBe(403);\n...\nconst res2 = await fetch();\n...\n// Later, we expect an \"unhandled\" error\nexpect(res2.status).toBe(500);\n```\n\n2. If you're using version `\u003e=3.0.0`, you can use `rejectOnHandlerError` to tell\n   NTARH to intercept unhandled handler errors and reject the promise returned\n   by `testApiHandler` _instead_ of relying on Next.js to respond with\n   `HTTP 500`. This is especially useful if you have `expect()` assertions\n   _inside_ your handler function:\n\n```typescript\nawait expect(\n  testApiHandler({\n    rejectOnHandlerError: true, // \u003c==\n    pagesHandler: (_req, res) =\u003e {\n      res.status(200);\n      throw new Error('bad bad not good');\n    },\n    test: async ({ fetch }) =\u003e {\n      const res = await fetch();\n      // By default, res.status would be 500...\n      //expect(res.status).toBe(500);\n    }\n  })\n  // ...but since we used rejectOnHandlerError, the whole promise rejects\n  // instead\n).rejects.toThrow('bad not good');\n\nawait testApiHandler({\n  rejectOnHandlerError: true, // \u003c==\n  appHandler: {\n    async GET(request) {\n      // Suppose this expectation fails\n      await expect(backend.getSomeStuff(request)).resolves.toStrictEqual(\n        someStuff\n      );\n\n      return new Response(null, { status: 200 });\n    }\n  },\n  test: async ({ fetch }) =\u003e {\n    await fetch();\n    // By default, res.status would be 500 due to the failing expect(). If we\n    // don't also expect() a non-500 response status here, the failing\n    // expectation in the handler will be swallowed and the test will pass\n    // (a false negative).\n  }\n});\n// ...but since we used rejectOnHandlerError, the whole promise rejects\n// and it is reported that the test failed, which is probably what you wanted.\n```\n\n\u003cbr /\u003e\n\n### `requestPatcher` (`url`)\n\n\u003e [!TIP]\n\u003e\n\u003e Manually setting the request url is usually unnecessary. Only set the url if\n\u003e [your handler expects it][35] or [you want to rely on query string parsing\n\u003e instead of `params`/`paramsPatcher`][36].\n\n#### 💎 Using `appHandler`\n\n\u003e ⪢ API reference: [`requestPatcher`][37], [`url`][38]\n\n`requestPatcher` is a function that receives a [`NextRequest`][1] object and\nreturns a [`Request`][39] instance. Use this function to edit the request\n_before_ it's injected into the handler.\n\n\u003e [!CAUTION]\n\u003e\n\u003e Be wary returning a brand new request from `requestPatcher` (i.e.\n\u003e `new NextRequest(newUrl)` instead of `new NextRequest(newUrl, oldRequest)`),\n\u003e especially one that is missing standard headers added by `fetch(...)`. If\n\u003e you're getting strange JSON-related errors or hanging tests, ensure this is\n\u003e not the cause.\n\nThe returned [`Request`][39] instance will be wrapped with [`NextRequest`][1] if\nit is not already an instance of [`NextRequest`][1], i.e.:\n\n```typescript\nconst returnedRequest = (await requestPatcher?.(request)) || request;\nconst nextRequest = new NextRequest(returnedRequest, { ... });\n```\n\nIf you're only setting the request url, use the `url` shorthand instead:\n\n```typescript\nawait testApiHandler({\n  // requestPatcher: (request) =\u003e new Request('ntarh:///my-url?some=query', request),\n  url: '/my-url?some=query'\n});\n```\n\n\u003e [!NOTE]\n\u003e\n\u003e Unlike the Pages Router's `NextApiRequest` type, the App Router's\n\u003e `NextRequest` class [does not support relative URLs][40]. Therefore, whenever\n\u003e you pass a relative url string via the `url` shorthand (e.g.\n\u003e `{ url: '/my-url?some=query' }`), NTARH will wrap that url like so:\n\u003e `new URL(url, 'ntarh://')`. In this case, your requests will have urls like\n\u003e `ntarh:///my-url?some=query`.\n\n##### URL Normalization\n\nBy default, when initializing the `NextRequest` object passed to your handler,\nif a URL with an empty `pathname` is encountered, NTARH sets said URL's\n`pathname` to `\"/\"` on your behalf. Additionally, if said URL is missing `host`\nand/or `protocol`, NTARH sets `host` to `\"\"` and `protocol` to `\"ntarh:\"`.\n\nIf you want your handler to receive the URL string and resulting\n`NextRequest::nextUrl` object exactly as you've typed it, use `requestPatcher`,\nwhich is executed after NTARH does URL normalization.\n\n#### 🔷 Using `pagesHandler`\n\n\u003e ⪢ API reference: [`requestPatcher`][41], [`url`][42]\n\n`requestPatcher` is a function that receives an [`IncomingMessage`][43]. Use\nthis function to modify the request _before_ it's injected into Next.js's\nresolver.\n\nIf you're only setting the request url, use the `url` shorthand instead:\n\n```typescript\nawait testApiHandler({\n  // requestPatcher: (req) =\u003e { req.url = '/my-url?some=query'; }\n  url: '/my-url?some=query'\n});\n```\n\nNote that, unlike with [the `URL` class][44], the `url` string can be relative.\n\n\u003cbr /\u003e\n\n### `responsePatcher`\n\n#### 💎 Using `appHandler`\n\n\u003e ⪢ API reference: [`responsePatcher`][45]\n\n`responsePatcher` is a function that receives the [`Response`][46] object\nreturned from `appHandler` and returns a [`Response`][46] instance. Use this\nfunction to edit the response _after_ your handler runs but _before_ it's\nprocessed by the server.\n\n#### 🔷 Using `pagesHandler`\n\n\u003e ⪢ API reference: [`responsePatcher`][47]\n\n`responsePatcher` is a function that receives a [`ServerResponse`][48] object.\nUse this function to edit the response _before_ it's injected into the handler.\n\n\u003cbr /\u003e\n\n### `paramsPatcher` (`params`)\n\n`paramsPatcher` is a function that receives an object representing \"processed\"\n[dynamic segments][49] (aka: routes, slugs).\n\nFor example, to test a handler normally accessible from `/api/user/:id` requires\npassing that handler a value for the \"id\" dynamic segment:\n\n```typescript\nawait testApiHandler({\n  paramsPatcher(params) {\n    params.id = 'test-id';\n  }\n});\n```\n\nOr:\n\n```typescript\nawait testApiHandler({\n  paramsPatcher: (params) =\u003e ({ id: 'test-id' })\n});\n```\n\nParameters can also be passed using the `params` shorthand:\n\n```typescript\nawait testApiHandler({\n  params: {\n    id: 'test-id'\n  }\n});\n```\n\n\u003e [!TIP]\n\u003e\n\u003e Due to its simplicity, favor the `params` shorthand over `paramsPatcher`.\n\n#### 💎 Using `appHandler`\n\n\u003e ⪢ API reference: [`paramsPatcher`][50], [`params`][51]\n\n\u003e [!IMPORTANT]\n\u003e\n\u003e Note that, starting with `next@15`, the `params` object passed to handlers via\n\u003e the context parameter [is now a (Frankensteinian) promise][52]. This means\n\u003e tests like `expect(params).toStrictEqual(...)` will no longer work unless\n\u003e `params` is first `await`-ed. More information [here][53].\n\nIf both `paramsPatcher` and the `params` shorthand are used, `paramsPatcher`\nwill receive `params` as its first argument.\n\n\u003e Route parameters should not be confused with [query string parameters][54],\n\u003e which are automatically parsed out from the url and made available via the\n\u003e [`NextRequest`][1] argument passed to your handler.\n\n#### 🔷 Using `pagesHandler`\n\n\u003e ⪢ API reference: [`paramsPatcher`][55], [`params`][56]\n\nIf both `paramsPatcher` and the `params` shorthand are used, `paramsPatcher`\nwill receive an object like `{ ...queryStringURLParams, ...params }` as its\nfirst argument.\n\n\u003e Route parameters should not be confused with [query string parameters][54],\n\u003e which are automatically parsed out from the url and added to the `params`\n\u003e object before `paramsPatcher` is evaluated.\n\n\u003cbr /\u003e\n\n## Examples\n\nWhat follows are several examples that demonstrate using NTARH with the [App\nRouter][57] and the [Pages Router][58].\n\nCheck out [the tests][59] for even more examples.\n\n\u003cbr /\u003e\n\n### Using the App Router\n\nThese examples use Next.js's [App Router][60] API.\n\n#### Testing Apollo's Official Next.js Integration @ `app/api/graphql`\n\nThis example is based on [the official Apollo Next.js App Router\nintegration][61]. You can run it yourself by copying and pasting the following\ncommands into your terminal.\n\n\u003e The following should be run in a nix-like environment. On Windows, that's\n\u003e [WSL][62]. Requires `curl`, `node`, and `git`.\n\n```bash\nmkdir -p /tmp/ntarh-test/test\ncd /tmp/ntarh-test\nnpm install --force next @apollo/server @as-integrations/next graphql-tag next-test-api-route-handler jest babel-jest @babel/core @babel/preset-env\necho 'module.exports={presets:[\"@babel/preset-env\"]};' \u003e babel.config.js\nmkdir -p app/api/graphql\ncurl -o app/api/graphql/route.js https://raw.githubusercontent.com/Xunnamius/next-test-api-route-handler/main/apollo_test_raw_app_route\ncurl -o test/integration.test.js https://raw.githubusercontent.com/Xunnamius/next-test-api-route-handler/main/apollo_test_raw_app_test\nnpx jest\n```\n\nThis script creates a new temporary directory, installs NTARH and configures\ndependencies, downloads the [app route][63] and [jest test][64] files shown\nbelow, and runs the test using [jest][65].\n\nThe following is our new app route:\n\n```typescript\n/* File: app/api/graphql/route.js */\n\nimport { ApolloServer } from '@apollo/server';\nimport { startServerAndCreateNextHandler } from '@as-integrations/next';\nimport { gql } from 'graphql-tag';\n\nconst resolvers = {\n  Query: {\n    hello: () =\u003e 'world'\n  }\n};\n\nconst typeDefs = gql`\n  type Query {\n    hello: String\n  }\n`;\n\nconst server = new ApolloServer({\n  resolvers,\n  typeDefs\n});\n\nconst handler = startServerAndCreateNextHandler(server);\n\nexport { handler as GET, handler as POST };\n```\n\nAnd with the following jest test, we ensure our route integrates with Apollo\ncorrectly:\n\n```typescript\n/* File: tests/integration.test.js */\n\nimport { testApiHandler } from 'next-test-api-route-handler';\n// Import the handler under test from the app/api directory\nimport * as appHandler from '../app/api/graphql/route';\n\ndescribe('my-test (app router)', () =\u003e {\n  it('does what I want 1', async () =\u003e {\n    expect.hasAssertions();\n\n    await testApiHandler({\n      appHandler,\n      test: async ({ fetch }) =\u003e {\n        const query = `query { hello }`;\n\n        const res = await fetch({\n          method: 'POST',\n          headers: {\n            'content-type': 'application/json' // Must use correct content type\n          },\n          body: JSON.stringify({ query })\n        });\n\n        await expect(res.json()).resolves.toStrictEqual({\n          data: { hello: 'world' }\n        });\n      }\n    });\n  });\n\n  it('does what I want 2', async () =\u003e {\n    // Exactly the same as the above...\n  });\n\n  it('does what I want 3', async () =\u003e {\n    // Exactly the same as the above...\n  });\n});\n```\n\n#### Testing Clerk's Official Next.js Integration @ `app/api/authed`\n\nSuppose we created a new _authenticated_ API endpoint at `app/api/authed` by\n[cloning the Clerk App Router demo repo][66] and following [Clerk's quick-start\nguide for Next.js][67]:\n\n```typescript\n/* File: app/api/authed/route.ts */\n\nimport { auth } from '@clerk/nextjs';\n\nexport async function GET() {\n  const { userId } = auth();\n  return Response.json({ isAuthed: !!userId, userId });\n}\n```\n\nHow might we test that this endpoint functions as we expect?\n\n```typescript\n/* File: test/unit.test.ts */\n\nimport { testApiHandler } from 'next-test-api-route-handler';\nimport * as appHandler from '../app/api/authed/route';\n\nimport type { auth } from '@clerk/nextjs';\n\nlet mockedClerkAuthReturnValue: Partial\u003cReturnType\u003ctypeof auth\u003e\u003e | undefined =\n  undefined;\n\njest.mock('@clerk/nextjs', () =\u003e {\n  return {\n    auth() {\n      return mockedClerkAuthReturnValue;\n    }\n  };\n});\n\nafterEach(() =\u003e {\n  mockedClerkAuthReturnValue = undefined;\n});\n\nit('returns isAuthed: true and a userId when authenticated', async () =\u003e {\n  expect.hasAssertions();\n\n  mockedClerkAuthReturnValue = { userId: 'winning' };\n\n  await testApiHandler({\n    appHandler,\n    test: async ({ fetch }) =\u003e {\n      await expect((await fetch()).json()).resolves.toStrictEqual({\n        isAuthed: true,\n        userId: 'winning'\n      });\n    }\n  });\n});\n\nit('returns isAuthed: false and nothing else when unauthenticated', async () =\u003e {\n  expect.hasAssertions();\n\n  mockedClerkAuthReturnValue = { userId: null };\n\n  await testApiHandler({\n    appHandler,\n    test: async ({ fetch }) =\u003e {\n      await expect((await fetch()).json()).resolves.toStrictEqual({\n        isAuthed: false,\n        userId: null\n      });\n    }\n  });\n});\n```\n\nIf you're feeling more adventurous, you can transform this unit test into an\n_integration_ test (like the Apollo example above) by calling Clerk's\n[`authMiddleware`][68] function in `appHandler` instead of mocking\n`@clerk/nextjs`:\n\n```typescript\n// This integration test also requires your Clerk dashboard is setup in test\n// mode and your Clerk secret key information is available in process.env. Said\n// information must be available BEFORE any Clerk packages are imported! You\n// will also have to setup authMiddleware properly in ../middleware.ts\n\n/* ... same imports as before ... */\n// Also import our Next.js middleware\nimport { default as middleware } from '../middleware';\n// And we want to keep our types as tight as we can too\nimport type { NextRequest } from 'next/server';\n\nconst DUMMY_CLERK_USER_ID = 'user_2aqlGWnjdTRRbbBk9OdBHHbniyK';\n\nit('returns isAuthed: true and a userId when authenticated', async () =\u003e {\n  expect.hasAssertions();\n\n  await testApiHandler({\n    rejectOnHandlerError: true,\n    // You may want to alter the default URL pathname like below if your Clerk\n    // middleware is using path-based filtering. By default, the pathname\n    // will always be '/' because 'ntarh://testApiHandler/' is the default url\n    url: 'ntarh://app/api/authed',\n    appHandler: {\n      get GET() {\n        return async function (...args: Parameters\u003ctypeof appHandler.GET\u003e) {\n          const request = args.at(0) as unknown as NextRequest;\n          const middlewareResponse = await middleware(request, {\n            /* ... */\n          });\n\n          // Make sure we're not being redirected to the sign in page since\n          // this is a publicly available endpoint\n          expect(middlewareResponse.headers.get('location')).toBeNull();\n          expect(middlewareResponse.ok).toBe(true);\n\n          const handlerResponse = await appHandler.GET(...args);\n\n          // You could run some expectations here (since rejectOnHandlerError is\n          // true), or you can run your remaining expectations in the test\n          // function below. Either way is fine.\n\n          return handlerResponse;\n        };\n      }\n    },\n    test: async ({ fetch }) =\u003e {\n      await expect((await fetch()).json()).resolves.toStrictEqual({\n        isAuthed: true,\n        userId: DUMMY_CLERK_USER_ID\n      });\n    }\n  });\n});\n\n/* ... */\n```\n\nYou can also try calling [`authMiddleware`][68] in `requestPatcher`; however,\nClerk's middleware does its magic by importing the `headers` helper function\nfrom `'next/headers'`, and **only functions invoked within `appHandler` have\naccess to the storage context that allows Next.js's helper functions to work**.\nFor insight into what you'd need to do to make [`authMiddleware`][68] callable\nin `requestPatcher`, check out [Clerk's own tests][69].\n\n#### Testing an Unreliable Handler on the Edge @ `app/api/unreliable`\n\nSuppose we have an API endpoint we use to test our application's error handling.\nThe endpoint responds with status code `HTTP 200` for every request except the\n10th, where status code `HTTP 555` is returned instead.\n\nHow might we test that this endpoint responds with `HTTP 555` once for every\nnine `HTTP 200` responses?\n\n```typescript\n/* File: test/unit.test.ts */\n\nimport { testApiHandler } from 'next-test-api-route-handler';\n// Import the handler under test from the app/api directory\nimport * as edgeHandler from '../app/api/unreliable';\n\nconst expectedReqPerError = 10;\n\nit('injects contrived errors at the required rate', async () =\u003e {\n  expect.hasAssertions();\n\n  // Signal to the edge endpoint (which is configurable) that there should be 1\n  // error among every 10 requests\n  process.env.REQUESTS_PER_CONTRIVED_ERROR = expectedReqPerError.toString();\n\n  await testApiHandler({\n    appHandler: edgeHandler,\n    requestPatcher(request) {\n      // Our edge handler expects Next.js to provide geo and ip data with the\n      // request, so let's add some. This is also where you'd mock/emulate the\n      // effects of any Next.js middleware\n      //\n      // IMPORTANT: starting with next@15, geo/ip have been removed from\n      // NextRequest and were functionally replaced by @vercel/function\n      // https://github.com/vercel/next.js/pull/68379\n      // https://nextjs.org/docs/app/building-your-application/upgrading/version-15#nextrequest-geolocation\n      return new NextRequest(request, {\n        geo: { city: 'Chicago', country: 'United States' },\n        ip: '110.10.77.7'\n      });\n    },\n    test: async ({ fetch }) =\u003e {\n      // Run 20 requests with REQUESTS_PER_CONTRIVED_ERROR = '10' and\n      // record the results\n      const results1 = await Promise.all(\n        [\n          ...Array.from({ length: expectedReqPerError - 1 }).map(() =\u003e\n            fetch({ method: 'GET' })\n          ),\n          fetch({ method: 'POST' }),\n          ...Array.from({ length: expectedReqPerError - 1 }).map(() =\u003e\n            fetch({ method: 'PUT' })\n          ),\n          fetch({ method: 'DELETE' })\n        ].map((p) =\u003e p.then((r) =\u003e r.status))\n      );\n\n      process.env.REQUESTS_PER_CONTRIVED_ERROR = '0';\n\n      // Run 10 requests with REQUESTS_PER_CONTRIVED_ERROR = '0' and record the\n      // results\n      const results2 = await Promise.all(\n        Array.from({ length: expectedReqPerError }).map(() =\u003e\n          fetch().then((r) =\u003e r.status)\n        )\n      );\n\n      // We expect results1 to be an array with eighteen `200`s and two\n      // `555`s in any order\n      //\n      // https://github.com/jest-community/jest-extended#toincludesamemembersmembers\n      // because responses could be received out of order\n      expect(results1).toIncludeSameMembers([\n        ...Array.from({ length: expectedReqPerError - 1 }).map(() =\u003e 200),\n        555,\n        ...Array.from({ length: expectedReqPerError - 1 }).map(() =\u003e 200),\n        555\n      ]);\n\n      // We expect results2 to be an array with ten `200`s\n      expect(results2).toStrictEqual([\n        ...Array.from({ length: expectedReqPerError }).map(() =\u003e 200)\n      ]);\n    }\n  });\n});\n```\n\n\u003cbr /\u003e\n\n### Using the Pages Router\n\nThese examples use Next.js's [Pages Router][70] API.\n\n#### Testing Next.js's Official Apollo Example @ `pages/api/graphql`\n\nThis example uses the [official Next.js Apollo demo][71]. You can easily run it\nyourself by copying and pasting the following commands into your terminal.\n\n\u003e The following should be run in a nix-like environment. On Windows, that's\n\u003e [WSL][62]. Requires `curl`, `node`, and `git`.\n\n```bash\ngit clone --depth=1 https://github.com/vercel/next.js /tmp/ntarh-test\ncd /tmp/ntarh-test/examples/api-routes-apollo-server-and-client\nnpm install --force\nnpm install --force next-test-api-route-handler jest babel-jest @babel/core @babel/preset-env\n# You could test with an older version of Next.js if you want, e.g.:\n# npm install --force next@9.0.6\n# Or even older:\n# npm install --force next@9.0.0 next-server\necho 'module.exports={presets:[\"@babel/preset-env\"]};' \u003e babel.config.js\nmkdir test\ncurl -o test/integration.test.js https://raw.githubusercontent.com/Xunnamius/next-test-api-route-handler/main/apollo_test_raw\nnpx jest\n```\n\nThis script clones [the Next.js repository][72], installs NTARH and configures\ndependencies, downloads the [jest test][73] file shown below, and runs it using\n[jest][65] to ensure our route integrates with Apollo correctly.\n\n\u003e [!IMPORTANT]\n\u003e\n\u003e Note that passing the [route configuration object][74] (imported below as\n\u003e `config`) through to NTARH and setting `request.url` to the proper value [may\n\u003e be necessary][75] when testing Apollo endpoints using the Pages Router.\n\n```typescript\n/* File: examples/api-routes-apollo-server-and-client/tests/integration.test.js */\n\nimport { testApiHandler } from 'next-test-api-route-handler';\n// Import the handler under test from the pages/api directory\nimport * as pagesHandler from '../pages/api/graphql';\n\ndescribe('my-test (pages router)', () =\u003e {\n  it('does what I want 1', async () =\u003e {\n    expect.hasAssertions();\n\n    await testApiHandler({\n      pagesHandler,\n      url: '/api/graphql', // Set the request url to the path graphql expects\n      test: async ({ fetch }) =\u003e {\n        const query = `query ViewerQuery {\n          viewer {\n            id\n            name\n            status\n          }\n        }`;\n\n        const res = await fetch({\n          method: 'POST',\n          headers: {\n            'content-type': 'application/json' // Must use correct content type\n          },\n          body: JSON.stringify({ query })\n        });\n\n        await expect(res.json()).resolves.toStrictEqual({\n          data: { viewer: { id: '1', name: 'John Smith', status: 'cached' } }\n        });\n      }\n    });\n  });\n\n  it('does what I want 2', async () =\u003e {\n    // Exactly the same as the above...\n  });\n\n  it('does what I want 3', async () =\u003e {\n    // Exactly the same as the above...\n  });\n});\n```\n\n#### Testing an Authenticated Flight Search Handler @ `pages/api/v3/flights/search`\n\nSuppose we have an _authenticated_ API endpoint our application uses to search\nfor flights. The endpoint responds with an array of flights satisfying the\nquery.\n\nHow might we test that this endpoint returns flights in our database as\nexpected?\n\n```typescript\n/* File: test/unit.test.ts */\n\nimport { testApiHandler } from 'next-test-api-route-handler';\nimport { DUMMY_API_KEY as KEY, getFlightData, RESULT_SIZE } from '../backend';\nimport * as pagesHandler from '../pages/api/v3/flights/search';\n\nimport type { PageConfig } from 'next';\n\nit('returns expected public flights with respect to match', async () =\u003e {\n  expect.hasAssertions();\n\n  // Get the flight data currently in the test database\n  const expectedFlights = getFlightData();\n\n  // Take any JSON object and stringify it into a URL-ready string\n  const encode = (o: Record\u003cstring, unknown\u003e) =\u003e\n    encodeURIComponent(JSON.stringify(o));\n\n  // This function will return in order the URIs we're interested in testing\n  // against our handler. Query strings are parsed by NTARH automatically.\n  //\n  // NOTE: setting the request url manually using encode(), while valid, is\n  // unnecessary here; we could have used `params` or `paramsPatcher` to do this\n  // more easily without explicitly setting a dummy request url.\n  //\n  // Example URI for `https://site.io/path?param=yes` would be `/path?param=yes`\n  const genUrl = (function* () {\n    // For example, the first should match all the flights from Spirit airlines!\n    yield `/?match=${encode({ airline: 'Spirit' })}`;\n    yield `/?match=${encode({ type: 'departure' })}`;\n    yield `/?match=${encode({ landingAt: 'F1A' })}`;\n    yield `/?match=${encode({ seatPrice: 500 })}`;\n    yield `/?match=${encode({ seatPrice: { $gt: 500 } })}`;\n    yield `/?match=${encode({ seatPrice: { $gte: 500 } })}`;\n    yield `/?match=${encode({ seatPrice: { $lt: 500 } })}`;\n    yield `/?match=${encode({ seatPrice: { $lte: 500 } })}`;\n  })();\n\n  await testApiHandler({\n    // Patch the request object to include our dummy URI\n    requestPatcher: (req) =\u003e {\n      req.url = genUrl.next().value || undefined;\n      // Could have done this instead of `fetch({ headers: { KEY }})` below:\n      // req.headers = { KEY };\n    },\n\n    pagesHandler,\n\n    test: async ({ fetch }) =\u003e {\n      // 8 URLs from genUrl means 8 calls to fetch:\n      const responses = await Promise.all(\n        Array.from({ length: 8 }).map(() =\u003e\n          fetch({ headers: { KEY } }).then(async (r) =\u003e [\n            r.status,\n            await r.json()\n          ])\n        )\n      );\n\n      // We expect all of the responses to be 200\n      expect(responses.some(([status]) =\u003e status !== 200)).toBe(false);\n\n      // We expect the array of flights returned to match our\n      // expectations given we already know what dummy data will be\n      // returned:\n\n      // https://github.com/jest-community/jest-extended#toincludesamemembersmembers\n      // because responses could be received out of order\n      expect(responses.map(([, r]) =\u003e r.flights)).toIncludeSameMembers([\n        expectedFlights\n          .filter((f) =\u003e f.airline === 'Spirit')\n          .slice(0, RESULT_SIZE),\n        expectedFlights\n          .filter((f) =\u003e f.type === 'departure')\n          .slice(0, RESULT_SIZE),\n        expectedFlights\n          .filter((f) =\u003e f.landingAt === 'F1A')\n          .slice(0, RESULT_SIZE),\n        expectedFlights\n          .filter((f) =\u003e f.seatPrice === 500)\n          .slice(0, RESULT_SIZE),\n        expectedFlights.filter((f) =\u003e f.seatPrice \u003e 500).slice(0, RESULT_SIZE),\n        expectedFlights.filter((f) =\u003e f.seatPrice \u003e= 500).slice(0, RESULT_SIZE),\n        expectedFlights.filter((f) =\u003e f.seatPrice \u003c 500).slice(0, RESULT_SIZE),\n        expectedFlights.filter((f) =\u003e f.seatPrice \u003c= 500).slice(0, RESULT_SIZE)\n      ]);\n    }\n  });\n\n  // We expect these two to fail with 400 errors\n\n  await testApiHandler({\n    pagesHandler,\n    url: `/?match=${encode({ ffms: { $eq: 500 } })}`,\n    test: async ({ fetch }) =\u003e\n      expect((await fetch({ headers: { KEY } })).status).toBe(400)\n  });\n\n  await testApiHandler({\n    pagesHandler,\n    url: `/?match=${encode({ bad: 500 })}`,\n    test: async ({ fetch }) =\u003e\n      expect((await fetch({ headers: { KEY } })).status).toBe(400)\n  });\n});\n```\n\n#### Testing an Unreliable Handler @ `pages/api/unreliable`\n\nSuppose we have an API endpoint we use to test our application's error handling.\nThe endpoint responds with status code `HTTP 200` for every request except the\n10th, where status code `HTTP 555` is returned instead.\n\nHow might we test that this endpoint responds with `HTTP 555` once for every\nnine `HTTP 200` responses?\n\n```typescript\n/* File: test/unit.test.ts */\n\nimport { testApiHandler } from 'next-test-api-route-handler';\n// Import the handler under test from the pages/api directory\nimport * as pagesHandler from '../pages/api/unreliable';\n\nconst expectedReqPerError = 10;\n\nit('injects contrived errors at the required rate', async () =\u003e {\n  expect.hasAssertions();\n\n  // Signal to the endpoint (which is configurable) that there should be 1\n  // error among every 10 requests\n  process.env.REQUESTS_PER_CONTRIVED_ERROR = expectedReqPerError.toString();\n\n  await testApiHandler({\n    pagesHandler,\n    test: async ({ fetch }) =\u003e {\n      // Run 20 requests with REQUESTS_PER_CONTRIVED_ERROR = '10' and\n      // record the results\n      const results1 = await Promise.all(\n        [\n          ...Array.from({ length: expectedReqPerError - 1 }).map(() =\u003e\n            fetch({ method: 'GET' })\n          ),\n          fetch({ method: 'POST' }),\n          ...Array.from({ length: expectedReqPerError - 1 }).map(() =\u003e\n            fetch({ method: 'PUT' })\n          ),\n          fetch({ method: 'DELETE' })\n        ].map((p) =\u003e p.then((r) =\u003e r.status))\n      );\n\n      process.env.REQUESTS_PER_CONTRIVED_ERROR = '0';\n\n      // Run 10 requests with REQUESTS_PER_CONTRIVED_ERROR = '0' and record the\n      // results\n      const results2 = await Promise.all(\n        Array.from({ length: expectedReqPerError }).map(() =\u003e\n          fetch().then((r) =\u003e r.status)\n        )\n      );\n\n      // We expect results1 to be an array with eighteen `200`s and two\n      // `555`s in any order\n      //\n      // https://github.com/jest-community/jest-extended#toincludesamemembersmembers\n      // because responses could be received out of order\n      expect(results1).toIncludeSameMembers([\n        ...Array.from({ length: expectedReqPerError - 1 }).map(() =\u003e 200),\n        555,\n        ...Array.from({ length: expectedReqPerError - 1 }).map(() =\u003e 200),\n        555\n      ]);\n\n      // We expect results2 to be an array with ten `200`s\n      expect(results2).toStrictEqual([\n        ...Array.from({ length: expectedReqPerError }).map(() =\u003e 200)\n      ]);\n    }\n  });\n});\n```\n\n\u003cbr /\u003e\n\n\u003c!-- symbiote-template-region-start 5 --\u003e\n\n## Appendix\n\n\u003c!-- symbiote-template-region-end --\u003e\n\nFurther documentation can be found under [`docs/`][x-repo-docs].\n\n### Limitations with App Router and Edge Runtime Emulation\n\nSince NTARH is meant for unit testing API routes rather than faithfully\nrecreating Next.js functionality, NTARH's feature set comes with some caveats.\nNamely: no Next.js features will be available that are external to processing\nAPI routes and executing their handlers. This includes [middleware][76] and\n`NextResponse.next` (see [`requestPatcher`][77] if you need to mutate the\n`Request` before it gets to the handler under test), [metadata][78], [static\nassets][79], [OpenTelemetry][80] and [instrumentation][81], [caching][82],\n[styling][83], [server actions and mutations][84], [helper functions][3]\n(except: `cookies`, `fetch` (global), `headers`, `NextRequest`, `NextResponse`,\n`notFound`, `permanentRedirect`, `redirect`, and `userAgent`), and anything\nrelated to React or [components][85].\n\nNTARH is for testing your API route handlers only.\n\nFurther, any support NTARH appears to have for any \"[edge runtime][86]\" (or any\nother runtime) beyond what is provided by [`AppRouteRouteModule`][87] is merely\ncosmetic. **Your tests will always run in Node.js** (or your runner of choice)\nand never in a different runtime, realm, or VM. This means unit testing like\nwith NTARH must be done in addition to, and not in lieu of, more holistic\ntesting practices (e.g. [end-to-end][88]).\n\nIf you're having trouble with your App Router and/or Edge Runtime routes,\nconsider [opening a new issue][x-repo-choose-new-issue]!\n\n\u003e Also note that Next.js's middleware **only supports the Edge runtime**, even\n\u003e if the Next.js application is being run entirely by Node.js. This is an\n\u003e artificial constraint imposed by Next.js; when running the middleware locally\n\u003e (via `npm run dev` or something similar), the middleware will still run on\n\u003e Node.js.\n\u003e\n\u003e Next.js's middleware limitation is discussed at length [here][89].\n\n#### Working around the App Router Patching the Global `fetch` Function\n\nNext.js's current App Router implementation mutates the global `fetch` function,\nredefining it entirely. This can cause [problems][90] in testing environments\nwhere the global `fetch` is to be mocked by something else.\n\nInternally, NTARH sidesteps this issue entirely by caching the value of\n`globalThis.fetch` upon import. This also means NTARH completely sidesteps other\ntools that rely on interception through rewriting the global `fetch` function,\nsuch as [Mock Service Worker (MSW)][91]. We still include the MSW bypass headers\nwith NTARH requests since we cannot guarantee that NTARH will not be imported\n_after_ MSW has finished patching global `fetch`.\n\nSimilarly, it is impossible for NTARH to meaningfully track mutations to the\nglobal `fetch` function; NTARH cannot tell the difference between Next.js\noverwriting `fetch` and, say, a Jest spy overwriting `fetch`. Therefore, **NTARH\ndoes not restore the cached `fetch` after the function returns.**\n\nIf Next.js's patching of `fetch` is causing trouble for you, you can do what\nNTARH does: capture the current global `fetch` (perhaps after setting up MSW)\nand then restore it after each test:\n\n```typescript\nconst originalGlobalFetch = fetch;\n\nafterEach(function () {\n  // Undo what Next.js does to the global fetch function\n  globalThis.fetch = originalGlobalFetch;\n});\n```\n\n#### Working around Global `AsyncLocalStorage` Availability\n\n`AppRouteRouteModule` and its dependents want `AsyncLocalStorage` to be\navailable globally and _immediately_. Unfortunately, Node.js does not place\n`AsyncLocalStorage` in `globalThis` natively.\n\nNTARH handles this by ensuring `AsyncLocalStorage` is added to `globalThis`\nbefore Next.js needs it. This is why [NTARH should always be the very first\nimport in any test file][12].\n\n\u003cbr /\u003e\n\n### Legacy Runtime Support\n\nAs of version `4.0.0`, NTARH supports both the App Router (for `next@\u003e=14.0.4`)\nand the \"legacy\" Pages Router Next.js APIs. However, due to the code churn with\n`next@13`, NTARH's support for the App Router begins at `next@14.0.4`. See\n[here][8] and [here][92] for more information.\n\nAdditionally, as of version `2.1.0`, NTARH's Pages Router support is fully\nbackwards compatible with Next.js going _allll_ the way back to `next@9.0.0`\n[when API routes were first introduced][93]!\n\nIf you're working with the Pages Router and `next@\u003c9.0.6` (so: [before\n`next-server` was merged into `next`][94]), you might need to install\n`next-server` manually:\n\n```shell\nnpm install --save-dev next-server\n```\n\nSimilarly, if you are using `npm@\u003c7` or `node@\u003c15`, you must install Next.js\n_and its peer dependencies_ manually. This is because [`npm@\u003c7` does not install\npeer dependencies by default][95].\n\n```shell\nnpm install --save-dev next@latest react\n```\n\n\u003e If you're also using an older version of Next.js, ensure you install the [peer\n\u003e dependencies (like `react`) that your specific Next.js version requires][96]!\n\n\u003cbr /\u003e\n\n### Jsdom Support\n\nNote that [jsdom does not support global fetch natively][97]. This should not be\nan issue, however, since neither your API code nor your API test code should be\nexecuted in a browser-like environment.\n\nFor projects configured to use jsdom by default, you can use an annotation to\nswitch environments only in the files housing your API tests:\n\n```typescript\n/**\n * @jest-environment node\n */\n// ⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆⬆\n\nimport { testApiHandler } from 'next-test-api-route-handler';\n\ntest('use the node test environment for all tests in this file', () =\u003e {\n  //...\n});\n```\n\nIf you're dead set on using jsdom over the node testing environment with NTARH,\nsee [here][98] and [here][99] for workarounds.\n\n\u003cbr /\u003e\n\n### Inspiration\n\nI'm constantly creating things with Next.js. Most of these applications have a\nmajor API component. Unfortunately, Next.js doesn't make unit testing your APIs\nvery easy. After a while, I noticed some conventions forming around how I liked\nto test my APIs and NTARH was born 🙂\n\nOf course, this all was back before the app router or edge routes existed. NTARH\ngot app router and edge route support in version 4.\n\nMy hope is that NTARH gets obsoleted because Vercel provided developers with\nsome officially supported tooling/hooks for _lightweight_ route execution where\nhandlers are passed fully initialized instances of\n`NextRequest`/`NextResponse`/`NextApiRequest`/`NextApiResponse` without\nballooning the execution time of the tests. That is: no spinning up the entire\nNext.js runtime just to run a single test in isolation.\n\nIt doesn't seem like it'd be such a lift to surface a wrapped version of the\nPages Router's [`apiResolver`][100] function and a pared-down subclass of the\nApp Router's [`AppRouteRouteModule`][87], both accessible with something like\n`import { ... } from 'next/test'`. This is essentially what NTARH does.\n\n\u003cbr /\u003e\n\n#### History: The Very _Very_ First Version of Ntarh\n\nWas looking over some ancient Next.js projects and found some of the very first\nversions of what would eventually become NTARH. My inner code hoarder requires I\nnote this code's existence somewhere.\n\nOh how far we've come 🙂\n\n![alt text][101]\n\n\u003cbr /\u003e\n\n\u003c!-- symbiote-template-region-start 6 --\u003e\n\n### Published Package Details\n\nThis is a [CJS2 package][x-pkg-cjs-mojito] with statically-analyzable exports\nbuilt by Babel for use in Node.js versions that are not end-of-life. For\nTypeScript users, this package supports both `\"Node10\"` and `\"Node16\"` module\nresolution strategies.\n\n\u003c!-- symbiote-template-region-end --\u003e\n\u003c!-- symbiote-template-region-start 7 --\u003e\n\n\u003cdetails\u003e\u003csummary\u003eExpand details\u003c/summary\u003e\n\nThat means both CJS2 (via `require(...)`) and ESM (via `import { ... } from ...`\nor `await import(...)`) source will load this package from the same entry points\nwhen using Node. This has several benefits, the foremost being: less code\nshipped/smaller package size, avoiding [dual package\nhazard][x-pkg-dual-package-hazard] entirely, distributables are not\npacked/bundled/uglified, a drastically less complex build process, and CJS\nconsumers aren't shafted.\n\nEach entry point (i.e. `ENTRY`) in [`package.json`'s\n`exports[ENTRY]`][x-repo-package-json] object includes one or more [export\nconditions][x-pkg-exports-conditions]. These entries may or may not include: an\n[`exports[ENTRY].types`][x-pkg-exports-types-key] condition pointing to a type\ndeclaration file for TypeScript and IDEs, a\n[`exports[ENTRY].module`][x-pkg-exports-module-key] condition pointing to\n(usually ESM) source for Webpack/Rollup, a `exports[ENTRY].node` and/or\n`exports[ENTRY].default` condition pointing to (usually CJS2) source for Node.js\n`require`/`import` and for browsers and other environments, and [other\nconditions][x-pkg-exports-conditions] not enumerated here. Check the\n[package.json][x-repo-package-json] file to see which export conditions are\nsupported.\n\nNote that, regardless of the [`{ \"type\": \"...\" }`][x-pkg-type] specified in\n[`package.json`][x-repo-package-json], any JavaScript files written in ESM\nsyntax (including distributables) will always have the `.mjs` extension. Note\nalso that [`package.json`][x-repo-package-json] may include the\n[`sideEffects`][x-pkg-side-effects-key] key, which is almost always `false` for\noptimal [tree shaking][x-pkg-tree-shaking] where appropriate.\n\n\u003c!-- symbiote-template-region-end --\u003e\n\u003c!-- symbiote-template-region-start 8 --\u003e\n\n\u003c/details\u003e\n\n### License\n\n\u003c!-- symbiote-template-region-end --\u003e\n\nSee [LICENSE][x-repo-license].\n\n\u003c!-- symbiote-template-region-start 9 --\u003e\n\n## Contributing and Support\n\n**[New issues][x-repo-choose-new-issue] and [pull requests][x-repo-pr-compare]\nare always welcome and greatly appreciated! 🤩** Just as well, you can [star 🌟\nthis project][x-badge-repo-link] to let me know you found it useful! ✊🏿 Or [buy\nme a beer][x-repo-sponsor], I'd appreciate it. Thank you!\n\nSee [CONTRIBUTING.md][x-repo-contributing] and [SUPPORT.md][x-repo-support] for\nmore information.\n\n\u003c!-- symbiote-template-region-end --\u003e\n\u003c!-- symbiote-template-region-start 10 --\u003e\n\n### Contributors\n\n\u003c!-- symbiote-template-region-end --\u003e\n\u003c!-- symbiote-template-region-start root-package-only --\u003e\n\u003c!-- remark-ignore-start --\u003e\n\u003c!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section --\u003e\n\n[![All Contributors](https://img.shields.io/badge/all_contributors-38-orange.svg?style=flat-square)](#contributors-)\n\n\u003c!-- ALL-CONTRIBUTORS-BADGE:END --\u003e\n\u003c!-- remark-ignore-end --\u003e\n\nThanks goes to these wonderful people ([emoji\nkey][x-repo-all-contributors-emojis]):\n\n\u003c!-- remark-ignore-start --\u003e\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\n\u003ctable\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://xunn.io/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/656017?v=4?s=100\" width=\"100px;\" alt=\"Bernard\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eBernard\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#infra-Xunnamius\" title=\"Infrastructure (Hosting, Build-Tools, etc)\"\u003e🚇\u003c/a\u003e \u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/commits?author=Xunnamius\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/commits?author=Xunnamius\" title=\"Documentation\"\u003e📖\u003c/a\u003e \u003ca href=\"#maintenance-Xunnamius\" title=\"Maintenance\"\u003e🚧\u003c/a\u003e \u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/commits?author=Xunnamius\" title=\"Tests\"\u003e⚠️\u003c/a\u003e \u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/pulls?q=is%3Apr+reviewed-by%3AXunnamius\" title=\"Reviewed Pull Requests\"\u003e👀\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://www.linkedin.com/in/kevinjennison/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/5924325?v=4?s=100\" width=\"100px;\" alt=\"Kevin Jennison\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eKevin Jennison\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/commits?author=kmjennison\" title=\"Documentation\"\u003e📖\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://github.com/jonkers3\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/100176328?v=4?s=100\" width=\"100px;\" alt=\"jonkers3\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003ejonkers3\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/commits?author=jonkers3\" title=\"Documentation\"\u003e📖\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://valentin-hervieu.fr/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/2678610?v=4?s=100\" width=\"100px;\" alt=\"Valentin Hervieu\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eValentin Hervieu\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/commits?author=ValentinH\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#ideas-ValentinH\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e \u003ca href=\"#research-ValentinH\" title=\"Research\"\u003e🔬\u003c/a\u003e \u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/commits?author=ValentinH\" title=\"Tests\"\u003e⚠️\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://danawoodman.com/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/157695?v=4?s=100\" width=\"100px;\" alt=\"Dana Woodman\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eDana Woodman\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#infra-danawoodman\" title=\"Infrastructure (Hosting, Build-Tools, etc)\"\u003e🚇\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://github.com/rhys-e\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/1895732?v=4?s=100\" width=\"100px;\" alt=\"Rhys\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eRhys\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#ideas-rhys-e\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://prakharshukla.dev/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/39938009?v=4?s=100\" width=\"100px;\" alt=\"Prakhar Shukla\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003ePrakhar Shukla\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/issues?q=author%3Aimprakharshukla\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://github.com/jakejones2\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/126596149?v=4?s=100\" width=\"100px;\" alt=\"Jake Jones\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eJake Jones\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/issues?q=author%3Ajakejones2\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e \u003ca href=\"#ideas-jakejones2\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e \u003ca href=\"#research-jakejones2\" title=\"Research\"\u003e🔬\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://github.com/desclapez\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/562849?v=4?s=100\" width=\"100px;\" alt=\"Diego Esclapez\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eDiego Esclapez\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/issues?q=author%3Adesclapez\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://github.com/k2xl\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/965260?v=4?s=100\" width=\"100px;\" alt=\"k2xl\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003ek2xl\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#research-k2xl\" title=\"Research\"\u003e🔬\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://github.com/machineghost\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/448908?v=4?s=100\" width=\"100px;\" alt=\"Jeremy Walker\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eJeremy Walker\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#example-machineghost\" title=\"Examples\"\u003e💡\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://github.com/adrian-kriegel\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/23387365?v=4?s=100\" width=\"100px;\" alt=\"Adrian Kriegel\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eAdrian Kriegel\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#example-adrian-kriegel\" title=\"Examples\"\u003e💡\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"http://hems.io/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/27327?v=4?s=100\" width=\"100px;\" alt=\"hems.io\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003ehems.io\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/issues?q=author%3Ahems\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e \u003ca href=\"#research-hems\" title=\"Research\"\u003e🔬\u003c/a\u003e \u003ca href=\"#ideas-hems\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e \u003ca href=\"#example-hems\" title=\"Examples\"\u003e💡\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://github.com/steve-taylor\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/1135589?v=4?s=100\" width=\"100px;\" alt=\"Steve Taylor\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eSteve Taylor\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#ideas-steve-taylor\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://github.com/willnix86\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/33470216?v=4?s=100\" width=\"100px;\" alt=\"Will Nixon\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eWill Nixon\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/issues?q=author%3Awillnix86\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e \u003ca href=\"#research-willnix86\" title=\"Research\"\u003e🔬\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://github.com/sebpowell\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/1786366?v=4?s=100\" width=\"100px;\" alt=\"Sebastien Powell\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eSebastien Powell\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#example-sebpowell\" title=\"Examples\"\u003e💡\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://github.com/zero734kr\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/51540538?v=4?s=100\" width=\"100px;\" alt=\"Hajin Lim\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eHajin Lim\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#ideas-zero734kr\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://meetjane.dev/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/47473728?v=4?s=100\" width=\"100px;\" alt=\"Jane\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eJane\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#example-sustainjane98\" title=\"Examples\"\u003e💡\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://janhesters.com/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/31096420?v=4?s=100\" width=\"100px;\" alt=\"Jan Hesters\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eJan Hesters\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/issues?q=author%3Ajanhesters\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://bencesomogyi.com/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/10220181?v=4?s=100\" width=\"100px;\" alt=\"Bence Somogyi\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eBence Somogyi\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/issues?q=author%3Asomogyibence\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e \u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/commits?author=somogyibence\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#research-somogyibence\" title=\"Research\"\u003e🔬\u003c/a\u003e \u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/commits?author=somogyibence\" title=\"Tests\"\u003e⚠️\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://github.com/tolivturnstile\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/121887214?v=4?s=100\" width=\"100px;\" alt=\"Tony\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eTony\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#research-tolivturnstile\" title=\"Research\"\u003e🔬\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://github.com/Jokinen\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/9090689?v=4?s=100\" width=\"100px;\" alt=\"Jaakko Jokinen\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eJaakko Jokinen\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/issues?q=author%3AJokinen\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e \u003ca href=\"#research-Jokinen\" title=\"Research\"\u003e🔬\u003c/a\u003e \u003ca href=\"#ideas-Jokinen\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://arun.blog/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/18581859?v=4?s=100\" width=\"100px;\" alt=\"Arun Sathiya\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eArun Sathiya\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#research-arunsathiya\" title=\"Research\"\u003e🔬\u003c/a\u003e \u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/commits?author=arunsathiya\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://github.com/scottsymm\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/274599?v=4?s=100\" width=\"100px;\" alt=\"Scott Symmank\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eScott Symmank\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#research-scottsymm\" title=\"Research\"\u003e🔬\u003c/a\u003e \u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/issues?q=author%3Ascottsymm\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://github.com/matiasdecarli\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/2442390?v=4?s=100\" width=\"100px;\" alt=\"Matias De Carli\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eMatias De Carli\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/commits?author=matiasdecarli\" title=\"Documentation\"\u003e📖\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://github.com/kingstarfly\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/38955962?v=4?s=100\" width=\"100px;\" alt=\"Xing Xiang\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eXing Xiang\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/commits?author=kingstarfly\" title=\"Documentation\"\u003e📖\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://www.kaarlej.com/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/117437182?v=4?s=100\" width=\"100px;\" alt=\"Kaarle Järvinen\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eKaarle Järvinen\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/issues?q=author%3AKaarleJ\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://rorysaur.blog/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/4686089?v=4?s=100\" width=\"100px;\" alt=\"Rory Ou\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eRory Ou\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/issues?q=author%3Arorysaur\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e \u003ca href=\"#research-rorysaur\" title=\"Research\"\u003e🔬\u003c/a\u003e \u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/commits?author=rorysaur\" title=\"Documentation\"\u003e📖\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://twitter.com/snaka\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/19329?v=4?s=100\" width=\"100px;\" alt=\"Shinji Nakamatsu\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eShinji Nakamatsu\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/commits?author=snaka\" title=\"Documentation\"\u003e📖\u003c/a\u003e \u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/issues?q=author%3Asnaka\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e \u003ca href=\"#research-snaka\" title=\"Research\"\u003e🔬\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://davidmytton.blog/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/117833?v=4?s=100\" width=\"100px;\" alt=\"David Mytton\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eDavid Mytton\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#research-davidmytton\" title=\"Research\"\u003e🔬\u003c/a\u003e \u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/issues?q=author%3Adavidmytton\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e \u003ca href=\"#data-davidmytton\" title=\"Data\"\u003e🔣\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://github.com/danactive\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/1093286?v=4?s=100\" width=\"100px;\" alt=\"Dan BROOKS\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eDan BROOKS\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/commits?author=danactive\" title=\"Documentation\"\u003e📖\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://github.com/rosswilson2306\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/71711192?v=4?s=100\" width=\"100px;\" alt=\"Ross Wilson\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eRoss Wilson\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/issues?q=author%3Arosswilson2306\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e \u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/commits?author=rosswilson2306\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#research-rosswilson2306\" title=\"Research\"\u003e🔬\u003c/a\u003e \u003ca href=\"#ideas-rosswilson2306\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://github.com/bobf\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/18470?v=4?s=100\" width=\"100px;\" alt=\"bobf\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003ebobf\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/issues?q=author%3Abobf\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e \u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/commits?author=bobf\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#research-bobf\" title=\"Research\"\u003e🔬\u003c/a\u003e \u003ca href=\"#ideas-bobf\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://www.joshmengerink.nl/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/10478429?v=4?s=100\" width=\"100px;\" alt=\"Josh\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eJosh\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/issues?q=author%3Alordphnx\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e \u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/commits?author=lordphnx\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#research-lordphnx\" title=\"Research\"\u003e🔬\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://vexquisit.com/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/215671?v=4?s=100\" width=\"100px;\" alt=\"David Heidrich\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eDavid Heidrich\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/issues?q=author%3ABowlingX\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e \u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/commits?author=BowlingX\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#research-BowlingX\" title=\"Research\"\u003e🔬\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://github.com/clueleaf\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/10379303?v=4?s=100\" width=\"100px;\" alt=\"clueleaf\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eclueleaf\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#security-clueleaf\" title=\"Security\"\u003e🛡️\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://github.com/danstarns\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/35999252?v=4?s=100\" width=\"100px;\" alt=\"Daniel Starns\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eDaniel Starns\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/issues?q=author%3Adanstarns\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e \u003ca href=\"#ideas-danstarns\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"16.66%\"\u003e\u003ca href=\"https://columkelly.com/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/98435978?v=4?s=100\" width=\"100px;\" alt=\"Colum Kelly\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eColum Kelly\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/Xunnamius/next-test-api-route-handler/issues?q=author%3Acolumk1\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e \u003ca href=\"#research-columk1\" title=\"Research\"\u003e🔬\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n  \u003ctfoot\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\" size=\"13px\" colspan=\"6\"\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/all-contributors/all-contributors-cli/1b8533af435da9854653492b1327a23a4dbd0a10/assets/logo-small.svg\"\u003e\n          \u003ca href=\"https://all-contributors.js.org/docs/en/bot/usage\"\u003eAdd your contributions\u003c/a\u003e\n        \u003c/img\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tfoot\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-restore --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\u003c!-- remark-ignore-end --\u003e\n\nThis project follows the [all-contributors][x-repo-all-contributors]\nspecification. Contributions of any kind welcome!\n\n\u003c!-- symbiote-template-region-end --\u003e\n\u003c!-- symbiote-template-region-start workspace-package-only --\u003e\n\u003c!-- (section elided by symbiote) --\u003e\n\u003c!-- symbiote-template-region-end --\u003e\n\n[x-badge-blm-image]: https://xunn.at/badge-blm 'Join the movement!'\n[x-badge-blm-link]: https://xunn.at/donate-blm\n[x-badge-codecov-image]:\n  https://img.shields.io/codecov/c/github/Xunnamius/next-test-api-route-handler/main?style=flat-square\u0026token=HWRIOBAAPW\u0026flag=package.main_root\n  'Is this package well-tested?'\n[x-badge-codecov-link]:\n  https://codecov.io/gh/Xunnamius/next-test-api-route-handler\n[x-badge-downloads-image]:\n  https://img.shields.io/npm/dm/next-test-api-route-handler?style=flat-square\n  'Number of times this package has been downloaded per month'\n[x-badge-downloads-link]: https://npmtrends.com/next-test-api-route-handler\n[x-badge-lastcommit-image]:\n  https://img.shields.io/github/last-commit/Xunnamius/next-test-api-route-handler?style=flat-square\n  'Latest commit timestamp'\n[x-badge-license-image]:\n  https://img.shields.io/npm/l/next-test-api-route-handler?style=flat-square\n  \"This package's source license\"\n[x-badge-license-link]:\n  https://github.com/Xunnamius/next-test-api-route-handler/blob/main/LICENSE\n[x-badge-npm-image]:\n  https://xunn.at/npm-pkg-version/next-test-api-route-handler\n  'Install this package using npm or yarn!'\n[x-badge-npm-link]: https://npm.im/next-test-api-route-handler\n[x-badge-repo-link]: https://github.com/Xunnamius/next-test-api-route-handler\n[x-badge-semanticrelease-image]:\n  https://xunn.at/badge-semantic-release\n  'This repo practices continuous integration and deployment!'\n[x-badge-semanticrelease-link]:\n  https://github.com/semantic-release/semantic-release\n[x-pkg-cjs-mojito]:\n  https://dev.to/jakobjingleheimer/configuring-commonjs-es-modules-for-nodejs-12ed#publish-only-a-cjs-distribution-with-property-exports\n[x-pkg-dual-package-hazard]:\n  https://nodejs.org/api/packages.html#dual-package-hazard\n[x-pkg-exports-conditions]:\n  https://webpack.js.org/guides/package-exports#reference-syntax\n[x-pkg-exports-module-key]:\n  https://webpack.js.org/guides/package-exports#providing-commonjs-and-esm-version-stateless\n[x-pkg-exports-types-key]:\n  https://devblogs.microsoft.com/typescript/announcing-typescript-4-5-beta#packagejson-exports-imports-and-self-referencing\n[x-pkg-side-effects-key]:\n  https://webpack.js.org/guides/tree-shaking#mark-the-file-as-side-effect-free\n[x-pkg-tree-shaking]: https://webpack.js.org/guides/tree-shaking\n[x-pkg-type]:\n  https://github.com/nodejs/node/blob/8d8e06a345043bec787e904edc9a2f5c5e9c275f/doc/api/packages.md#type\n[x-repo-all-contributors]: https://github.com/all-contributors/all-contributors\n[x-repo-all-contributors-emojis]: https://allcontributors.org/docs/en/emoji-key\n[x-repo-choose-new-issue]:\n  https://github.com/Xunnamius/next-test-api-route-handler/issues/new/choose\n[x-repo-contributing]: /CONTRIBUTING.md\n[x-repo-docs]: docs\n[x-repo-license]: ./LICENSE\n[x-repo-package-json]: package.json\n[x-repo-pr-compare]:\n  https://github.com/Xunnamius/next-test-api-route-handler/compare\n[x-repo-sponsor]: https://github.com/sponsors/Xunnamius\n[x-repo-support]: /.github/SUPPORT.md\n[1]: https://nextjs.org/docs/app/api-reference/functions/next-request\n[2]: https://nextjs.org/docs/app/building-your-application/routing\n[3]: https://nextjs.org/docs/app/api-reference/functions\n[4]: https://nextjs.org/docs/api-routes/introduction\n[5]: https://nextjs.org/docs/basic-features/typescript#api-routes\n[6]:\n  https://github.com/Xunnamius/next-test-api-route-handler/actions/workflows/is-next-compat.yml\n[7]: https://github.com/vercel/next.js/releases\n[8]:\n  https://github.com/Xunnamius/next-test-api-route-handler/issues/999#issuecomment-1956787672\n[9]: #legacy-runtime-support\n[10]: #jsdom-support\n[11]: #working-around-global-asynclocalstorage-availability\n[12]: #usage\n[13]:\n  https://github.com/Xunnamius/next-test-api-route-handler/blob/main/docs/src/interfaces/NtarhInitAppRouter.md#appHandler\n[14]:\n  https://github.com/vercel/next.js/blob/0aa0179246d4e59f74cd1d62e3beb8e9b670fc4e/packages/next/src/server/web/http.ts#L5\n[15]:\n  https://github.com/vercel/next.js/blob/0aa0179246d4e59f74cd1d62e3beb8e9b670fc4e/packages/next/src/server/future/route-modules/app-route/module.ts#L75\n[16]:\n  https://github.com/vercel/next.js/blob/0aa0179246d4e59f74cd1d62e3beb8e9b670fc4e/packages/next/src/server/future/route-modules/app-route/module.ts#L84\n[17]:\n  https://github.com/vercel/next.js/blob/0aa0179246d4e59f74cd1d62e3beb8e9b670fc4e/packages/next/src/server/future/route-modules/app-route/module.ts#L100C4-L100C4\n[18]: #rejectonhandlererror\n[19]: #working-around-the-app-router-patching-the-global-fetch-function\n[20]:\n  https://github.com/Xunnamius/next-test-api-route-handler/blob/main/docs/src/interfaces/NtarhInitPagesRouter.md#pagesHandler\n[21]:\n  https://github.com/Xunnamius/next-test-api-route-handler/blob/main/docs/src/interfaces/NtarhInit.md#test\n[22]: https://nodejs.org/dist/latest-v18.x/docs/api/globals.html#fetch\n[23]: https://developer.mozilla.org/en-US/docs/Web/API/fetch#resource\n[24]: https://developer.mozilla.org/en-US/docs/Web/API/fetch#options\n[25]: https://developer.mozilla.org/en-US/docs/Web/API/fetch#redirect\n[26]: https://mswjs.io\n[27]:\n  https://github.com/mswjs/msw/blob/a037e3a3f4f4d4cc712d2b3867b3410e4bcfaad6/src/core/bypass.ts#L33C29-L33C44\n[28]: https://nextjs.org/docs/app/api-reference/functions/redirect\n[29]:\n  https://nextjs.org/docs/pages/building-your-application/routing/api-routes#redirects-to-a-specified-path-or-url\n[30]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie\n[31]: https://www.npmjs.com/package/cookie\n[32]: ./test/unit-index.test.ts\n[33]:\n  https://github.com/Xunnamius/next-test-api-route-handler/blob/main/docs/src/interfaces/NtarhInit.md#rejectOnHandlerError\n[34]:\n  https://github.com/vercel/next.js/blob/f4e49377ac3ca2807f773bc1dcd5375c89bde9ef/packages/next/server/api-utils.ts#L134\n[35]: #testing-nextjss-official-apollo-example--pagesapigraphql\n[36]: #testing-an-authenticated-flight-search-handler--pagesapiv3flightssearch\n[37]:\n  https://github.com/Xunnamius/next-test-api-route-handler/blob/main/docs/src/interfaces/NtarhInitAppRouter.md#requestpatcher\n[38]:\n  https://github.com/Xunnamius/next-test-api-route-handler/blob/main/docs/src/interfaces/NtarhInitAppRouter.md#url\n[39]: https://developer.mozilla.org/en-US/docs/Web/API/Request\n[40]: https://nextjs.org/docs/messages/middleware-relative-urls\n[41]:\n  https://github.com/Xunnamius/next-test-api-route-handler/blob/main/docs/src/interfaces/NtarhInitPagesRouter.md#requestpatcher\n[42]:\n  https://github.com/Xunnamius/next-test-api-route-handler/blob/main/docs/src/interfaces/NtarhInitPagesRouter.md#url\n[43]: https://nodejs.org/api/http.html#http_class_http_incomingmessage\n[44]: https://developer.mozilla.org/en-US/docs/Web/API/URL/URL#url\n[45]:\n  https://github.com/Xunnamius/next-test-api-route-handler/blob/main/docs/src/interfaces/NtarhInitAppRouter.md#responsePatcher\n[46]: https://developer.mozilla.org/en-US/docs/Web/API/Response\n[47]:\n  https://github.com/Xunnamius/next-test-api-route-handler/blob/main/docs/src/interfaces/NtarhInitPagesRouter.md#responsePatcher\n[48]: https://nodejs.org/api/http.html#http_class_http_serverresponse\n[49]:\n  https://nextjs.org/docs/app/building-your-application/routing/dynamic-routes\n[50]:\n  https://github.com/Xunnamius/next-test-api-route-handler/blob/main/docs/src/interfaces/NtarhInitAppRouter.md#paramsPatcher\n[51]:\n  https://github.com/Xunnamius/next-test-api-route-handler/blob/main/docs/src/interfaces/NtarhInitAppRouter.md#params\n[52]: https://github.com/vercel/next.js/pull/70568\n[53]:\n  https://nextjs.org/docs/app/building-your-application/upgrading/version-15#params--searchparams\n[54]: https://en.wikipedia.org/wiki/Query_string\n[55]:\n  https://github.com/Xunnamius/next-test-api-route-handler/blob/main/docs/src/interfaces/NtarhInitPagesRouter.md#paramsPatcher\n[56]:\n  https://github.com/Xunnamius/next-test-api-route-handler/blob/main/docs/src/interfaces/NtarhInitPagesRouter.md#params\n[57]: #using-the-app-router\n[58]: #using-the-pages-router\n[59]: test/unit-index.test.ts\n[60]: https://nextjs.org/docs/app\n[61]:\n  https://www.npmjs.com/package/@as-integrations/next/v/3.0.0#app-router-route-handlers\n[62]: https://docs.microsoft.com/en-us/windows/wsl/install-win10\n[63]: ./apollo_test_raw_app_route\n[64]: ./apollo_test_raw_app_test\n[65]: https://www.npmjs.com/package/jest\n[66]: https://github.com/clerk/clerk-nextjs-demo-app-router\n[67]: https://clerk.com/docs/quickstarts/nextjs\n[68]: https://clerk.com/docs/references/nextjs/auth-middleware\n[69]:\n  https://github.com/clerk/javascript/blob/434a96ebefc550b726b417788b7bae9e41791408/packages/nextjs/src/server/authMiddleware.test.ts#L4\n[70]: https://nextjs.org/docs/pages\n[71]:\n  https://github.com/vercel/next.js/tree/deprecated-main/examples/api-routes-apollo-server-and-client\n[72]: https://github.com/vercel/next.js\n[73]: ./apollo_test_raw\n[74]: https://nextjs.org/docs/api-routes/api-middlewares#custom-config\n[75]: https://github.com/Xunnamius/next-test-api-route-handler/issues/56\n[76]: https://nextjs.org/docs/app/building-your-application/routing/middleware\n[77]: #requestpatcher-url\n[78]: https://nextjs.org/docs/app/building-your-application/optimizing#metadata\n[79]:\n  https://nextjs.org/docs/app/building-your-application/optimizing#static-assets\n[80]:\n  https://nextjs.org/docs/pages/building-your-application/optimizing/open-telemetry\n[81]:\n  https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation\n[82]: https://nextjs.org/docs/app/building-your-application/caching\n[83]: https://nextjs.org/docs/app/building-your-application/styling\n[84]:\n  https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations\n[85]: https://nextjs.org/docs/app/api-reference/components\n[86]:\n  https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#runtime\n[87]:\n  https://github.com/vercel/next.js/blob/0aa0179246d4e59f74cd1d62e3beb8e9b670fc4e/packages/next/src/server/future/route-modules/app-route/module.ts#L118C24-L118C24\n[88]:\n  https://nextjs.org/docs/app/building-your-application/testing#types-of-tests\n[89]: https://github.com/vercel/next.js/discussions/46722\n[90]: https://github.com/mswjs/msw/issues/1644\n[91]: https://github.com/mswjs/msw\n[92]: https://github.com/Xunnamius/next-test-api-route-handler/discussions/953\n[93]: https://nextjs.org/blog/next-9\n[94]: https://github.com/vercel/next.js/pull/8613\n[95]:\n  https://github.blog/2021-02-02-npm-7-is-now-generally-available#peer-dependencies\n[96]:\n  https://github.com/vercel/next.js/blob/v9.0.0/packages/next/package.json#L106-L109\n[97]: https://github.com/jestjs/jest/issues/13834#issuecomment-1407375787\n[98]: https://github.com/jsdom/jsdom/issues/1724\n[99]:\n  https://stackoverflow.com/questions/74945569/cannot-access-built-in-node-js-fetch-function-from-jest-tests\n[100]:\n  https://github.com/vercel/next.js/blob/90f95399ddfd036624c69b09910f40fa36c00ac2/packages/next/src/server/api-utils/node/api-resolver.ts#L321\n[101]: ./very-first-version-of-ntarh.png\n[102]:\n  https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/order.md#limitations-of---fix\n","funding_links":["https://github.com/sponsors/Xunnamius"],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FXunnamius%2Fnext-test-api-route-handler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FXunnamius%2Fnext-test-api-route-handler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FXunnamius%2Fnext-test-api-route-handler/lists"}