From 46e2900a26442e74dcf862420ed1bfa33efa853a Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Wed, 18 Dec 2024 12:09:12 +0000 Subject: [PATCH] test: ensure dev server is loaded before running tests --- test/hmr.test.ts | 4 ++++ test/spa-loader/spa-preloader-outside-disabled.test.ts | 6 +++++- test/spa-loader/spa-preloader-outside-enabled.test.ts | 9 +++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/test/hmr.test.ts b/test/hmr.test.ts index b3a1ae3c9a..7c6ea46705 100644 --- a/test/hmr.test.ts +++ b/test/hmr.test.ts @@ -29,6 +29,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('/').then(r => r.includes('Home page')).catch(() => null), true) + }) + it('should work', async () => { const { page, pageErrors, consoleLogs } = await renderPage('/') diff --git a/test/spa-loader/spa-preloader-outside-disabled.test.ts b/test/spa-loader/spa-preloader-outside-disabled.test.ts index 66c4e0f2ae..26101889c0 100644 --- a/test/spa-loader/spa-preloader-outside-disabled.test.ts +++ b/test/spa-loader/spa-preloader-outside-disabled.test.ts @@ -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('/spa') expect(html).toContain(`
loading...
`) diff --git a/test/spa-loader/spa-preloader-outside-enabled.test.ts b/test/spa-loader/spa-preloader-outside-enabled.test.ts index 3ef4537c06..1562f060a5 100644 --- a/test/spa-loader/spa-preloader-outside-enabled.test.ts +++ b/test/spa-loader/spa-preloader-outside-enabled.test.ts @@ -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' })