Skip to content

Commit 7055449

Browse files
committed
test: sample docker config
1 parent a4bf5b0 commit 7055449

1 file changed

Lines changed: 91 additions & 0 deletions

File tree

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import * as crypto from 'node:crypto';
2+
import * as path from 'node:path';
3+
4+
import { parseNumber, range, unwrap } from '@douglasneuroinformatics/libjs';
5+
import { defineConfig, devices } from '@playwright/test';
6+
import type { Project } from '@playwright/test';
7+
8+
import { AUTH_STORAGE_DIR } from './src/helpers/constants';
9+
10+
import type { BrowserTarget, ProjectMetadata } from './src/helpers/types';
11+
12+
console.log(process.env.APP_PORT);
13+
14+
const appPort = parseNumber(process.env.APP_PORT);
15+
const gatewayPort = parseNumber(process.env.GATEWAY_PORT);
16+
17+
if (Number.isNaN(appPort)) {
18+
throw new Error(`Expected APP_PORT to be number, got ${process.env.APP_PORT}`);
19+
} else if (Number.isNaN(gatewayPort)) {
20+
throw new Error(`Expected GATEWAY_PORT to be number, got ${process.env.GATEWAY_PORT}`);
21+
}
22+
23+
const baseURL = `http://localhost:${appPort}`;
24+
25+
const browsers: { target: BrowserTarget; use: Project['use'] }[] = [
26+
{ target: 'Desktop Chrome', use: { ...devices['Desktop Chrome'], channel: 'chromium', headless: true } },
27+
{ target: 'Desktop Firefox', use: { ...devices['Desktop Firefox'], headless: true } }
28+
] as const;
29+
30+
export default defineConfig({
31+
globalSetup: path.resolve(import.meta.dirname, 'src/global/global.setup.ts'),
32+
globalTeardown: path.resolve(import.meta.dirname, 'src/global/global.teardown.ts'),
33+
maxFailures: 1,
34+
outputDir: path.resolve(import.meta.dirname, '.playwright/output'),
35+
projects: [
36+
{
37+
name: 'Global Setup',
38+
teardown: 'Global Teardown',
39+
testMatch: '**/global/global.setup.spec.ts',
40+
use: {
41+
baseURL
42+
}
43+
},
44+
{
45+
name: 'Global Teardown',
46+
testMatch: '**/global/global.teardown.spec.ts',
47+
use: {
48+
baseURL
49+
}
50+
},
51+
...unwrap(range(1, 4)).flatMap((i) => {
52+
return browsers.map((browser) => {
53+
const browserId = crypto.createHash('sha256').update(browser.target).digest('hex');
54+
return {
55+
dependencies: i === 1 ? ['Global Setup'] : [`${i - 1}.x - ${browser.target}`],
56+
metadata: {
57+
authStorageFile: path.resolve(AUTH_STORAGE_DIR, `${browserId}.json`),
58+
browserId,
59+
browserTarget: browser.target
60+
} satisfies ProjectMetadata,
61+
name: `${i}.x - ${browser.target}`,
62+
testMatch: `**/${i}.*.spec.ts`,
63+
use: {
64+
...browser.use,
65+
baseURL
66+
}
67+
};
68+
});
69+
})
70+
],
71+
reporter: [['html', { open: 'never', outputFolder: path.resolve(import.meta.dirname, '.playwright/report') }]],
72+
testDir: path.resolve(import.meta.dirname, 'src'),
73+
webServer: [
74+
{
75+
command: 'true', // Dummy command since services are assumed running in Docker
76+
url: `http://localhost:${appPort}/api/v1/setup`,
77+
timeout: 10_000
78+
},
79+
{
80+
command: 'true', // Dummy command since services are assumed running in Docker
81+
url: `http://localhost:${gatewayPort}/api/healthcheck`,
82+
timeout: 10_000
83+
},
84+
{
85+
command: 'true', // Dummy command since services are assumed running in Docker
86+
url: `http://localhost:${appPort}`,
87+
timeout: 10_000
88+
}
89+
],
90+
workers: process.env.CI ? 1 : undefined
91+
});

0 commit comments

Comments
 (0)