Releases: johannschopplich/nitro-test-utils
v3.0.0
🚨 Breaking Changes
- Infer
$fetchRawresponses from Nitro'sInternalApi- by @johannschopplich (92017) - Replace HTTP test server with in-process dispatch - by @johannschopplich (f62b5)
🚀 Features
- Add
listRouteshelper for route introspection - by @johannschopplich (f450a)
📖 Migration Guide
In-process request dispatch
v3 stops starting a real HTTP listener for your tests. Instead, the Nitro app is dispatched in-process – each request is handed directly to the app's Web Request handler, the same code path every cloud preset invokes at runtime. No ports, no sockets, no localhost round-trip.
This removes injectServerUrl. Replace it with injectNitroFetch, which returns the raw request dispatcher:
-import { injectServerUrl } from 'nitro-test-utils/e2e'
-const url = injectServerUrl()
+import { injectNitroFetch } from 'nitro-test-utils/e2e'
+const nitroFetch = injectNitroFetch()
+const response = await nitroFetch(new Request('http://nitro.test/api/health'))Typed $fetchRaw responses
$fetchRaw now inherits route-level typing from Nitro's InternalApi augmentation. Its first generic default changed from T = any to T = unknown, so call sites that dereference data without narrowing will fail to type-check.
The preferred fix is to set up Nitro's type augmentation so $fetchRaw picks up handler return types automatically – see Route-Level Response Types. Where that isn't practical, pass an explicit generic:
-const { data } = await $fetchRaw('/api/users')
-expect(data.id).toBe(1)
+const { data } = await $fetchRaw<{ id: number }>('/api/users')
+expect(data?.id).toBe(1)Note
The second generic on $fetchRaw previously accepted ofetch's ResponseType ('json', 'text', …). It now represents the request route. This only affects code that passed an explicit second generic – a rarely-used call shape.
View changes on GitHub
v2.0.3
🐞 Bug Fixes
- config: Preserve user
globalSetupentries alongside global worker - by @johannschopplich in #22 (b2e29)
View changes on GitHub
v2.0.2
🐞 Bug Fixes
- Rename
NitroInlineConfigtoNitroTestConfig- by @johannschopplich (23f40)
View changes on GitHub
v2.0.1
🐞 Bug Fixes
- Import
UserConfigtype fromvitest/configto include Vitest augmentation - by @johannschopplich (52390)
View changes on GitHub
v2.0.0
🚨 Breaking Changes
- Move Nitro config to second argument of
defineConfig- by @johannschopplich (5ad1b)
📖 Migration Guide
Nitro options as second argument
Nitro v3 ships an official Vite plugin (nitro/vite) that claims the nitro key on Vite's UserConfig for server configuration. Since nitro-test-utils v1 used the same key for test runner configuration, this caused a TypeScript type collision when both packages were used together (#20).
defineConfig now accepts the Nitro test options as a second argument instead of a key on the Vite config. This eliminates the module augmentation entirely – no shared key, no collision, no risk of this happening again.
The update is a one-line change. Move the nitro config object from inside the first argument to the second:
import { defineConfig } from 'nitro-test-utils/config'
-export default defineConfig({
- nitro: {
- global: true,
- },
-})
+export default defineConfig({}, {
+ global: true,
+})If you're using custom options, the same pattern applies:
-export default defineConfig({
- nitro: {
- global: {
- rootDir: 'backend',
- mode: 'production',
- },
- rerunOnSourceChanges: false,
- },
-})
+export default defineConfig({}, {
+ global: {
+ rootDir: 'backend',
+ mode: 'production',
+ },
+ rerunOnSourceChanges: false,
+})View changes on GitHub
v1.4.0
v1.3.0
🚀 Features
- Add
nitro-test-utils/envsubpath export forimport.meta.testtypes - by @johannschopplich (27c35)
View changes on GitHub
v1.2.0
🐞 Bug Fixes
- Resolve dev server port conflict by using
get-port-please- by @johannschopplich (4d98a)
View changes on GitHub
v1.1.0
🚀 Features
- Local cloudflare worker testing - by @johannschopplich (39632)
🐞 Bug Fixes
- Default
retry: 0increateNitroFetchto prevent masked test failures - by @johannschopplich (2778a)
View changes on GitHub
v1.0.0
🚨 Breaking Changes
- Support for Nitro v3 - by @johannschopplich (aca3c)
🚀 Features
- Support shared cookies between tests - by @johannschopplich in #9 (d656b)
🐞 Bug Fixes
- Align buildDir and tsconfig with Nitro v3 defaults - by @johannschopplich and Claude Opus 4.6 (0e00b)
forceRerunTriggersduplication - by @johannschopplich (c08cd)- Add missing Vitest augmentation for config - by @johannschopplich (dc31c)
🏎 Performance
- Drop
pathe- by @johannschopplich (0ccf2)