-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathplaywright.config.ts
More file actions
80 lines (74 loc) · 2.04 KB
/
playwright.config.ts
File metadata and controls
80 lines (74 loc) · 2.04 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { existsSync } from 'node:fs';
import { basename, dirname, join } from 'node:path';
import { defineConfig, devices } from '@playwright/test';
import fg from 'fast-glob';
const BASE_PORT = 9400;
const WP_VERSION = process.env.WP_VERSION || 'latest';
const RUN_PROJECT = process.env.RUN_PROJECT;
// Find the closest blueprint.json by walking up from the spec's directory
function findBlueprint(dir: string): string | null {
let current = dir;
while (current !== '.' && current !== '/') {
const bp = join(current, 'blueprint.json');
if (existsSync(bp)) return bp;
current = dirname(current);
}
return null;
}
// Discover spec files that have a blueprint.json in their directory or any ancestor
const specs = fg
.sync('**/*.spec.ts', { ignore: ['node_modules/**'] })
.map((spec) => {
const dir = dirname(spec);
const blueprint = findBlueprint(dir);
if (!blueprint) return null;
return {
name: basename(spec, '.spec.ts'),
dir,
spec: basename(spec),
blueprint,
};
})
.filter(
(
s,
): s is {
name: string;
dir: string;
spec: string;
blueprint: string;
} => s !== null,
);
const active = RUN_PROJECT
? specs.filter((p) => p.name === RUN_PROJECT)
: specs;
// Dedupe blueprints and assign ports
const blueprints = [...new Set(active.map((s) => s.blueprint))];
const portMap = Object.fromEntries(
blueprints.map((bp, i) => [bp, BASE_PORT + i]),
);
export default defineConfig({
forbidOnly: !!process.env.CI,
retries: 0,
workers: 1,
reporter: 'html',
use: {
trace: 'retain-on-failure',
video: 'retain-on-failure',
screenshot: 'only-on-failure',
},
webServer: blueprints.map((bp) => ({
command: `wp-playground-cli server --auto-mount --blueprint=${bp} --wp=${WP_VERSION} --port=${portMap[bp]} --internal-cookie-store=true --login=false`,
url: `http://127.0.0.1:${portMap[bp]}`,
reuseExistingServer: false,
})),
projects: active.map((p) => ({
name: p.name,
testDir: p.dir,
testMatch: p.spec,
use: {
...devices['Desktop Chrome'],
baseURL: `http://127.0.0.1:${portMap[p.blueprint]}`,
},
})),
});