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,6 +9,7 @@ const isWebpack =
const isDev = process.env.TEST_ENV === 'dev' const isDev = process.env.TEST_ENV === 'dev'
if (!isDev) {
await setup({ await setup({
rootDir: fileURLToPath(new URL('../fixtures/spa-loader', import.meta.url)), rootDir: fileURLToPath(new URL('../fixtures/spa-loader', import.meta.url)),
dev: isDev, dev: isDev,
@ -24,11 +24,9 @@ await setup({
}, },
}, },
}) })
}
describe('spaLoadingTemplateLocation flag is set to `within`', () => { describe.skipIf(isDev)('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)
})
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,16 +1,15 @@
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'
if (!isDev) {
await setup({ await setup({
rootDir: fileURLToPath(new URL('../fixtures/spa-loader', import.meta.url)), rootDir: fileURLToPath(new URL('../fixtures/spa-loader', import.meta.url)),
dev: isDev,
server: true, server: true,
browser: true, browser: true,
setupTimeout: (isWindows ? 360 : 120) * 1000, setupTimeout: (isWindows ? 360 : 120) * 1000,
@ -22,23 +21,18 @@ await setup({
}, },
}, },
}) })
}
describe('spaLoadingTemplateLocation flag is set to `body`', () => { describe.skipIf(isDev)('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)
})
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)