mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
test: extract dynamic paths test from within other test! (#3860)
This commit is contained in:
parent
a8317830a8
commit
a0c4d6e7e3
@ -180,59 +180,59 @@ describe('extends support', () => {
|
||||
expect(html).toContain('Injected by extended middleware from bar')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('dynamic paths', () => {
|
||||
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()
|
||||
}
|
||||
})
|
||||
describe('dynamic paths', () => {
|
||||
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 () => {
|
||||
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))
|
||||
if (process.env.TEST_WITH_WEBPACK) {
|
||||
// Webpack injects CSS differently
|
||||
return
|
||||
}
|
||||
const css = await $fetch(cssURL)
|
||||
const imageUrls = Array.from(css.matchAll(/url\(([^)]*)\)/g)).map(m => m[1].replace(/[-.][\w]{8}\./g, '.'))
|
||||
expect(imageUrls).toMatchInlineSnapshot(`
|
||||
it('adds relative paths to CSS', async () => {
|
||||
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))
|
||||
if (process.env.TEST_WITH_WEBPACK) {
|
||||
// Webpack injects CSS differently
|
||||
return
|
||||
}
|
||||
const css = await $fetch(cssURL)
|
||||
const imageUrls = Array.from(css.matchAll(/url\(([^)]*)\)/g)).map(m => m[1].replace(/[-.][\w]{8}\./g, '.'))
|
||||
expect(imageUrls).toMatchInlineSnapshot(`
|
||||
[
|
||||
"./logo.svg",
|
||||
"../public.svg",
|
||||
]
|
||||
`)
|
||||
})
|
||||
})
|
||||
|
||||
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()
|
||||
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()
|
||||
|
||||
const html = await $fetch('/assets')
|
||||
for (const match of html.matchAll(/(href|src)="(.*?)"/g)) {
|
||||
const url = match[2]
|
||||
// TODO: webpack does not yet support dynamic static paths
|
||||
expect(url.startsWith('/foo/_other/') || url === '/foo/public.svg' || (process.env.TEST_WITH_WEBPACK && url === '/public.svg')).toBeTruthy()
|
||||
}
|
||||
})
|
||||
const html = await $fetch('/assets')
|
||||
for (const match of html.matchAll(/(href|src)="(.*?)"/g)) {
|
||||
const url = match[2]
|
||||
// TODO: webpack does not yet support dynamic static paths
|
||||
expect(url.startsWith('/foo/_other/') || url === '/foo/public.svg' || (process.env.TEST_WITH_WEBPACK && url === '/public.svg')).toBeTruthy()
|
||||
}
|
||||
})
|
||||
|
||||
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()
|
||||
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()
|
||||
|
||||
const html = await $fetch('/assets')
|
||||
for (const match of html.matchAll(/(href|src)="(.*?)"/g)) {
|
||||
const url = match[2]
|
||||
// TODO: webpack does not yet support dynamic static paths
|
||||
expect(url.startsWith('https://example.com/_cdn/') || url === 'https://example.com/public.svg' || (process.env.TEST_WITH_WEBPACK && url === '/public.svg')).toBeTruthy()
|
||||
}
|
||||
})
|
||||
const html = await $fetch('/assets')
|
||||
for (const match of html.matchAll(/(href|src)="(.*?)"/g)) {
|
||||
const url = match[2]
|
||||
// TODO: webpack does not yet support dynamic static paths
|
||||
expect(url.startsWith('https://example.com/_cdn/') || url === 'https://example.com/public.svg' || (process.env.TEST_WITH_WEBPACK && url === '/public.svg')).toBeTruthy()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user