test: skip testing spa-preloader in dev

This commit is contained in:
Daniel Roe 2025-02-28 22:33:26 +00:00
parent 9a9fcdab5b
commit 6cf97bfe5f
No known key found for this signature in database
GPG Key ID: CBC814C393D93268
2 changed files with 41 additions and 52 deletions

View File

@ -1,8 +1,7 @@
import { fileURLToPath } from 'node:url' import { fileURLToPath } from 'node:url'
import { describe, expect, it } from 'vitest' import { describe, expect, it } from 'vitest'
import { isWindows } from 'std-env' import { isWindows } from 'std-env'
import { $fetch, createPage, fetch, setup, url } from '@nuxt/test-utils/e2e' import { $fetch, createPage, setup, url } from '@nuxt/test-utils/e2e'
import { expectWithPolling } from '../utils'
const isWebpack = const isWebpack =
process.env.TEST_BUILDER === 'webpack' || process.env.TEST_BUILDER === 'webpack' ||
@ -10,25 +9,24 @@ const isWebpack =
const isDev = process.env.TEST_ENV === 'dev' const isDev = process.env.TEST_ENV === 'dev'
await setup({ if (!isDev) {
rootDir: fileURLToPath(new URL('../fixtures/spa-loader', import.meta.url)), await setup({
dev: isDev, rootDir: fileURLToPath(new URL('../fixtures/spa-loader', import.meta.url)),
server: true, dev: isDev,
browser: true, server: true,
setupTimeout: (isWindows ? 360 : 120) * 1000, browser: true,
nuxtConfig: { setupTimeout: (isWindows ? 360 : 120) * 1000,
builder: isWebpack ? 'webpack' : 'vite', nuxtConfig: {
spaLoadingTemplate: true, builder: isWebpack ? 'webpack' : 'vite',
experimental: { spaLoadingTemplate: true,
spaLoadingTemplateLocation: 'within', experimental: {
spaLoadingTemplateLocation: 'within',
},
}, },
},
})
describe('spaLoadingTemplateLocation flag is set to `within`', () => {
it.runIf(isDev)('should load dev server', async () => {
await expectWithPolling(() => fetch('/').then(r => r.status === 200).catch(() => null), true)
}) })
}
describe.skipIf(isDev)('spaLoadingTemplateLocation flag is set to `within`', () => {
it('should render loader inside appTag', async () => { it('should render loader inside appTag', async () => {
const html = await $fetch<string>('/spa') const html = await $fetch<string>('/spa')
expect(html).toContain(`<div id="__nuxt"><div data-testid="loader">loading...</div></div>`) expect(html).toContain(`<div id="__nuxt"><div data-testid="loader">loading...</div></div>`)
@ -38,17 +36,14 @@ describe('spaLoadingTemplateLocation flag is set to `within`', () => {
const page = await createPage() const page = await createPage()
await page.goto(url('/spa')) await page.goto(url('/spa'))
const loader = page.getByTestId('loader') await page.getByTestId('loader').waitFor({ state: 'visible' })
const content = page.getByTestId('content') expect(await page.getByTestId('content').isHidden()).toBeTruthy()
await loader.waitFor({ state: 'visible' })
expect(await content.isHidden()).toBeTruthy()
await page.waitForFunction(() => window.useNuxtApp?.() && window.useNuxtApp?.().isHydrating) await page.waitForFunction(() => window.useNuxtApp?.() && window.useNuxtApp?.().isHydrating)
expect(await content.isHidden()).toBeTruthy() expect(await page.getByTestId('content').isHidden()).toBeTruthy()
await content.waitFor({ state: 'visible' }) await page.getByTestId('content').waitFor({ state: 'visible' })
await page.close() await page.close()
}, 60_000) }, 60_000)

View File

@ -1,44 +1,38 @@
import { fileURLToPath } from 'node:url' import { fileURLToPath } from 'node:url'
import { describe, expect, it } from 'vitest' import { describe, expect, it } from 'vitest'
import { isWindows } from 'std-env' import { isWindows } from 'std-env'
import { createPage, fetch, setup, url } from '@nuxt/test-utils/e2e' import { createPage, setup, url } from '@nuxt/test-utils/e2e'
import type { Page } from 'playwright-core' import type { Page } from 'playwright-core'
import { expectWithPolling } from '../utils'
const isWebpack = process.env.TEST_BUILDER === 'webpack' || process.env.TEST_BUILDER === 'rspack' const isWebpack = process.env.TEST_BUILDER === 'webpack' || process.env.TEST_BUILDER === 'rspack'
const isDev = process.env.TEST_ENV === 'dev' const isDev = process.env.TEST_ENV === 'dev'
await setup({ if (!isDev) {
rootDir: fileURLToPath(new URL('../fixtures/spa-loader', import.meta.url)), await setup({
dev: isDev, rootDir: fileURLToPath(new URL('../fixtures/spa-loader', import.meta.url)),
server: true, server: true,
browser: true, browser: true,
setupTimeout: (isWindows ? 360 : 120) * 1000, setupTimeout: (isWindows ? 360 : 120) * 1000,
nuxtConfig: { nuxtConfig: {
builder: isWebpack ? 'webpack' : 'vite', builder: isWebpack ? 'webpack' : 'vite',
spaLoadingTemplate: true, spaLoadingTemplate: true,
experimental: { experimental: {
spaLoadingTemplateLocation: 'body', spaLoadingTemplateLocation: 'body',
},
}, },
},
})
describe('spaLoadingTemplateLocation flag is set to `body`', () => {
it.runIf(isDev)('should load dev server', async () => {
await expectWithPolling(() => fetch('/').then(r => r.status === 200).catch(() => null), true)
}) })
}
describe.skipIf(isDev)('spaLoadingTemplateLocation flag is set to `body`', () => {
it('should render spa-loader', async () => { it('should render spa-loader', async () => {
const page = await createPage() const page = await createPage()
await page.goto(url('/spa'), { waitUntil: 'domcontentloaded' }) await page.goto(url('/spa'), { waitUntil: 'domcontentloaded' })
const loader = page.getByTestId('loader') await page.getByTestId('loader').waitFor({ state: 'visible' })
const content = page.getByTestId('content') expect(await page.getByTestId('content').isHidden()).toBeTruthy()
await loader.waitFor({ state: 'visible' }) await page.getByTestId('content').waitFor({ state: 'visible' })
expect(await content.isHidden()).toBeTruthy() expect(await page.getByTestId('loader').isHidden()).toBeTruthy()
await content.waitFor({ state: 'visible' })
expect(await loader.isHidden()).toBeTruthy()
await page.close() await page.close()
}, 60_000) }, 60_000)