N
Nuxt5mo ago
Mike

Using multiple workers causes project to be repeatably built despite using `server:true`

I am using Playwright and nuxt test utils. My playwright config looks like this:
/** Taken (but modified) from https://github.com/nuxt/test-utils/blob/main/examples/app-playwright/playwright.config.ts */
import { fileURLToPath } from "node:url"
import { defineConfig, devices } from "@playwright/test"
import type { ConfigOptions } from "@nuxt/test-utils/playwright"

const devicesToTest = ["Desktop Chrome"] satisfies Array<
string | (typeof devices)[string]
>

/* See https://playwright.dev/docs/test-configuration. */
export default defineConfig<ConfigOptions>({
testDir: "./tests",
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
workers: 1,
retries: 0,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: "html",
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry",
/* Nuxt configuration options */
nuxt: {
rootDir: fileURLToPath(new URL(".", import.meta.url)),
server: true,
browser: true,
/* Don't conflict with dev server on 3001 */
port: 4001,
},
},
projects: devicesToTest.map((p) =>
typeof p === "string" ? { name: p, use: devices[p] } : p,
),
})
/** Taken (but modified) from https://github.com/nuxt/test-utils/blob/main/examples/app-playwright/playwright.config.ts */
import { fileURLToPath } from "node:url"
import { defineConfig, devices } from "@playwright/test"
import type { ConfigOptions } from "@nuxt/test-utils/playwright"

const devicesToTest = ["Desktop Chrome"] satisfies Array<
string | (typeof devices)[string]
>

/* See https://playwright.dev/docs/test-configuration. */
export default defineConfig<ConfigOptions>({
testDir: "./tests",
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
workers: 1,
retries: 0,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: "html",
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry",
/* Nuxt configuration options */
nuxt: {
rootDir: fileURLToPath(new URL(".", import.meta.url)),
server: true,
browser: true,
/* Don't conflict with dev server on 3001 */
port: 4001,
},
},
projects: devicesToTest.map((p) =>
typeof p === "string" ? { name: p, use: devices[p] } : p,
),
})
I've set server: true to reuse the same server. However if i set workers > 1, the project is rebuilt and a new dev server is started in each worker. This causes an issue, since port 4001 is already in use after the first worker has been started. Thus the tests fail when using multiple workers. Also it just seems wasteful to rebuild the whole project in each worker. Is this expected behaviour? If so is there a way i can reuse the build and dev server on all workers? If not, should I create an issue?
1 Reply
Mike
MikeOP5mo ago
Looks like there's a draft PR that'll do what I want: https://github.com/nuxt/test-utils/pull/881
GitHub
feat(playwright): reuse existing server by Barbapapazes · Pull Requ...
related to #803 Hello 👋, I was trying this module to write tests cause I really think tests are important. But, in development, this module, e2e with Playwright, is slow. So slow that it creates to...
Want results from more Discord servers?
Add your server