forked from tnicola/cypress-parallel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple-spec.reporter.js
86 lines (75 loc) · 2.06 KB
/
simple-spec.reporter.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
'use strict';
/**
* @module JSONStreamCustom
*/
/**
* Module dependencies.
*/
var Base = require('mocha/lib/reporters/base');
var constants = require('mocha/lib/runner').constants;
const settings = JSON.parse(process.env.CY_PARALLEL_SETTINGS);
const {
EVENT_TEST_PENDING,
EVENT_TEST_FAIL,
EVENT_TEST_PASS,
EVENT_SUITE_BEGIN
} = constants;
/**
* Expose `JSONStream`.
*/
exports = module.exports = JSONStreamCustom;
/**
* Constructs a new `JSONStreamCustom` reporter instance.
*
* @public
* @class
* @memberof Mocha.reporters
* @extends Mocha.reporters.Base
* @param {Runner} runner - Instance triggers reporter actions.
* @param {Object} [options] - runner options
*/
function JSONStreamCustom(runner, options) {
Base.call(this, runner, options);
const { color, consoleLog } = Base;
var self = this;
let currentSuite = {};
function getSuiteTitles() {
let result = '';
let current = currentSuite;
while (current.parent) {
result = `${current.title} - ${result}`;
current = current.parent;
}
return result;
}
function getTestDescription(test) {
return `${getSuiteTitles()}${test.title} (${self.runner.suite.file})`;
}
runner.on(EVENT_SUITE_BEGIN, function (suite) {
currentSuite = suite;
});
runner.on(EVENT_TEST_PENDING, function (test) {
const format = color('pending', ' - %s');
consoleLog(format, getTestDescription(test));
});
runner.on(EVENT_TEST_FAIL, function (test) {
const format = color('fail', '%s');
if (settings.isVerbose) {
consoleLog(format, {
test: getTestDescription(test),
error: test.err.stack,
})
} else {
consoleLog(format, getTestDescription(test));
}
});
runner.on(EVENT_TEST_PASS, function (test) {
const format =
color('checkmark', ' ' + Base.symbols.ok) +
color('pass', ' %s') +
color(test.speed, ' (%dms)');
consoleLog(format, getTestDescription(test), test.duration);
});
}
JSONStreamCustom.description =
'Logs test results without need for them to be reported in the correct order';