forked from mikeperri/karma-longest-reporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (28 loc) · 1.04 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
const os = require('os');
const LongestReporter = function (baseReporterDecorator, helper, { maximumDisplay = 10, minimumMillis = 0 }) {
baseReporterDecorator(this);
const write = process.stdout.write.bind(process.stdout);
const specs = [];
this.onSpecComplete = function (browser, result) {
const name = result.suite.join(' ') + ' ' + result.description;
const time = result.time;
specs.push({
name,
time
});
};
this.onBrowserComplete = function (browser) {
const longestSpecs = specs
.sort((a, b) => (a.time < b.time ? 1 : -1))
.slice(0, maximumDisplay);
longestSpecs
.filter(spec => spec.time > minimumMillis)
.forEach(spec =>
write(helper.formatTimeInterval(spec.time) + ': ' + spec.name + os.EOL)
);
};
};
LongestReporter.$inject = ['baseReporterDecorator', 'helper', 'config.longestSpecsToReport'];
module.exports = {
'reporter:longest': ['type', LongestReporter]
};