Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9719a5b

Browse files
authored
feat(runtime-utils): support h3 v2 (#1515)
1 parent 2c0864e commit 9719a5b

20 files changed

Lines changed: 1751 additions & 151 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// https://nuxt.com/docs/api/configuration/nuxt-config
2+
export default defineNuxtConfig({
3+
devtools: { enabled: true },
4+
compatibilityDate: '2024-04-03',
5+
})
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "example-nitro-v3",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"build": "nuxt build",
7+
"dev": "nuxt dev",
8+
"generate": "nuxt generate",
9+
"preview": "nuxt preview",
10+
"postinstall": "nuxt prepare",
11+
"test": "vitest run"
12+
},
13+
"dependencies": {
14+
"h3": "^2.0.1-rc.7",
15+
"nitro": "https://pkg.pr.new/nitrojs/nitro@00598a8",
16+
"nuxt": "https://pkg.pr.new/nuxt@33005"
17+
},
18+
"devDependencies": {
19+
"@nuxt/test-utils": "latest",
20+
"happy-dom": "20.0.11",
21+
"playwright-core": "1.57.0",
22+
"tinyglobby": "0.2.15",
23+
"typescript": "5.9.3",
24+
"vitest": "3.2.4"
25+
}
26+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { describe, expect, it } from 'vitest'
2+
3+
describe('my test', () => {
4+
// ... test with Nuxt environment!
5+
it('works', () => {
6+
expect(Object.keys(useAppConfig())).toMatchInlineSnapshot(`
7+
[
8+
"nuxt",
9+
]
10+
`)
11+
})
12+
})
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { registerEndpoint } from '@nuxt/test-utils/runtime'
2+
import { it, expect, describe } from 'vitest'
3+
4+
describe('registerEndpoint tests', () => {
5+
it('works with h3 v2 syntax', async () => {
6+
registerEndpoint('/test1/', event => new Response(event.req.headers.get('x-custom-header') || ''))
7+
8+
const fetchOptions = {
9+
headers: { 'x-custom-header': 'my-value' },
10+
}
11+
12+
expect(await $fetch('/test1/', fetchOptions)).toBe('my-value')
13+
expect(await fetch('/test1/', fetchOptions).then(r => r.text())).toBe('my-value')
14+
})
15+
})
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { fileURLToPath } from 'node:url'
2+
import { $fetch, setup } from '@nuxt/test-utils/e2e'
3+
import { describe, expect, it } from 'vitest'
4+
5+
describe.todo('app', async () => {
6+
await setup({
7+
rootDir: fileURLToPath(new URL('../', import.meta.url)),
8+
})
9+
it('runs a test', async () => {
10+
const html = await $fetch<string>('/')
11+
expect(html.slice(0, 15)).toMatchInlineSnapshot(`
12+
"<!DOCTYPE html>"
13+
`)
14+
})
15+
})
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"files": [],
3+
"references": [
4+
{
5+
"path": "./.nuxt/tsconfig.app.json"
6+
},
7+
{
8+
"path": "./.nuxt/tsconfig.server.json"
9+
},
10+
{
11+
"path": "./.nuxt/tsconfig.shared.json"
12+
},
13+
{
14+
"path": "./.nuxt/tsconfig.node.json"
15+
}
16+
]
17+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { defineConfig } from 'vitest/config'
2+
import { defineVitestProject } from '@nuxt/test-utils/config'
3+
4+
export default defineConfig({
5+
test: {
6+
projects: [
7+
await defineVitestProject({
8+
test: {
9+
name: 'nuxt',
10+
include: ['**/nuxt/*.spec.ts'],
11+
},
12+
}),
13+
{
14+
test: {
15+
name: 'unit',
16+
include: ['**/*.e2e.spec.ts'],
17+
},
18+
},
19+
],
20+
},
21+
})

‎package.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"fake-indexeddb": "^6.2.5",
7878
"get-port-please": "^3.2.0",
7979
"h3": "^1.15.4",
80+
"h3-next": "npm:h3@^2.0.1-rc.6",
8081
"local-pkg": "^1.1.2",
8182
"magic-string": "^0.30.21",
8283
"node-fetch-native": "^1.6.7",
@@ -174,14 +175,15 @@
174175
"@nuxt/schema": "4.2.2",
175176
"@nuxt/test-utils": "workspace:*",
176177
"@types/node": "24.10.4",
178+
"nitro": "https://pkg.pr.new/nitrojs/nitro@00598a8",
177179
"rollup": "4.54.0",
178180
"vite": "7.3.0",
179181
"vite-node": "5.2.0",
180182
"vitest": "3.2.4",
181183
"vue": "^3.5.26"
182184
},
183185
"engines": {
184-
"node": "^20.0.0 || ^22.0.0 || >=24.0.0"
186+
"node": "^20.11.1 || ^22.0.0 || >=24.0.0"
185187
},
186188
"packageManager": "[email protected]"
187189
}

0 commit comments

Comments
 (0)