2022-04-15 15:19:05 +00:00
|
|
|
import { fileURLToPath } from 'node:url'
|
2022-02-18 18:14:57 +00:00
|
|
|
import { describe, expect, it } from 'vitest'
|
2022-04-07 11:28:04 +00:00
|
|
|
// import { isWindows } from 'std-env'
|
2022-03-24 12:33:42 +00:00
|
|
|
import { setup, fetch, $fetch, startServer } from '@nuxt/test-utils'
|
2022-04-05 18:38:23 +00:00
|
|
|
import { expectNoClientErrors } from './utils'
|
2022-02-18 18:14:57 +00:00
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
await setup({
|
|
|
|
rootDir: fileURLToPath(new URL('./fixtures/basic', import.meta.url)),
|
2022-04-05 18:38:23 +00:00
|
|
|
server: true,
|
|
|
|
browser: true
|
2022-03-22 18:12:54 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
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'
|
2022-03-08 18:03:21 +00:00
|
|
|
})
|
2022-03-22 18:12:54 +00:00
|
|
|
})
|
2022-03-08 18:03:21 +00:00
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
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 })
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('pages', () => {
|
|
|
|
it('render index', async () => {
|
|
|
|
const html = await $fetch('/')
|
|
|
|
|
|
|
|
// Snapshot
|
|
|
|
// expect(html).toMatchInlineSnapshot()
|
|
|
|
|
|
|
|
// should render text
|
|
|
|
expect(html).toContain('Hello Nuxt 3!')
|
|
|
|
// 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')
|
2022-06-08 20:09:31 +00:00
|
|
|
expect(html).toContain('Composable | template: auto imported from ~/components/template.ts')
|
2022-03-22 18:12:54 +00:00
|
|
|
// should import components
|
|
|
|
expect(html).toContain('This is a custom component with a named export.')
|
2022-08-02 15:05:02 +00:00
|
|
|
// should apply attributes to client-only components
|
|
|
|
expect(html).toContain('<div style="color:red;" class="client-only"></div>')
|
|
|
|
// should register global components automatically
|
2022-07-27 13:05:34 +00:00
|
|
|
expect(html).toContain('global component registered automatically')
|
|
|
|
expect(html).toContain('global component via suffix')
|
2022-04-05 18:38:23 +00:00
|
|
|
|
2022-04-07 00:39:44 +00:00
|
|
|
await expectNoClientErrors('/')
|
2022-03-08 18:03:21 +00:00
|
|
|
})
|
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
it('render 404', async () => {
|
|
|
|
const html = await $fetch('/not-found')
|
2022-03-08 18:03:21 +00:00
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
// Snapshot
|
|
|
|
// expect(html).toMatchInlineSnapshot()
|
2022-03-08 18:03:21 +00:00
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
expect(html).toContain('[...slug].vue')
|
|
|
|
expect(html).toContain('404 at not-found')
|
2022-04-05 18:38:23 +00:00
|
|
|
|
2022-04-07 00:39:44 +00:00
|
|
|
await expectNoClientErrors('/not-found')
|
2022-03-22 18:12:54 +00:00
|
|
|
})
|
2022-03-08 18:03:21 +00:00
|
|
|
|
2022-05-03 09:31:58 +00:00
|
|
|
it('preserves query', async () => {
|
|
|
|
const html = await $fetch('/?test=true')
|
|
|
|
|
|
|
|
// Snapshot
|
|
|
|
// expect(html).toMatchInlineSnapshot()
|
|
|
|
|
|
|
|
// should render text
|
|
|
|
expect(html).toContain('Path: /?test=true')
|
|
|
|
|
|
|
|
await expectNoClientErrors('/?test=true')
|
|
|
|
})
|
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
it('/nested/[foo]/[bar].vue', async () => {
|
|
|
|
const html = await $fetch('/nested/one/two')
|
2022-03-08 18:03:21 +00:00
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
// Snapshot
|
|
|
|
// expect(html).toMatchInlineSnapshot()
|
2022-03-08 18:03:21 +00:00
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
expect(html).toContain('nested/[foo]/[bar].vue')
|
|
|
|
expect(html).toContain('foo: one')
|
|
|
|
expect(html).toContain('bar: two')
|
|
|
|
})
|
2022-03-08 18:03:21 +00:00
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
it('/nested/[foo]/index.vue', async () => {
|
|
|
|
const html = await $fetch('/nested/foobar')
|
2022-03-08 18:03:21 +00:00
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
// TODO: should resolved to same entry
|
|
|
|
// const html2 = await $fetch('/nested/foobar/index')
|
|
|
|
// expect(html).toEqual(html2)
|
2022-03-08 18:03:21 +00:00
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
// Snapshot
|
|
|
|
// expect(html).toMatchInlineSnapshot()
|
2022-03-08 18:03:21 +00:00
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
expect(html).toContain('nested/[foo]/index.vue')
|
|
|
|
expect(html).toContain('foo: foobar')
|
2022-04-05 18:38:23 +00:00
|
|
|
|
2022-04-07 00:39:44 +00:00
|
|
|
await expectNoClientErrors('/nested/foobar')
|
2022-03-22 18:12:54 +00:00
|
|
|
})
|
2022-03-08 18:03:21 +00:00
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
it('/nested/[foo]/user-[group].vue', async () => {
|
|
|
|
const html = await $fetch('/nested/foobar/user-admin')
|
2022-03-08 18:03:21 +00:00
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
// Snapshot
|
|
|
|
// expect(html).toMatchInlineSnapshot()
|
2022-03-08 18:03:21 +00:00
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
expect(html).toContain('nested/[foo]/user-[group].vue')
|
|
|
|
expect(html).toContain('foo: foobar')
|
|
|
|
expect(html).toContain('group: admin')
|
2022-04-05 18:38:23 +00:00
|
|
|
|
2022-04-07 00:39:44 +00:00
|
|
|
await expectNoClientErrors('/nested/foobar/user-admin')
|
2022-03-22 18:12:54 +00:00
|
|
|
})
|
2022-03-25 11:55:05 +00:00
|
|
|
|
|
|
|
it('/parent', async () => {
|
|
|
|
const html = await $fetch('/parent')
|
|
|
|
expect(html).toContain('parent/index')
|
2022-04-05 18:38:23 +00:00
|
|
|
|
2022-04-07 00:39:44 +00:00
|
|
|
await expectNoClientErrors('/parent')
|
2022-03-25 11:55:05 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('/another-parent', async () => {
|
|
|
|
const html = await $fetch('/another-parent')
|
|
|
|
expect(html).toContain('another-parent/index')
|
2022-04-05 18:38:23 +00:00
|
|
|
|
2022-04-07 00:39:44 +00:00
|
|
|
await expectNoClientErrors('/another-parent')
|
2022-03-25 11:55:05 +00:00
|
|
|
})
|
2022-03-22 18:12:54 +00:00
|
|
|
})
|
2022-03-08 18:03:21 +00:00
|
|
|
|
2022-04-05 14:02:29 +00:00
|
|
|
describe('head tags', () => {
|
|
|
|
it('should render tags', async () => {
|
2022-08-02 11:20:44 +00:00
|
|
|
const headHtml = await $fetch('/head')
|
|
|
|
expect(headHtml).toContain('<title>Using a dynamic component - Title Template Fn Change</title>')
|
|
|
|
expect(headHtml).not.toContain('<meta name="description" content="first">')
|
|
|
|
expect(headHtml).toContain('<meta charset="utf-16">')
|
|
|
|
expect(headHtml).not.toContain('<meta charset="utf-8">')
|
|
|
|
expect(headHtml).toContain('<meta name="description" content="overriding with an inline useHead call">')
|
|
|
|
expect(headHtml).toMatch(/<html[^>]*class="html-attrs-test"/)
|
|
|
|
expect(headHtml).toMatch(/<body[^>]*class="body-attrs-test"/)
|
|
|
|
expect(headHtml).toContain('script>console.log("works with useMeta too")</script>')
|
2022-08-02 11:43:25 +00:00
|
|
|
expect(headHtml).toContain('<script src="https://a-body-appended-script.com" data-meta-body="true"></script></body>')
|
2022-08-02 11:20:44 +00:00
|
|
|
|
|
|
|
const indexHtml = await $fetch('/')
|
2022-04-11 09:03:31 +00:00
|
|
|
// should render charset by default
|
2022-08-02 11:20:44 +00:00
|
|
|
expect(indexHtml).toContain('<meta charset="utf-8">')
|
2022-04-11 09:03:31 +00:00
|
|
|
// should render <Head> components
|
2022-08-02 11:20:44 +00:00
|
|
|
expect(indexHtml).toContain('<title>Basic fixture</title>')
|
2022-04-05 14:02:29 +00:00
|
|
|
})
|
2022-07-25 12:05:58 +00:00
|
|
|
|
|
|
|
// TODO: Doesn't adds header in test environment
|
|
|
|
// it.todo('should render stylesheet link tag (SPA mode)', async () => {
|
|
|
|
// const html = await $fetch('/head', { headers: { 'x-nuxt-no-ssr': '1' } })
|
|
|
|
// expect(html).toMatch(/<link rel="stylesheet" href="\/_nuxt\/[^>]*.css"/)
|
|
|
|
// })
|
2022-04-05 14:02:29 +00:00
|
|
|
})
|
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
describe('navigate', () => {
|
|
|
|
it('should redirect to index with navigateTo', async () => {
|
2022-05-11 17:33:29 +00:00
|
|
|
const { headers } = await fetch('/navigate-to/', { redirect: 'manual' })
|
2022-03-22 18:12:54 +00:00
|
|
|
|
2022-05-11 17:33:29 +00:00
|
|
|
expect(headers.get('location')).toEqual('/')
|
2022-03-08 18:03:21 +00:00
|
|
|
})
|
2022-03-22 18:12:54 +00:00
|
|
|
})
|
2022-03-08 18:03:21 +00:00
|
|
|
|
2022-04-07 11:28:04 +00:00
|
|
|
describe('errors', () => {
|
|
|
|
it('should render a JSON error page', async () => {
|
|
|
|
const res = await fetch('/error', {
|
|
|
|
headers: {
|
|
|
|
accept: 'application/json'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
expect(res.status).toBe(500)
|
2022-04-07 19:15:30 +00:00
|
|
|
const error = await res.json()
|
|
|
|
delete error.stack
|
2022-04-12 20:37:32 +00:00
|
|
|
expect(error).toMatchObject({
|
|
|
|
description: process.env.NUXT_TEST_DEV ? expect.stringContaining('<pre>') : '',
|
|
|
|
message: 'This is a custom error',
|
|
|
|
statusCode: 500,
|
|
|
|
statusMessage: 'Internal Server Error',
|
|
|
|
url: '/error'
|
|
|
|
})
|
2022-04-07 11:28:04 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should render a HTML error page', async () => {
|
|
|
|
const res = await fetch('/error')
|
|
|
|
expect(await res.text()).toContain('This is a custom error')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
describe('middlewares', () => {
|
|
|
|
it('should redirect to index with global middleware', async () => {
|
|
|
|
const html = await $fetch('/redirect/')
|
2022-03-16 21:39:47 +00:00
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
// Snapshot
|
|
|
|
// expect(html).toMatchInlineSnapshot()
|
2022-03-16 21:39:47 +00:00
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
expect(html).toContain('Hello Nuxt 3!')
|
2022-03-16 21:39:47 +00:00
|
|
|
})
|
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
it('should inject auth', async () => {
|
|
|
|
const html = await $fetch('/auth')
|
2022-03-08 18:03:21 +00:00
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
// Snapshot
|
|
|
|
// expect(html).toMatchInlineSnapshot()
|
2022-03-08 18:03:21 +00:00
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
expect(html).toContain('auth.vue')
|
|
|
|
expect(html).toContain('auth: Injected by injectAuth middleware')
|
|
|
|
})
|
2022-03-08 18:03:21 +00:00
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
it('should not inject auth', async () => {
|
|
|
|
const html = await $fetch('/no-auth')
|
2022-03-08 18:03:21 +00:00
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
// Snapshot
|
|
|
|
// expect(html).toMatchInlineSnapshot()
|
2022-03-08 18:03:21 +00:00
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
expect(html).toContain('no-auth.vue')
|
|
|
|
expect(html).toContain('auth: ')
|
|
|
|
expect(html).not.toContain('Injected by injectAuth middleware')
|
|
|
|
})
|
|
|
|
})
|
2022-03-08 18:03:21 +00:00
|
|
|
|
2022-04-01 09:55:23 +00:00
|
|
|
describe('plugins', () => {
|
|
|
|
it('basic plugin', async () => {
|
|
|
|
const html = await $fetch('/plugins')
|
|
|
|
expect(html).toContain('myPlugin: Injected by my-plugin')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('async plugin', async () => {
|
|
|
|
const html = await $fetch('/plugins')
|
|
|
|
expect(html).toContain('asyncPlugin: Async plugin works! 123')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
describe('layouts', () => {
|
|
|
|
it('should apply custom layout', async () => {
|
|
|
|
const html = await $fetch('/with-layout')
|
2022-03-08 18:03:21 +00:00
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
// Snapshot
|
|
|
|
// expect(html).toMatchInlineSnapshot()
|
2022-03-08 18:03:21 +00:00
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
expect(html).toContain('with-layout.vue')
|
|
|
|
expect(html).toContain('Custom Layout:')
|
2022-02-25 20:14:53 +00:00
|
|
|
})
|
2022-03-22 18:12:54 +00:00
|
|
|
})
|
2022-02-25 20:14:53 +00:00
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
describe('reactivity transform', () => {
|
|
|
|
it('should works', async () => {
|
|
|
|
const html = await $fetch('/')
|
2022-03-08 18:03:21 +00:00
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
expect(html).toContain('Sugar Counter 12 x 2 = 24')
|
|
|
|
})
|
|
|
|
})
|
2022-03-08 18:03:21 +00:00
|
|
|
|
2022-07-07 16:04:38 +00:00
|
|
|
describe('server tree shaking', () => {
|
|
|
|
it('should work', async () => {
|
|
|
|
const html = await $fetch('/client')
|
|
|
|
|
|
|
|
expect(html).toContain('This page should not crash when rendered')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
describe('extends support', () => {
|
2022-03-24 12:33:42 +00:00
|
|
|
describe('layouts & pages', () => {
|
|
|
|
it('extends foo/layouts/default & foo/pages/index', async () => {
|
2022-03-22 18:12:54 +00:00
|
|
|
const html = await $fetch('/foo')
|
2022-03-24 12:33:42 +00:00
|
|
|
expect(html).toContain('Extended layout from foo')
|
|
|
|
expect(html).toContain('Extended page from foo')
|
2022-03-22 18:12:54 +00:00
|
|
|
})
|
|
|
|
|
2022-03-24 12:33:42 +00:00
|
|
|
it('extends [bar/layouts/override & bar/pages/override] over [foo/layouts/override & foo/pages/override]', async () => {
|
2022-03-22 18:12:54 +00:00
|
|
|
const html = await $fetch('/override')
|
2022-03-24 12:33:42 +00:00
|
|
|
expect(html).toContain('Extended layout from bar')
|
2022-03-22 18:12:54 +00:00
|
|
|
expect(html).toContain('Extended page from bar')
|
2022-03-08 18:03:21 +00:00
|
|
|
})
|
2022-02-18 18:14:57 +00:00
|
|
|
})
|
2022-03-17 22:17:59 +00:00
|
|
|
|
2022-03-24 12:33:42 +00:00
|
|
|
describe('components', () => {
|
|
|
|
it('extends foo/components/ExtendsFoo', async () => {
|
|
|
|
const html = await $fetch('/foo')
|
|
|
|
expect(html).toContain('Extended component from foo')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('extends bar/components/ExtendsOverride over foo/components/ExtendsOverride', async () => {
|
|
|
|
const html = await $fetch('/override')
|
|
|
|
expect(html).toContain('Extended component from bar')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-03-22 18:12:54 +00:00
|
|
|
describe('middlewares', () => {
|
|
|
|
it('extends foo/middleware/foo', async () => {
|
2022-03-24 12:33:42 +00:00
|
|
|
const html = await $fetch('/foo')
|
|
|
|
expect(html).toContain('Middleware | foo: Injected by extended middleware from foo')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('extends bar/middleware/override over foo/middleware/override', async () => {
|
|
|
|
const html = await $fetch('/override')
|
|
|
|
expect(html).toContain('Middleware | override: Injected by extended middleware from bar')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('composables', () => {
|
|
|
|
it('extends foo/composables/foo', async () => {
|
|
|
|
const html = await $fetch('/foo')
|
|
|
|
expect(html).toContain('Composable | useExtendsFoo: foo')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('plugins', () => {
|
|
|
|
it('extends foo/plugins/foo', async () => {
|
|
|
|
const html = await $fetch('/foo')
|
|
|
|
expect(html).toContain('Plugin | foo: String generated from foo plugin!')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('server', () => {
|
|
|
|
it('extends foo/server/api/foo', async () => {
|
|
|
|
expect(await $fetch('/api/foo')).toBe('foo')
|
2022-03-22 18:12:54 +00:00
|
|
|
})
|
2022-03-17 22:17:59 +00:00
|
|
|
|
2022-03-24 12:33:42 +00:00
|
|
|
it('extends foo/server/middleware/foo', async () => {
|
|
|
|
const { headers } = await fetch('/')
|
|
|
|
expect(headers.get('injected-header')).toEqual('foo')
|
2022-03-17 22:17:59 +00:00
|
|
|
})
|
|
|
|
})
|
2022-04-04 08:23:11 +00:00
|
|
|
|
|
|
|
describe('app', () => {
|
|
|
|
it('extends foo/app/router.options & bar/app/router.options', async () => {
|
|
|
|
const html: string = await $fetch('/')
|
|
|
|
const routerLinkClasses = html.match(/href="\/" class="([^"]*)"/)[1].split(' ')
|
|
|
|
expect(routerLinkClasses).toContain('foo-active-class')
|
|
|
|
expect(routerLinkClasses).toContain('bar-exact-active-class')
|
|
|
|
})
|
|
|
|
})
|
2022-03-23 14:57:35 +00:00
|
|
|
})
|
2022-03-22 15:51:26 +00:00
|
|
|
|
2022-07-07 16:26:04 +00:00
|
|
|
describe('automatically keyed composables', () => {
|
|
|
|
it('should automatically generate keys', async () => {
|
|
|
|
const html = await $fetch('/keyed-composables')
|
|
|
|
expect(html).toContain('true')
|
|
|
|
expect(html).not.toContain('false')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-03-23 14:57:35 +00:00
|
|
|
describe('dynamic paths', () => {
|
2022-04-07 19:15:30 +00:00
|
|
|
if (process.env.NUXT_TEST_DEV) {
|
|
|
|
// TODO:
|
|
|
|
it.todo('dynamic paths in dev')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-03-23 14:57:35 +00:00
|
|
|
it('should work with no overrides', async () => {
|
|
|
|
const html = await $fetch('/assets')
|
|
|
|
for (const match of html.matchAll(/(href|src)="(.*?)"/g)) {
|
|
|
|
const url = match[2]
|
|
|
|
expect(url.startsWith('/_nuxt/') || url === '/public.svg').toBeTruthy()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('adds relative paths to CSS', async () => {
|
|
|
|
if (process.env.TEST_WITH_WEBPACK) {
|
|
|
|
// Webpack injects CSS differently
|
|
|
|
return
|
|
|
|
}
|
2022-04-07 19:15:30 +00:00
|
|
|
|
|
|
|
const html = await $fetch('/assets')
|
|
|
|
const urls = Array.from(html.matchAll(/(href|src)="(.*?)"/g)).map(m => m[2])
|
|
|
|
const cssURL = urls.find(u => /_nuxt\/entry.*\.css$/.test(u))
|
|
|
|
expect(cssURL).toBeDefined()
|
2022-03-23 14:57:35 +00:00
|
|
|
const css = await $fetch(cssURL)
|
|
|
|
const imageUrls = Array.from(css.matchAll(/url\(([^)]*)\)/g)).map(m => m[1].replace(/[-.][\w]{8}\./g, '.'))
|
|
|
|
expect(imageUrls).toMatchInlineSnapshot(`
|
2022-03-22 15:51:26 +00:00
|
|
|
[
|
|
|
|
"./logo.svg",
|
|
|
|
"../public.svg",
|
2022-06-10 15:17:11 +00:00
|
|
|
"../public.svg",
|
|
|
|
"../public.svg",
|
2022-03-22 15:51:26 +00:00
|
|
|
]
|
|
|
|
`)
|
2022-03-23 14:57:35 +00:00
|
|
|
})
|
2022-03-22 15:51:26 +00:00
|
|
|
|
2022-03-23 14:57:35 +00:00
|
|
|
it('should allow setting base URL and build assets directory', async () => {
|
|
|
|
process.env.NUXT_APP_BUILD_ASSETS_DIR = '/_other/'
|
|
|
|
process.env.NUXT_APP_BASE_URL = '/foo/'
|
|
|
|
await startServer()
|
2022-03-22 15:51:26 +00:00
|
|
|
|
2022-04-07 11:28:04 +00:00
|
|
|
const html = await $fetch('/foo/assets')
|
2022-07-25 09:52:21 +00:00
|
|
|
for (const match of html.matchAll(/(href|src)="(.`*?)"/g)) {
|
|
|
|
const url = match[2]
|
|
|
|
expect(
|
|
|
|
url.startsWith('/foo/_other/') ||
|
|
|
|
url === '/foo/public.svg' ||
|
|
|
|
// TODO: webpack does not yet support dynamic static paths
|
|
|
|
(process.env.TEST_WITH_WEBPACK && url === '/public.svg')
|
|
|
|
).toBeTruthy()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should allow setting relative baseURL', async () => {
|
|
|
|
delete process.env.NUXT_APP_BUILD_ASSETS_DIR
|
|
|
|
process.env.NUXT_APP_BASE_URL = './'
|
|
|
|
await startServer()
|
|
|
|
|
|
|
|
const html = await $fetch('/assets')
|
2022-03-23 14:57:35 +00:00
|
|
|
for (const match of html.matchAll(/(href|src)="(.*?)"/g)) {
|
|
|
|
const url = match[2]
|
2022-07-25 09:52:21 +00:00
|
|
|
expect(
|
|
|
|
url.startsWith('./_nuxt/') ||
|
|
|
|
url === './public.svg' ||
|
|
|
|
// TODO: webpack does not yet support dynamic static paths
|
|
|
|
(process.env.TEST_WITH_WEBPACK && url === '/public.svg')
|
|
|
|
).toBeTruthy()
|
|
|
|
expect(url.startsWith('./_nuxt/_nuxt')).toBeFalsy()
|
2022-03-23 14:57:35 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-05-11 17:33:29 +00:00
|
|
|
it('should use baseURL when redirecting', async () => {
|
|
|
|
process.env.NUXT_APP_BUILD_ASSETS_DIR = '/_other/'
|
|
|
|
process.env.NUXT_APP_BASE_URL = '/foo/'
|
|
|
|
await startServer()
|
|
|
|
const { headers } = await fetch('/foo/navigate-to/', { redirect: 'manual' })
|
|
|
|
|
|
|
|
expect(headers.get('location')).toEqual('/foo/')
|
|
|
|
})
|
|
|
|
|
2022-03-23 14:57:35 +00:00
|
|
|
it('should allow setting CDN URL', async () => {
|
|
|
|
process.env.NUXT_APP_BASE_URL = '/foo/'
|
|
|
|
process.env.NUXT_APP_CDN_URL = 'https://example.com/'
|
|
|
|
process.env.NUXT_APP_BUILD_ASSETS_DIR = '/_cdn/'
|
|
|
|
await startServer()
|
|
|
|
|
2022-04-07 11:28:04 +00:00
|
|
|
const html = await $fetch('/foo/assets')
|
2022-03-23 14:57:35 +00:00
|
|
|
for (const match of html.matchAll(/(href|src)="(.*?)"/g)) {
|
|
|
|
const url = match[2]
|
2022-07-25 09:52:21 +00:00
|
|
|
expect(
|
|
|
|
url.startsWith('https://example.com/_cdn/') ||
|
|
|
|
url === 'https://example.com/public.svg' ||
|
|
|
|
// TODO: webpack does not yet support dynamic static paths
|
|
|
|
(process.env.TEST_WITH_WEBPACK && url === '/public.svg')
|
|
|
|
).toBeTruthy()
|
2022-03-23 14:57:35 +00:00
|
|
|
}
|
2022-03-22 15:51:26 +00:00
|
|
|
})
|
2022-02-18 18:14:57 +00:00
|
|
|
})
|