forked from js-tasks-ru/nodejs-20190329-2_dobiday
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreporter.js
45 lines (39 loc) · 949 Bytes
/
reporter.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
const mocha = require('mocha');
function Reporter(runner) {
mocha.reporters.Base.call(this, runner);
let passes = 0;
let failures = 0;
const tests = [];
runner.on('pass', function(test) {
passes++;
tests.push({
description: test.title,
success: true,
suite: test.parent.titlePath(),
time: test.duration,
});
});
runner.on('fail', function(test, err) {
failures++;
tests.push({
description: test.title,
success: false,
suite: test.parent.titlePath(),
time: test.duration,
});
});
runner.on('end', function() {
console.log(JSON.stringify({
result: {
mocha: tests,
},
summary: {
success: passes,
failed: failures,
},
}));
});
}
module.exports = Reporter;
// To have this reporter "extend" a built-in reporter uncomment the following line:
// mocha.utils.inherits(MyReporter, mocha.reporters.Spec);