-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (38 loc) · 1.08 KB
/
index.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
const path = require('path');
const { spawn } = require('child_process');
const hs = require('hs-test-web');
async function startServerAndTest(host, port, stage, test) {
const src = stage.substring(process.cwd().length + 1) + '/src/';
const server = spawn(process.argv[0], [
__dirname + '/start.js',
'host:' + host,
'port:' + port,
'src:' + src
]);
let out = '';
let err = '';
server.stdout.on('data', (data) => {
console.log(data.toString());
out += data;
});
server.stderr.on('data', (data) => {
console.error(data.toString());
err += data;
});
const sleep = (ms) => new Promise(res => setTimeout(res, ms));
try {
while (true) {
await sleep(10);
if (err.length > 0) {
return hs.wrong(err);
}
if (out.includes("Compiled successfully.")) {
break;
}
}
return await test();
} finally {
server.kill();
}
}
exports.startServerAndTest = startServerAndTest;