From a0c4d6e7e32f490d6f375340bffdc1d3b68a42eb Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Wed, 23 Mar 2022 14:57:35 +0000 Subject: [PATCH] test: extract dynamic paths test from within other test! (#3860) --- test/basic.test.ts | 86 +++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/test/basic.test.ts b/test/basic.test.ts index 62ac6814ec..11c57935ce 100644 --- a/test/basic.test.ts +++ b/test/basic.test.ts @@ -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() + } }) })