-
Notifications
You must be signed in to change notification settings - Fork 0
/
amdjs-run.js
41 lines (35 loc) · 974 Bytes
/
amdjs-run.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
const fs = require('fs');
const browserDo = require('browser-do');
const { Writable } = require('stream');
let result = null;
let timeoutSeconds = 20;
const opts = {mock: 'amdjs-tests/mock.js'};
const browser = process.argv[2];
if (browser) opts.browser = browser;
const server = browserDo(opts);
const detectFinish = new Writable({
write(chunk, encoding, callback) {
const lines = chunk.toString();
process.stdout.write(lines);
const check = lines.match(/#test: (\w+)/);
if (check) {
result = check[1];
process.stdout.write('amdjs-tests ' + result + '\n');
done();
}
callback();
}
});
function done() {
server.stop();
process.exit(result === 'pass' ? 0 : 1);
}
fs.createReadStream('amdjs-tests/index.html')
.pipe(server)
.pipe(detectFinish);
setTimeout(() => {
if (result === null) {
process.stdout.write('Timeout: no result received in ' + timeoutSeconds + 'seconds');
}
done();
}, timeoutSeconds * 1000);