-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
44 lines (42 loc) · 1.49 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
/* eslint-env node */
function MultiReporter (opts) {
if (!opts || !opts.reporters || !opts.reporters.length) {
throw new Error('Cannot run a multireporter without providing reports to run');
}
this.reporters = [];
opts.reporters.forEach(r => {
if (!r.ReporterClass) {
throw new Error('Each reporter must provide the reporter class');
}
// if (!r.opts) {
// process.stdout(chalk.yellow(`Reporter ${r.reporterClass.name} did not provide any options.`));
// }
this.reporters.push(new r.ReporterClass(...r.args));
});
}
MultiReporter.prototype = {
report: function (prefix, data) {
const args = arguments;
// do some helpful coersion of messages from assertions without a message
if (data.error && !data.error.message) {
if (data.error.hasOwnProperty('actual') && data.error.hasOwnProperty('expected')) {
data.error.message = `Assertion failure without message - Actual: ${data.error.actual} Expected: ${data.error.expected}`;
data.error.stack = '[stack hidden - error is assertion error]';
}
}
this.reporters.forEach(r => r.report(...args));
},
reportMetadata: function (tag, metadata) {
const args = arguments;
this.reporters.forEach(r => {
if (r.reportMetadata && typeof r.reportMetadata === "function") {
r.reportMetadata(...args);
}
});
},
finish: function () {
const args = arguments;
this.reporters.forEach(r => r.finish(...args));
}
};
module.exports = MultiReporter;