diff --git a/test/basic.test.ts b/test/basic.test.ts
index f937d7e5d0..a7ad8688c9 100644
--- a/test/basic.test.ts
+++ b/test/basic.test.ts
@@ -8,30 +8,133 @@ describe('fixtures:basic', async () => {
server: true
})
- it('server api', async () => {
- expect(await $fetch('/api/hello')).toBe('Hello API')
- expect(await $fetch('/api/hey')).toEqual({
- foo: 'bar',
- baz: 'qux'
+ describe('server api', () => {
+ it('should serialize', async () => {
+ expect(await $fetch('/api/hello')).toBe('Hello API')
+ expect(await $fetch('/api/hey')).toEqual({
+ foo: 'bar',
+ baz: 'qux'
+ })
+ })
+
+ it('should preserve states', async () => {
+ expect(await $fetch('/api/counter')).toEqual({ count: 0 })
+ expect(await $fetch('/api/counter')).toEqual({ count: 1 })
+ expect(await $fetch('/api/counter')).toEqual({ count: 2 })
+ expect(await $fetch('/api/counter')).toEqual({ count: 3 })
})
})
- it('render index.html', async () => {
- const index = await $fetch('/')
+ describe('pages', () => {
+ it('render index', async () => {
+ const html = await $fetch('/')
- // Snapshot
- // expect(index).toMatchInlineSnapshot()
+ // Snapshot
+ // expect(html).toMatchInlineSnapshot()
- // should render text
- expect(index).toContain('Hello Nuxt 3!')
- // should render
components
- expect(index).toContain('Basic fixture')
- // should inject runtime config
- expect(index).toContain('RuntimeConfig: 123')
- // should import components
- expect(index).toContain('This is a custom component with a named export.')
- // composables auto import
- expect(index).toContain('auto imported from ~/components/foo.ts')
- expect(index).toContain('auto imported from ~/components/useBar.ts')
+ // should render text
+ expect(html).toContain('Hello Nuxt 3!')
+ // should render components
+ expect(html).toContain('Basic fixture')
+ // should inject runtime config
+ expect(html).toContain('RuntimeConfig | testConfig: 123')
+ // composables auto import
+ expect(html).toContain('Composable | foo: auto imported from ~/components/foo.ts')
+ expect(html).toContain('Composable | bar: auto imported from ~/components/useBar.ts')
+ // plugins
+ expect(html).toContain('Plugin | myPlugin: Injected by my-plugin')
+ // should import components
+ expect(html).toContain('This is a custom component with a named export.')
+ })
+
+ it('render 404', async () => {
+ const html = await $fetch('/not-found')
+
+ // Snapshot
+ // expect(html).toMatchInlineSnapshot()
+
+ expect(html).toContain('[...slug].vue')
+ expect(html).toContain('404 at not-found')
+ })
+
+ it('/nested/[foo]/[bar].vue', async () => {
+ const html = await $fetch('/nested/one/two')
+
+ // Snapshot
+ // expect(html).toMatchInlineSnapshot()
+
+ expect(html).toContain('nested/[foo]/[bar].vue')
+ expect(html).toContain('foo: one')
+ expect(html).toContain('bar: two')
+ })
+
+ it('/nested/[foo]/index.vue', async () => {
+ const html = await $fetch('/nested/foobar')
+
+ // TODO: should resolved to same entry
+ // const html2 = await $fetch('/nested/foobar/index')
+ // expect(html).toEqual(html2)
+
+ // Snapshot
+ // expect(html).toMatchInlineSnapshot()
+
+ expect(html).toContain('nested/[foo]/index.vue')
+ expect(html).toContain('foo: foobar')
+ })
+
+ it('/nested/[foo]/user-[group].vue', async () => {
+ const html = await $fetch('/nested/foobar/user-admin')
+
+ // Snapshot
+ // expect(html).toMatchInlineSnapshot()
+
+ expect(html).toContain('nested/[foo]/user-[group].vue')
+ expect(html).toContain('foo: foobar')
+ expect(html).toContain('group: admin')
+ })
+ })
+
+ describe('middlewares', () => {
+ it('should redirect to index with global middleware', async () => {
+ const html = await $fetch('/redirect/')
+
+ // Snapshot
+ // expect(html).toMatchInlineSnapshot()
+
+ expect(html).toContain('Hello Nuxt 3!')
+ })
+
+ it('should inject auth', async () => {
+ const html = await $fetch('/auth')
+
+ // Snapshot
+ // expect(html).toMatchInlineSnapshot()
+
+ expect(html).toContain('auth.vue')
+ expect(html).toContain('auth: Injected by injectAuth middleware')
+ })
+
+ it('should not inject auth', async () => {
+ const html = await $fetch('/no-auth')
+
+ // Snapshot
+ // expect(html).toMatchInlineSnapshot()
+
+ expect(html).toContain('no-auth.vue')
+ expect(html).toContain('auth: ')
+ expect(html).not.toContain('Injected by injectAuth middleware')
+ })
+ })
+
+ describe('layouts', () => {
+ it('should apply custom layout', async () => {
+ const html = await $fetch('/with-layout')
+
+ // Snapshot
+ // expect(html).toMatchInlineSnapshot()
+
+ expect(html).toContain('with-layout.vue')
+ expect(html).toContain('Custom Layout:')
+ })
})
})
diff --git a/test/fixtures/basic/layouts/PascalCase.js b/test/fixtures/basic/layouts/PascalCase.ts
similarity index 100%
rename from test/fixtures/basic/layouts/PascalCase.js
rename to test/fixtures/basic/layouts/PascalCase.ts
diff --git a/test/fixtures/basic/layouts/custom.vue b/test/fixtures/basic/layouts/custom.vue
new file mode 100644
index 0000000000..e7938d8f69
--- /dev/null
+++ b/test/fixtures/basic/layouts/custom.vue
@@ -0,0 +1,6 @@
+
+
+ Custom Layout:
+
+
+
diff --git a/test/fixtures/basic/layouts/test-layout.js b/test/fixtures/basic/layouts/test-layout.js
deleted file mode 100644
index e69de29bb2..0000000000
diff --git a/test/fixtures/basic/middleware/PascalCase.js b/test/fixtures/basic/middleware/PascalCase.js
deleted file mode 100644
index e69de29bb2..0000000000
diff --git a/test/fixtures/basic/middleware/injectAuth.ts b/test/fixtures/basic/middleware/injectAuth.ts
new file mode 100644
index 0000000000..30801347ae
--- /dev/null
+++ b/test/fixtures/basic/middleware/injectAuth.ts
@@ -0,0 +1,3 @@
+export default defineNuxtRouteMiddleware((to) => {
+ to.meta.auth = 'Injected by injectAuth middleware'
+})
diff --git a/test/fixtures/basic/middleware/redirect.global.ts b/test/fixtures/basic/middleware/redirect.global.ts
new file mode 100644
index 0000000000..9d7f4fe541
--- /dev/null
+++ b/test/fixtures/basic/middleware/redirect.global.ts
@@ -0,0 +1,5 @@
+export default defineNuxtRouteMiddleware((to) => {
+ if (to.path.startsWith('/redirect/')) {
+ return navigateTo(to.path.slice('/redirect/'.length - 1))
+ }
+})
diff --git a/test/fixtures/basic/middleware/test-middleware.js b/test/fixtures/basic/middleware/test-middleware.js
deleted file mode 100644
index e69de29bb2..0000000000
diff --git a/test/fixtures/basic/nuxt.config.ts b/test/fixtures/basic/nuxt.config.ts
index 059d1a7041..a3fb219710 100644
--- a/test/fixtures/basic/nuxt.config.ts
+++ b/test/fixtures/basic/nuxt.config.ts
@@ -8,7 +8,6 @@ export default defineNuxtConfig({
output: { dir: process.env.NITRO_OUTPUT_DIR }
},
publicRuntimeConfig: {
- // @ts-ignore TODO: Fix schema types
testConfig: '123'
},
modules: ['~/modules/example'],
diff --git a/test/fixtures/basic/pages/[...slug].vue b/test/fixtures/basic/pages/[...slug].vue
new file mode 100644
index 0000000000..47a02c1123
--- /dev/null
+++ b/test/fixtures/basic/pages/[...slug].vue
@@ -0,0 +1,6 @@
+
+
+
[...slug].vue
+
404 at {{ $route.params.slug[0] }}
+
+
diff --git a/test/fixtures/basic/pages/auth.vue b/test/fixtures/basic/pages/auth.vue
new file mode 100644
index 0000000000..034a251b0b
--- /dev/null
+++ b/test/fixtures/basic/pages/auth.vue
@@ -0,0 +1,12 @@
+
+
+
+
+
auth.vue
+
auth: {{ $route.meta.auth }}
+
+
diff --git a/test/fixtures/basic/pages/index.vue b/test/fixtures/basic/pages/index.vue
index 49bdab3c3b..f67e352814 100644
--- a/test/fixtures/basic/pages/index.vue
+++ b/test/fixtures/basic/pages/index.vue
@@ -4,9 +4,10 @@
Basic fixture
Hello Nuxt 3!
- RuntimeConfig: {{ config.testConfig }}
- {{ foo }}
- {{ bar }}
+ RuntimeConfig | testConfig: {{ config.testConfig }}
+ Composable | foo: {{ foo }}
+ Composable | bar: {{ bar }}
+ Plugin | myPlugin: {{ $myPlugin() }}
diff --git a/test/fixtures/basic/pages/nested/[foo]/[bar].vue b/test/fixtures/basic/pages/nested/[foo]/[bar].vue
new file mode 100644
index 0000000000..2f0a50e69f
--- /dev/null
+++ b/test/fixtures/basic/pages/nested/[foo]/[bar].vue
@@ -0,0 +1,7 @@
+
+
+
nested/[foo]/[bar].vue
+
foo: {{ $route.params.foo }}
+
bar: {{ $route.params.bar }}
+
+
diff --git a/test/fixtures/basic/pages/nested/[foo]/index.vue b/test/fixtures/basic/pages/nested/[foo]/index.vue
new file mode 100644
index 0000000000..b2ea680a54
--- /dev/null
+++ b/test/fixtures/basic/pages/nested/[foo]/index.vue
@@ -0,0 +1,6 @@
+
+
+
nested/[foo]/index.vue
+
foo: {{ $route.params.foo }}
+
+
diff --git a/test/fixtures/basic/pages/nested/[foo]/user-[group].vue b/test/fixtures/basic/pages/nested/[foo]/user-[group].vue
new file mode 100644
index 0000000000..027545a80f
--- /dev/null
+++ b/test/fixtures/basic/pages/nested/[foo]/user-[group].vue
@@ -0,0 +1,7 @@
+
+
+
nested/[foo]/user-[group].vue
+
foo: {{ $route.params.foo }}
+
group: {{ $route.params.group }}
+
+
diff --git a/test/fixtures/basic/pages/no-auth.vue b/test/fixtures/basic/pages/no-auth.vue
new file mode 100644
index 0000000000..0fc01f77c9
--- /dev/null
+++ b/test/fixtures/basic/pages/no-auth.vue
@@ -0,0 +1,12 @@
+
+
+
+
+
no-auth.vue
+
auth: {{ $route.meta.auth }}
+
+
diff --git a/test/fixtures/basic/pages/with-layout.vue b/test/fixtures/basic/pages/with-layout.vue
new file mode 100644
index 0000000000..c7f73bc774
--- /dev/null
+++ b/test/fixtures/basic/pages/with-layout.vue
@@ -0,0 +1,11 @@
+
+
+
+
+
diff --git a/test/fixtures/basic/plugins/my-plugin.ts b/test/fixtures/basic/plugins/my-plugin.ts
new file mode 100644
index 0000000000..264cd636ff
--- /dev/null
+++ b/test/fixtures/basic/plugins/my-plugin.ts
@@ -0,0 +1,7 @@
+export default defineNuxtPlugin(() => {
+ return {
+ provide: {
+ myPlugin: () => 'Injected by my-plugin'
+ }
+ }
+})
diff --git a/test/fixtures/basic/server/api/counter.ts b/test/fixtures/basic/server/api/counter.ts
new file mode 100644
index 0000000000..8c33e3545d
--- /dev/null
+++ b/test/fixtures/basic/server/api/counter.ts
@@ -0,0 +1,3 @@
+let counter = 0
+
+export default () => ({ count: counter++ })
diff --git a/test/fixtures/basic/types.ts b/test/fixtures/basic/types.ts
index d7e6446e5e..78e6c0f1f9 100644
--- a/test/fixtures/basic/types.ts
+++ b/test/fixtures/basic/types.ts
@@ -40,9 +40,10 @@ describe('aliases', () => {
})
describe('middleware', () => {
- it('recognises named middleware', () => {
- definePageMeta({ middleware: 'test-middleware' })
- definePageMeta({ middleware: 'pascal-case' })
+ it('recognizes named middleware', () => {
+ definePageMeta({ middleware: 'inject-auth' })
+ // @ts-expect-error ignore global middleware
+ definePageMeta({ middleware: 'redirect' })
// @ts-expect-error Invalid middleware
definePageMeta({ middleware: 'invalid-middleware' })
})
@@ -62,8 +63,8 @@ describe('middleware', () => {
})
describe('layouts', () => {
- it('recognises named layouts', () => {
- definePageMeta({ layout: 'test-layout' })
+ it('recognizes named layouts', () => {
+ definePageMeta({ layout: 'custom' })
definePageMeta({ layout: 'pascal-case' })
// @ts-expect-error Invalid layout
definePageMeta({ layout: 'invalid-layout' })