Skip to content

Commit ddb3f5f

Browse files
committed
update playwright config
1 parent baa27d0 commit ddb3f5f

File tree

3 files changed

+60
-36
lines changed

3 files changed

+60
-36
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,4 @@ storybook-static
7474
.claude/settings.local.json
7575

7676
# playwright
77-
testing/e2e/.output/
78-
testing/e2e/playwright/.cache/
77+
test/.playwright

testing/e2e/playwright.config.ts

Lines changed: 54 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,69 @@
11
import * as path from 'node:path';
22

3-
import { parseNumber } from '@douglasneuroinformatics/libjs';
3+
import { parseNumber, range, unwrap } from '@douglasneuroinformatics/libjs';
44
import { defineConfig, devices } from '@playwright/test';
5+
import type { Project } from '@playwright/test';
56

6-
const API_PORT = parseNumber(process.env.API_DEV_SERVER_PORT);
7-
const GATEWAY_PORT = parseNumber(process.env.GATEWAY_DEV_SERVER_PORT);
8-
const WEB_PORT = parseNumber(process.env.WEB_DEV_SERVER_PORT);
7+
import type { BrowserTarget, ProjectMetadata } from './src/helpers/types';
8+
9+
const apiPort = parseNumber(process.env.API_DEV_SERVER_PORT);
10+
const gatewayPort = parseNumber(process.env.GATEWAY_DEV_SERVER_PORT);
11+
const webPort = parseNumber(process.env.WEB_DEV_SERVER_PORT);
12+
13+
if (Number.isNaN(apiPort)) {
14+
throw new Error(`Expected API_DEV_SERVER_PORT to be number, got ${process.env.API_DEV_SERVER_PORT}`);
15+
} else if (!gatewayPort) {
16+
throw new Error(`Expected GATEWAY_DEV_SERVER_PORT to be number, got ${process.env.GATEWAY_DEV_SERVER_PORT}`);
17+
} else if (Number.isNaN(webPort)) {
18+
throw new Error(`Expected WEB_DEV_SERVER_PORT to be number, got ${process.env.WEB_DEV_SERVER_PORT}`);
19+
}
20+
21+
const baseURL = `http://localhost:${webPort}`;
22+
23+
const browsers: { target: BrowserTarget; use: Project['use'] }[] = [
24+
{ target: 'Desktop Chrome', use: { ...devices['Desktop Chrome'], channel: 'chromium', headless: true } },
25+
{ target: 'Desktop Firefox', use: { ...devices['Desktop Firefox'], headless: true } },
26+
{ target: 'Desktop Safari', use: devices['Desktop Safari'] }
27+
] as const;
928

1029
export default defineConfig({
11-
fullyParallel: true,
12-
outputDir: path.resolve(import.meta.dirname, '.output/results'),
30+
maxFailures: 1,
31+
outputDir: path.resolve(import.meta.dirname, '.playwright/output'),
1332
projects: [
1433
{
1534
name: 'Global Setup',
1635
teardown: 'Global Teardown',
17-
testMatch: '**/global/global.setup.spec.ts'
36+
testMatch: '**/global/global.setup.spec.ts',
37+
use: {
38+
baseURL
39+
}
1840
},
1941
{
2042
name: 'Global Teardown',
21-
testMatch: '**/global/global.teardown.spec.ts'
22-
},
23-
{
24-
dependencies: ['Global Setup'],
25-
name: 'Desktop Chrome',
26-
testIgnore: '**/global/**',
27-
use: { ...devices['Desktop Chrome'] }
43+
testMatch: '**/global/global.teardown.spec.ts',
44+
use: {
45+
baseURL
46+
}
2847
},
29-
{
30-
dependencies: ['Global Setup'],
31-
name: 'Desktop Firefox',
32-
testIgnore: '**/global/**',
33-
use: { ...devices['Desktop Firefox'] }
34-
},
35-
{
36-
dependencies: ['Global Setup'],
37-
name: 'Desktop Safari',
38-
testIgnore: '**/global/**',
39-
use: { ...devices['Desktop Safari'] }
40-
}
48+
...unwrap(range(1, 4)).flatMap((i) => {
49+
return browsers.map((browser) => {
50+
return {
51+
dependencies: i === 1 ? ['Global Setup'] : [`${i - 1}.x - ${browser.target}`],
52+
metadata: {
53+
browserTarget: browser.target
54+
} satisfies ProjectMetadata,
55+
name: `${i}.x - ${browser.target}`,
56+
testMatch: `**/${i}.*.spec.ts`,
57+
use: {
58+
...browser.use,
59+
baseURL
60+
}
61+
};
62+
});
63+
})
4164
],
4265
reporter: [['html', { open: 'never', outputFolder: path.resolve(import.meta.dirname, '.output/report') }]],
4366
testDir: path.resolve(import.meta.dirname, 'src'),
44-
use: {
45-
baseURL: `http://localhost:${WEB_PORT}`,
46-
trace: 'on-first-retry'
47-
},
4867
webServer: [
4968
{
5069
command: 'pnpm dev:test',
@@ -54,7 +73,7 @@ export default defineConfig({
5473
timeout: 1000
5574
},
5675
timeout: 10_000,
57-
url: `http://localhost:${API_PORT}`
76+
url: `http://localhost:${apiPort}`
5877
},
5978
{
6079
command: 'pnpm dev:test',
@@ -64,7 +83,7 @@ export default defineConfig({
6483
timeout: 1000
6584
},
6685
timeout: 10_000,
67-
url: `http://localhost:${GATEWAY_PORT}/api/healthcheck`
86+
url: `http://localhost:${gatewayPort}/api/healthcheck`
6887
},
6988
{
7089
command: 'pnpm dev:test',
@@ -74,7 +93,8 @@ export default defineConfig({
7493
timeout: 1000
7594
},
7695
timeout: 10_000,
77-
url: `http://localhost:${WEB_PORT}`
96+
url: `http://localhost:${webPort}`
7897
}
79-
]
98+
],
99+
workers: process.env.CI ? 1 : undefined
80100
});

testing/e2e/src/helpers/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export type BrowserTarget = 'Desktop Chrome' | 'Desktop Firefox' | 'Desktop Safari';
2+
3+
export type ProjectMetadata = {
4+
browserTarget: BrowserTarget;
5+
};

0 commit comments

Comments
 (0)