-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
78 lines (66 loc) · 2.31 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
var fs = require('fs');
var path = require('path');
var mkdirp = require('mkdirp');
var fE;
var bambooReporter = function (baseReporterDecorator, config, formatError) {
fE = formatError;
baseReporterDecorator(this);
var filename = config && config.filename || 'mocha.json';
var results = {
time: 0, tests: [], failures: [], passes: [], skips: []
};
this.onRunStart = function () {
this._browsers = [];
if (fs.existsSync(filename)) {
fs.unlinkSync(filename);
}
};
this.onSpecComplete = function (browser, result) {
results.time += result.time;
result.browser = browser.name;
results.tests.push(result);
if (result.skipped) results.skips.push(result);
else if (result.success) results.passes.push(result);
else results.failures.push(result);
};
this.onRunComplete = function (browser, result) {
var obj = {
stats: {tests: (result.success + result.failed), passes: result.success, failures: result.failed, duration: results.time }, failures: results.failures.map(clean), passes: results.passes.map(clean), skipped: results.skips.map(clean)
};
// If the directoy we're supposed to write into does not exist, create it
var dir = path.dirname(filename);
if (dir !== '.') {
mkdirp.sync(dir);
}
fs.writeFileSync(filename, JSON.stringify(obj, null, 2), 'utf-8');
results = {
time: 0, tests: [], failures: [], passes: [], skips: []
};
};
};
function clean(test) {
var o = {
title : test.suite.concat(test.description).join(' '),
fullTitle : test.suite[0],
duration : test.time
};
if (!test.success) {
o.error = '';
test.log.forEach(function(log) {
// translate sourcemap
log = fE(log);
o.error += log.split('\n').reduce(function(memo, line, i) {
// keep first line
line = line.split('<-');
if (line[1]) memo += '\n\tat' + line[1];
return memo;
});
});
}
return o;
}
bambooReporter.$inject = ['baseReporterDecorator', 'config.bambooReporter', 'formatError'];
// PUBLISH DI MODULE
module.exports = {
'reporter:bamboo': ['type', bambooReporter]
};