import { defineConfig, devices } from '@playwright/test'; import { fileURLToPath } from 'node:url'; import { dirname, resolve } from 'node:path'; /** * Written without `@nx/playwright`'s preset on purpose: Playwright loads this * file through Node's ESM loader, and pulling in `@nx/devkit` from there drags * Nx's native binding in under `runSync`, where it fails to initialise. Only * `testDir`, `outputDir` and the web server came from the preset anyway. */ const here = dirname(fileURLToPath(import.meta.url)); const workspaceRoot = resolve(here, '..'); const baseURL = process.env['BASE_URL'] || 'http://localhost:4200'; /** * The dev server is started on whatever port `BASE_URL` names, rather than * always 4200. * * `reuseExistingServer` means Playwright will happily adopt whatever is already * listening there — and if that is a different project's dev server, every test * fails with "element(s) not found" while the real cause is that the page under * test was never served. Set BASE_URL to move both halves at once: * * BASE_URL=http://localhost:4280 npx nx e2e landing-e2e */ const port = new URL(baseURL).port || '4200'; export default defineConfig({ testDir: './src', outputDir: resolve(workspaceRoot, 'dist/.playwright/landing-e2e/test-output'), timeout: 60_000, forbidOnly: !!process.env['CI'], retries: process.env['CI'] ? 2 : 0, workers: process.env['CI'] ? 1 : undefined, reporter: [['list']], use: { baseURL, trace: 'on-first-retry', }, webServer: { command: `npx nx run landing:serve --port=${port}`, url: baseURL, reuseExistingServer: true, timeout: 180_000, cwd: workspaceRoot, }, projects: [ { name: 'chromium', use: { ...devices['Desktop Chrome'] }, }, ], });