-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
44 lines (34 loc) · 983 Bytes
/
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
var fs = require('fs')
var defaultOpts = {
file: 'jasmine-test-results.json',
beautify: true,
indentationLevel: 4 // used if beautify === true
};
function reporter(opts) {
var options = shallowMerge(defaultOpts, typeof opts === 'object' ? opts : {});
var specResults = [];
var masterResults = Object.create(null);
this.suiteDone = function(suite) {
suite.specs = specResults;
masterResults[suite.id] = suite;
specResults = [];
};
this.specDone = function(spec) {
specResults.push(spec);
};
this.jasmineDone = function() {
var resultsOutput = options.beautify ?
JSON.stringify(masterResults, null, options.indentationLevel) :
JSON.stringify(masterResults);
fs.writeFileSync(options.file, resultsOutput);
};
};
function shallowMerge(obj1, obj2) {
var mergedObj = {};
Object.keys(obj1).forEach(function(key) {
if (!obj2[key]) mergedObj[key] = obj1[key];
else mergedObj[key] = obj2[key];
});
return mergedObj;
};
module.exports = reporter;