Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: merge issue #2758 test #2868

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions specs/fixtures/issues/2758/app.vue

This file was deleted.

23 changes: 0 additions & 23 deletions specs/fixtures/issues/2758/nuxt.config.ts

This file was deleted.

14 changes: 0 additions & 14 deletions specs/fixtures/issues/2758/package.json

This file was deleted.

3 changes: 0 additions & 3 deletions specs/fixtures/issues/2758/pages/index.vue

This file was deleted.

15 changes: 0 additions & 15 deletions specs/issues/2758.spec.ts

This file was deleted.

38 changes: 34 additions & 4 deletions specs/routing_strategies/root_redirect.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { test, expect } from 'vitest'
import { fileURLToPath } from 'node:url'
import { setup, url, fetch } from '../utils'
import { startServerWithRuntimeConfig } from '../helper'

await setup({
rootDir: fileURLToPath(new URL(`../fixtures/basic`, import.meta.url)),
Expand All @@ -10,12 +11,41 @@ await setup({
i18n: {
strategy: 'prefix',
defaultLocale: 'en',
rootRedirect: 'fr'
// configure `rootDirect` to object so it can be overwritten by `runtimeConfig`
rootRedirect: { path: 'about', statusCode: 302 }
}
}
})

test('can redirect to rootRedirect option path', async () => {
const res = await fetch('/')
expect(res.url).toBe(url('/fr'))
describe('rootRedirect', async () => {
test('can redirect to rootRedirect option path', async () => {
const restore = await startServerWithRuntimeConfig({
public: {
i18n: {
rootRedirect: 'fr'
}
}
})

const res = await fetch('/')
expect(res.url).toBe(url('/fr'))

await restore()
})

test('(#2758) `statusCode` in `rootRedirect` should work with strategy "prefix"', async () => {
const restore = await startServerWithRuntimeConfig({
public: {
i18n: {
rootRedirect: { statusCode: 418, path: 'test-route' }
}
}
})

const res = await fetch(url('/'))
expect(res.status).toEqual(418)
expect(res.headers.get('location')).toEqual('/en/test-route')

await restore()
})
})