-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
62 lines (54 loc) · 1.44 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* eslint-disable no-console */
const run = require('./lib/browser-run');
const {Transform} = require('stream');
const tapParse = require('./lib/tap-parse');
module.exports = function(opts = {}) {
const tap = opts.tap || opts.tape || opts.jasmine || opts.mocha;
const chunks = [];
const dpl = new Transform({
transform(chunk, enc, cb) {
chunks.push(chunk);
cb();
},
flush(cb) {
const self = this;
let failed = false;
let browserDo;
self.stop = () => browserDo && browserDo.stop();
const holdOutput = new Transform({
transform(chunk, enc, _cb) {
_cb(null, chunk);
self.push(chunk);
},
flush(_cb) {
if (!tap) cb();
_cb();
}
});
const data = Buffer.concat(chunks).toString();
browserDo = run(opts, data, holdOutput);
if (tap) {
tapParse(holdOutput, (err, passed) => {
failed = !passed;
if (err) {
console.error(err.message);
}
if (opts.onCoverage) {
browserDo.askCoverage();
}
if (!opts.keepOpen) {
setTimeout(() => {
if (opts.onCoverage) {
browserDo.checkCoverage(opts.onCoverage);
}
self.stop();
cb();
self.emit('exit', failed ? 1 : 0);
}, 1000);
}
});
}
}
});
return dpl;
};