test: try to improve dev test stability (#31218)

Co-authored-by: Pooya Parsa <pooya@pi0.io>
This commit is contained in:
Daniel Roe 2025-03-06 11:36:28 +00:00 committed by GitHub
parent 854d3d066b
commit 85a2c3dc8b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 33 additions and 12 deletions

View File

@ -310,6 +310,7 @@ jobs:
TEST_CONTEXT: ${{ matrix.context }}
TEST_PAYLOAD: ${{ matrix.payload }}
SKIP_BUNDLE_SIZE: true
NITRO_NO_UNIX_SOCKET: ${{ matrix.env == 'dev' && '1' || '' }}
- uses: codecov/codecov-action@0565863a31f2c772f9f0395002a31e3f06189574 # v5.4.0
if: github.event_name != 'push' && matrix.env == 'built' && matrix.builder == 'vite' && matrix.context == 'default' && matrix.os == 'ubuntu-latest' && matrix.manifest == 'manifest-on'

View File

@ -553,6 +553,7 @@ export default defineResolvers({
'**/*.{spec,test}.{js,cts,mts,ts,jsx,tsx}', // ignore tests
'**/*.d.{cts,mts,ts}', // ignore type declarations
'**/.{pnpm-store,vercel,netlify,output,git,cache,data}',
'**/*.sock',
relative(rootDir, analyzeDir),
relative(rootDir, buildDir),
])

View File

@ -22,13 +22,14 @@ if (process.env.TEST_ENV !== 'built' && !isWindows) {
browser: true,
setupTimeout: (isWindows ? 360 : 120) * 1000,
nuxtConfig: {
buildDir: join(fixturePath, '.nuxt', 'test', Math.random().toString(36).slice(2, 8)),
builder: isWebpack ? 'webpack' : 'vite',
},
})
const indexVue = await fsp.readFile(join(fixturePath, 'pages/index.vue'), 'utf8')
describe('hmr', () => {
describe('hmr', { sequential: true }, () => {
beforeAll(async () => {
await expectWithPolling(() => $fetch<string>('/').then(r => r.includes('Home page')).catch(() => null), true)
})
@ -67,7 +68,7 @@ if (process.env.TEST_ENV !== 'built' && !isWindows) {
await page.close()
})
it('should detect new routes', async () => {
it('should detect new routes', { timeout: 60000 }, async () => {
const res = await fetch('/some-404')
expect(res.status).toBe(404)
@ -76,7 +77,7 @@ if (process.env.TEST_ENV !== 'built' && !isWindows) {
await expectWithPolling(() => $fetch<string>('/some-404').then(r => r.includes('Home page')).catch(() => null), true)
})
it('should hot reload route rules', async () => {
it('should hot reload route rules', { timeout: 60000 }, async () => {
await expectWithPolling(() => fetch('/route-rules').then(r => r.headers.get('x-extend')).catch(() => null), 'added in routeRules')
// write new page route
@ -147,7 +148,7 @@ if (process.env.TEST_ENV !== 'built' && !isWindows) {
})
it.skipIf(isWebpack)('should HMR routes', { timeout: 60_000 }, async () => {
const { page, pageErrors, consoleLogs } = await renderPage('/routes')
const { page, pageErrors, consoleLogs } = await renderPage('/routes', { retries: 5 })
await fsp.writeFile(join(fixturePath, 'pages/routes/non-existent.vue'), `<template><div data-testid="contents">A new route!</div></template>`)

View File

@ -2,18 +2,23 @@ import { fileURLToPath } from 'node:url'
import { describe, expect, it } from 'vitest'
import { $fetch, createPage, setup } from '@nuxt/test-utils/e2e'
import { isWindows } from 'std-env'
import { join } from 'pathe'
import { expectNoClientErrors } from './utils'
const isWebpack = process.env.TEST_BUILDER === 'webpack' || process.env.TEST_BUILDER === 'rspack'
const isDev = process.env.TEST_ENV === 'dev'
const fixtureDir = fileURLToPath(new URL('./fixtures/runtime-compiler', import.meta.url))
await setup({
rootDir: fileURLToPath(new URL('./fixtures/runtime-compiler', import.meta.url)),
dev: process.env.TEST_ENV === 'dev',
rootDir: fixtureDir,
dev: isDev,
server: true,
browser: true,
setupTimeout: (isWindows ? 360 : 120) * 1000,
nuxtConfig: {
builder: isWebpack ? 'webpack' : 'vite',
buildDir: isDev ? join(fixtureDir, '.nuxt', 'test', Math.random().toString(36).slice(2, 8)) : undefined,
},
})

View File

@ -2,18 +2,23 @@ import { fileURLToPath } from 'node:url'
import { describe, expect, it } from 'vitest'
import { isWindows } from 'std-env'
import { setup } from '@nuxt/test-utils/e2e'
import { join } from 'pathe'
import { renderPage } from './utils'
const isWebpack = process.env.TEST_BUILDER === 'webpack' || process.env.TEST_BUILDER === 'rspack'
const isDev = process.env.TEST_ENV === 'dev'
const fixtureDir = fileURLToPath(new URL('./fixtures/suspense', import.meta.url))
await setup({
rootDir: fileURLToPath(new URL('./fixtures/suspense', import.meta.url)),
dev: process.env.TEST_ENV === 'dev',
rootDir: fixtureDir,
dev: isDev,
server: true,
browser: true,
setupTimeout: (isWindows ? 360 : 120) * 1000,
nuxtConfig: {
builder: isWebpack ? 'webpack' : 'vite',
buildDir: isDev ? join(fixtureDir, '.nuxt', 'test', Math.random().toString(36).slice(2, 8)) : undefined,
},
})

View File

@ -8,7 +8,7 @@ import { getBrowser, url, useTestContext } from '@nuxt/test-utils/e2e'
export const isRenderingJson = process.env.TEST_PAYLOAD !== 'js'
export async function renderPage (path = '/') {
export async function renderPage (path = '/', opts?: { retries?: number }) {
const ctx = useTestContext()
if (!ctx.options.browser) {
throw new Error('`renderPage` require `options.browser` to be set')
@ -38,7 +38,7 @@ export async function renderPage (path = '/') {
})
if (path) {
await gotoPath(page, path)
await gotoPath(page, path, opts?.retries)
}
return {
@ -71,8 +71,16 @@ export function expectNoErrorsOrWarnings (consoleLogs: Array<{ type: string, tex
expect(consoleLogWarnings).toEqual([])
}
export async function gotoPath (page: Page, path: string) {
await page.goto(url(path))
export async function gotoPath (page: Page, path: string, retries = 0) {
for (let retry = 0; retry <= retries; retry++) {
try {
await page.goto(url(path), { timeout: 3000 })
} catch (error) {
if (retry === retries) {
throw error
}
}
}
await page.waitForFunction(path => window.useNuxtApp?.()._route.fullPath === path && !window.useNuxtApp?.().isHydrating, path)
}