-
Notifications
You must be signed in to change notification settings - Fork 96
/
browser-test-harness.js
74 lines (63 loc) · 1.83 KB
/
browser-test-harness.js
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
const childProcess = require('child_process');
const path = require('path');
const waitOn = require('wait-on');
const ports = require('./server-ports');
const storybook = childProcess.spawn(process.execPath, [
path.join('node_modules', 'cross-env', 'src', 'bin', 'cross-env-shell.js'),
'DISABLE_HMR=true',
'USE_PRODUCTION_BUILD=true',
path.join('node_modules', '.bin', 'start-storybook'),
'--ci',
'-p',
`${ports.storybook}`,
]);
const cspServer = childProcess.spawn(process.execPath, [
path.join('node_modules', 'cross-env', 'src', 'bin', 'cross-env-shell.js'),
'USE_PRODUCTION_BUILD=true',
path.join('csp-server', 'start.sh'),
`${ports.cspServer}`,
]);
process.on('exit', () => {
storybook.kill();
cspServer.kill();
});
const cmdArgsMap = {
accessibility: ['test:accessibility'],
browser: ['test:browser:ci'],
};
waitOn({
resources: [
`http://localhost:${ports.storybook}`,
`http://localhost:${ports.cspServer}`,
],
timeout: 60000,
})
.then(() => {
if (!process.argv[2]) {
// eslint-disable-next-line no-restricted-syntax
throw new Error('Started servers but no command supplied to run after');
}
const args = cmdArgsMap[process.argv[2]];
if (!args) {
// eslint-disable-next-line no-restricted-syntax
throw new Error('Unknown argument provided');
}
const child = childProcess.spawn('pnpm', args, {
stdio: 'inherit',
});
process.on('exit', () => {
child.kill();
});
child.on('exit', (code) => {
// eslint-disable-next-line no-process-exit
process.exit(code);
});
})
.catch((error) => {
storybook.kill();
cspServer.kill();
// eslint-disable-next-line no-console
console.error(error);
// eslint-disable-next-line no-restricted-syntax
throw new Error('Unable to spin up standalone servers');
});