-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
55 lines (45 loc) · 1.53 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
/*global require,console,process,module*/
var parseResult,
output = {};
(function () {
'use strict';
var fs = require('fs'),
SPECJSONReporter;
function getCurrentOutputPointer(suite) {
var current = output,
key = suite.join(' ');
if (current[key] === undefined) {
current[key] = {};
}
current = current[key];
return current;
}
parseResult = function (result) {
var testStatus = result.success ? 'PASSED' : 'FAILED',
current = getCurrentOutputPointer(result.suite);
current[result.description] = testStatus;
};
SPECJSONReporter = function (baseReporterDecorator, config) {
baseReporterDecorator(this);
this.onSpecComplete = function (browser, result) {
parseResult(result, browser);
};
this.onRunComplete = function () {
if (config.outputFile) {
fs.writeFile(config.outputFile, JSON.stringify(output, null, 4), function (err) {
if (err) {
console.log(err);
} else {
console.log("JSON file was written to " + config.outputFile);
}
});
} else {
process.stdout.write(JSON.stringify(output));
}
};
};
SPECJSONReporter.$inject = ['baseReporterDecorator', 'config.specjsonReporter'];
module.exports = {
'reporter:specjson': ['type', SPECJSONReporter]
};
}());