Skip to content

Commit

Permalink
feat!: land initial App Router support
Browse files Browse the repository at this point in the history
Closes #938, #773

BREAKING CHANGE: `NtarhParameters` has been superseded by `NtarhInit`,
`NtarhInitAppRouter`, and `NtarhInitPagesRouter`.

BREAKING CHANGE: the `handler` option of `testApiHandler` (i.e.
`testApiHandler({ handler })`) has been renamed to `pagesHandler`. It is
otherwise functionally equivalent.

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

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

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

BREAKING CHANGE: `requestPatcher`, `reponsePatcher`, and `paramsPatcher` options
of `testApiHandler({ ... })` no longer support parenthetical shorthand notation.
For example, the following will cause a type error:
`testApiHandler({ paramsPatcher: (params) => (params.id = "some-id") })`.

BREAKING CHANGE: this version of NTARH is now actively tracking a second Next.js
internal export, one that is not guaranteed to be available before
`next@14.0.4`. Therefore, versions of Next.js older than 14.0.4 **explicitly
unsupported** when using the `appHandler` option. On the other hand,
`pagesHandler` will always work regardless of Next.js version until Vercel
eventually removes the Pages Router functionality entirely.

BREAKING CHANGE: the `pagesHandler` option of `testApiHandler` (i.e.
`testApiHandler({ pagesHandler })`) will **not** accept edge runtime routes. To
test your edge runtime routes, use the `appHandler` option instead.
  • Loading branch information
Xunnamius committed Jan 9, 2024
1 parent c79969e commit e2d8865
Show file tree
Hide file tree
Showing 5 changed files with 968 additions and 644 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ it('returns expected public flights with respect to match', async () => {
// against our handler. Query strings are parsed by NTARH automatically.
//
// NOTE: setting the request url manually using encode(), while valid, is
// unnecessary here; we could have used `params` or `paramPatcher` to do this
// unnecessary here; we could have used `params` or `paramsPatcher` to do this
// more easily without explicitly setting a dummy request url.
//
// Example URI for `https://site.io/path?param=yes` would be `/path?param=yes`
Expand Down

0 comments on commit e2d8865

Please sign in to comment.