-
Notifications
You must be signed in to change notification settings - Fork 2
/
e2e.js
57 lines (44 loc) · 1.34 KB
/
e2e.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
const getPort = require('get-port');
const {spawn} = require('child_process');
const service = spawn('npm', ['start']);
const net = require('net');
const kill = require('tree-kill');
function startTest(serverPid, env) {
const test = spawn('npx', ['react-scripts', 'test', '--env=jsdom'], {env: env});
test.stdout.on('data', (data) => {
console.log(`stdoutTest: ${data}`);
});
test.stderr.on('data', (data) => {
console.log(`stderrTest: ${data}`);
});
test.on('exit', (code) => {
console.log('exit', code);
kill(serverPid);
process.exit(code);
});
test.on('close', (code) => {
console.log('close', code);
kill(serverPid);
process.exit(code);
});
}
function start() {
getPort().then(port => {
const env = Object.create(process.env);
env.PORT = port;
env.REACT_APP_IS_E2E_TEST=true;
env.CI = true;
const onServerStdout = (data) => {
console.log(`stdout: ${data}`);
// there gotta be a way to check for react app to be compiled and served
setTimeout(() => startTest(server.pid, env), 10000)
};
const onServerStderr = (data) => {
console.log(`stderr: ${data}`);
};
const server = spawn('npx', ['react-scripts', 'start'], { env: env });
server.stdout.on('data', onServerStdout);
server.stderr.on('data', onServerStderr);
});
}
start();