-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
71 lines (65 loc) · 1.91 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
var _ = require('lodash');
/*
JSON Reporter that reports just the Summary Info
Collection.Info.Name
Collection.Info.Id
Run.Stats.Requests.*
Run.Stats.Assertions.*
Run.Timings.*
Run.Failures[n].Parent.Name
Run.Failures[n].Parent.Id
Run.Failures[n].Source.Name
Run.Failures[n].Source.Id
Run.Failures[n].Error.Message
Run.Failures[n].Error.Test
*/
function createSummary(summary) {
// Just pull out the miminum parts for each failure
var failures = [];
summary.run.failures.forEach(function(failure) {
failures.push({
'Parent': {
'Name': failure.parent.name,
'Id' : failure.parent.id
},
'Source': {
'Name': failure.source.name,
'Id' : failure.source.id
},
'Error': {
'Message': failure.error.message,
'Test' : failure.error.test
}
});
});
// Build main object with just the bits needed plus the slimmed down failures
var result = {};
Object.assign(result, {
'Collection': {
'Info': {
'Name': summary.collection.name,
'Id': summary.collection.id
}
},
'Run': {
'Stats': {
"Requests" : summary.run.stats.requests,
"Assertions" : summary.run.stats.assertions
},
'Failures': failures,
'Timings' : summary.run.timings
}
});
return result;
}
module.exports = function(newman, options) {
newman.on('beforeDone', function(err, data) {
if (err) { return; }
newman.exports.push({
name: 'newman-reporter-json-summary',
default: 'summary.json',
path: options.summaryJsonExport,
content: JSON.stringify(createSummary(data.summary))
});
});
};