test: ensure dev server is loaded before running tests

This commit is contained in:
Daniel Roe 2024-12-18 12:09:12 +00:00
parent aa79b3a120
commit f66cf928e2
No known key found for this signature in database
GPG Key ID: 3714AB03996F442B
3 changed files with 16 additions and 3 deletions

View File

@ -28,6 +28,10 @@ if (process.env.TEST_ENV !== 'built' && !isWindows) {
const indexVue = await fsp.readFile(join(fixturePath, 'pages/index.vue'), 'utf8')
describe('hmr', () => {
it('should load dev server', async () => {
await expectWithPolling(() => $fetch<string>('/').then(r => r.includes('Home page')).catch(() => null), true)
})
it('should work', async () => {
const { page, pageErrors, consoleLogs } = await renderPage('/')

View File

@ -1,7 +1,8 @@
import { fileURLToPath } from 'node:url'
import { describe, expect, it } from 'vitest'
import { isWindows } from 'std-env'
import { $fetch, createPage, setup, url } from '@nuxt/test-utils/e2e'
import { $fetch, createPage, fetch, setup, url } from '@nuxt/test-utils/e2e'
import { expectWithPolling } from '../utils'
const isWebpack =
process.env.TEST_BUILDER === 'webpack' ||
@ -25,6 +26,9 @@ await setup({
})
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)
})
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>`)

View File

@ -1,14 +1,16 @@
import { fileURLToPath } from 'node:url'
import { describe, expect, it } from 'vitest'
import { isWindows } from 'std-env'
import { createPage, setup, url } from '@nuxt/test-utils/e2e'
import { createPage, fetch, 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: process.env.TEST_ENV === 'dev',
dev: isDev,
server: true,
browser: true,
setupTimeout: (isWindows ? 360 : 120) * 1000,
@ -22,6 +24,9 @@ await setup({
})
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)
})
it('should render spa-loader', async () => {
const page = await createPage()
await page.goto(url('/spa'), { waitUntil: 'domcontentloaded' })