-
Notifications
You must be signed in to change notification settings - Fork 1
/
reporter.js
70 lines (58 loc) · 1.24 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var Base = require('./base'),
cursor = Base.cursor,
color = Base.color;
exports = module.exports = BambooJSONReporter;
/**
* Initialize a new `JSON` reporter.
*
* @param {Runner} runner
* @api public
*/
function BambooJSONReporter(runner) {
var self = this;
Base.call(this, runner);
var tests = [],
failures = [],
passes = [],
skipped = [];
runner.on('test end', function(test) {
tests.push(test);
});
runner.on('pending', function(test) {
skipped.push(test);
});
runner.on('pass', function(test) {
passes.push(test);
});
runner.on('fail', function(test) {
failures.push(test);
});
runner.on('end', function() {
var obj = {
stats: self.stats,
failures: failures.map(clean),
passes: passes.map(clean),
skipped: skipped.map(clean)
};
process.stdout.write(JSON.stringify(obj, null, 2));
});
}
/**
* Return a plain-object representation of `test`
* free of cyclic properties etc.
*
* @param {Object} test
* @return {Object}
* @api private
*/
function clean(test) {
var o = {
title: test.title,
fullTitle: test.fullTitle(),
duration: test.duration
}
if (test.hasOwnProperty("err")) {
o.error = test.err.stack.toString();
}
return o;
}