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 { describe, expect, it } from 'vitest'
import { isWindows } from 'std-env'
import { $fetch, createPage, fetch, setup, url } from '@nuxt/test-utils/e2e'
import { expectWithPolling } from '../utils'
import { $fetch, createPage, setup, url } from '@nuxt/test-utils/e2e'
const isWebpack =
process.env.TEST_BUILDER === 'webpack' ||
@ -10,25 +9,24 @@ const isWebpack =
const isDev = process.env.TEST_ENV === 'dev'
await setup({
rootDir: fileURLToPath(new URL('../fixtures/spa-loader', import.meta.url)),
dev: isDev,
server: true,
browser: true,
setupTimeout: (isWindows ? 360 : 120) * 1000,
nuxtConfig: {
builder: isWebpack ? 'webpack' : 'vite',
spaLoadingTemplate: true,
experimental: {
spaLoadingTemplateLocation: 'within',
if (!isDev) {
await setup({
rootDir: fileURLToPath(new URL('../fixtures/spa-loader', import.meta.url)),
dev: isDev,
server: true,
browser: true,
setupTimeout: (isWindows ? 360 : 120) * 1000,
nuxtConfig: {
builder: isWebpack ? 'webpack' : 'vite',
spaLoadingTemplate: true,
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 () => {
const html = await $fetch<string>('/spa')
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()
await page.goto(url('/spa'))
const loader = page.getByTestId('loader')
const content = page.getByTestId('content')
await loader.waitFor({ state: 'visible' })
expect(await content.isHidden()).toBeTruthy()
await page.getByTestId('loader').waitFor({ state: 'visible' })
expect(await page.getByTestId('content').isHidden()).toBeTruthy()
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()
}, 60_000)

View File

@ -1,44 +1,38 @@
import { fileURLToPath } from 'node:url'
import { describe, expect, it } from 'vitest'
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 { expectWithPolling } from '../utils'
const isWebpack = process.env.TEST_BUILDER === 'webpack' || process.env.TEST_BUILDER === 'rspack'
const isDev = process.env.TEST_ENV === 'dev'
await setup({
rootDir: fileURLToPath(new URL('../fixtures/spa-loader', import.meta.url)),
dev: isDev,
server: true,
browser: true,
setupTimeout: (isWindows ? 360 : 120) * 1000,
nuxtConfig: {
builder: isWebpack ? 'webpack' : 'vite',
spaLoadingTemplate: true,
experimental: {
spaLoadingTemplateLocation: 'body',
if (!isDev) {
await setup({
rootDir: fileURLToPath(new URL('../fixtures/spa-loader', import.meta.url)),
server: true,
browser: true,
setupTimeout: (isWindows ? 360 : 120) * 1000,
nuxtConfig: {
builder: isWebpack ? 'webpack' : 'vite',
spaLoadingTemplate: true,
experimental: {
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 () => {
const page = await createPage()
await page.goto(url('/spa'), { waitUntil: 'domcontentloaded' })
const loader = page.getByTestId('loader')
const content = page.getByTestId('content')
await page.getByTestId('loader').waitFor({ state: 'visible' })
expect(await page.getByTestId('content').isHidden()).toBeTruthy()
await loader.waitFor({ state: 'visible' })
expect(await content.isHidden()).toBeTruthy()
await content.waitFor({ state: 'visible' })
expect(await loader.isHidden()).toBeTruthy()
await page.getByTestId('content').waitFor({ state: 'visible' })
expect(await page.getByTestId('loader').isHidden()).toBeTruthy()
await page.close()
}, 60_000)