-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathe2e-docker.js
More file actions
72 lines (63 loc) · 1.82 KB
/
Copy pathe2e-docker.js
File metadata and controls
72 lines (63 loc) · 1.82 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
#!/usr/bin/env node
import { execFileSync, spawnSync } from 'child_process';
import { createConnection } from 'net';
import { readFileSync } from 'fs';
const { devDependencies } = JSON.parse(readFileSync(new URL('../package.json', import.meta.url)));
const version = devDependencies['@playwright/test'].replace(/^[^0-9]*/, '');
const image = `mcr.microsoft.com/playwright:v${version}-noble`;
const name = 'sable-e2e-browser';
const port = 3000;
const waitForServer = () =>
new Promise((resolve, reject) => {
const deadline = Date.now() + 60_000;
const attempt = () => {
const socket = createConnection({ host: '127.0.0.1', port })
.on('connect', () => {
socket.end();
resolve();
})
.on('error', () => {
if (Date.now() > deadline) {
reject(new Error(`playwright server did not start on port ${port}`));
return;
}
setTimeout(attempt, 500);
});
};
attempt();
});
const stop = () => spawnSync('docker', ['rm', '-f', name], { stdio: 'ignore' });
stop();
execFileSync(
'docker',
[
'run',
'--rm',
'--detach',
'--init',
'--name',
name,
'--network',
'host',
'--workdir',
'/home/pwuser',
'--user',
'pwuser',
image,
'/bin/sh',
'-c',
`npx -y playwright@${version} run-server --port ${port} --host 0.0.0.0`,
],
{ stdio: 'inherit' }
);
process.on('exit', stop);
process.on('SIGINT', () => process.exit(130));
process.on('SIGTERM', () => process.exit(143));
await waitForServer();
const args = process.argv.slice(2);
if (args[0] === '--') args.shift();
const result = spawnSync('pnpm', ['exec', 'playwright', 'test', ...args], {
stdio: 'inherit',
env: { ...process.env, PW_TEST_CONNECT_WS_ENDPOINT: `ws://127.0.0.1:${port}/` },
});
process.exit(result.status ?? 1);