-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplaywright.config.base.ts
More file actions
58 lines (52 loc) · 2.12 KB
/
Copy pathplaywright.config.base.ts
File metadata and controls
58 lines (52 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { defineConfig, devices } from '@playwright/test';
const DEFAULT_PORT = '3222';
// Exported so tests/e2e/app/helpers.ts can point browser-context cookies at
// the same origin the webServer answers on.
export const E2E_BASE_URL = `http://localhost:${DEFAULT_PORT}`;
export interface E2eBackendOptions {
serverEnv: Record<string, string>;
// Runs before `next start`: resets the backend's data files and does any
// further setup it needs (e.g. sqlite applying migrations).
beforeStart: string;
}
// Shared e2e config. Everything backend-specific arrives via `options`, so each
// target is a thin config file calling this — no .env files involved.
export function defineE2eConfig(options: E2eBackendOptions) {
const { serverEnv, beforeStart } = options;
const baseURL = E2E_BASE_URL;
// tests/e2e/app/helpers.ts builds its own DI container in this process
// (calling BFF use-cases directly instead of going over HTTP), so it needs
// the same backend selection as the `next start` server spawned below.
Object.assign(process.env, serverEnv);
return defineConfig({
testDir: './tests/e2e',
// One server is shared across specs; keep the run serial.
fullyParallel: false,
workers: 1,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 1 : 0,
timeout: 30_000,
reporter: 'list',
use: { baseURL, trace: 'on-first-retry' },
webServer: {
// Run the backend's beforeStart (data reset + any setup), then serve the
// built artifact. `env` is what selects the backend.
command: `${beforeStart} && node_modules/.bin/next start -p ${DEFAULT_PORT}`,
url: `${baseURL}/sign-in`,
env: serverEnv,
reuseExistingServer: !process.env.CI,
timeout: 120_000,
},
projects: [
// Tests are grouped by folder: API tests drive the route handlers
// directly and need no browser; app tests drive the pages in Chromium
// (`npx playwright install chromium`).
{ name: 'api', testDir: './tests/e2e/api' },
{
name: 'app',
testDir: './tests/e2e/app',
use: { ...devices['Desktop Chrome'] },
},
],
});
}