import {defineConfig, devices} from '@playwright/test' const resultsDir = process.env.TEST_RESULT_OUTPUT_DIR // browser/harness/vite.config.mjs reads the same variable; they must agree. // ?? would accept an empty string here, which resolves to port 0. const harnessPort = process.env.RCE_HARNESS_PORT?.trim() || '4455' const harnessUrl = `http://localhost:${harnessPort}` // Validate here rather than leaving it to playwright: Number('x') is NaN, and // NaN < 1 is false, so its own `< 1` guard passes NaN straight through and the // run allocates zero workers and never finishes. const rawWorkers = process.env.PLAYWRIGHT_WORKERS?.trim() const workers = rawWorkers ? Number(rawWorkers) : undefined if (workers !== undefined && (!Number.isInteger(workers) || workers < 1)) { throw new Error(`PLAYWRIGHT_WORKERS must be a positive integer, got "${rawWorkers}"`) } export default defineConfig({ testDir: './tests', timeout: 90_000, fullyParallel: true, forbidOnly: !!process.env.CI, retries: process.env.CI ? 2 : 0, workers, reporter: resultsDir ? [ ['list'], [ 'junit', // Records the failed attempts of a test that later passed, as // children. Note the entry still carries no , // so surfacing it needs Jenkins' Flaky Test Handler plugin; without // that the retry data is in the artifact but not in the UI. {outputFile: `${resultsDir}/canvas-rce-browser.xml`, includeRetries: true}, ], ] : [ ['html', {outputFolder: 'playwright-report'}], ['junit', {outputFile: 'playwright-junit.xml'}], ], use: { baseURL: harnessUrl, trace: 'on-first-retry', }, projects: [ { name: 'chromium', use: {...devices['Desktop Chrome']}, }, ], webServer: { // Not harness:dev -- the dev server died partway through a full sharded run. // build:browser-harness produces the build this serves. command: 'pnpm run harness:preview', // webServer defaults cwd to this config's directory; the script is a level up. cwd: '..', url: harnessUrl, reuseExistingServer: !process.env.CI, timeout: 120_000, }, })