forked from canvaspixels/courgette
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcucumberFormatter.js
59 lines (49 loc) · 1.68 KB
/
cucumberFormatter.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
const cucumber = require('cucumber');
class CucumberStepFormatter extends cucumber.Formatter {
constructor(options) {
super(options);
options.eventBroadcaster
.on('test-step-attachment', this.attached.bind(this))
.on('test-case-started', this.logTestCaseName.bind(this))
.on('test-step-finished', this.logTestStep.bind(this))
.on('test-case-finished', this.logSeparator.bind(this))
.on('test-run-finished', this.logTestRunResult.bind(this));
}
attached({ data }) {
if (data.includes('Hook Step:')) {
this.hookStep = data;
}
}
logTestCaseName({ sourceLocation }) {
const { gherkinDocument, pickle } = this.eventDataCollector.getTestCaseData(sourceLocation);
const text = `${gherkinDocument.feature.name}::: ${pickle.name}\n`;
const colouredText = this.colorFns.location(text);
this.log(colouredText);
}
logTestStep({ testCase, index, result }) {
const { gherkinKeyword, pickleStep } =
this.eventDataCollector.getTestStepData({ testCase, index });
let text;
if (pickleStep) {
text = `${gherkinKeyword}${pickleStep.text} ---> ${result.status.toUpperCase()}\n`;
} else {
const statusUpper = result.status.toUpperCase();
text = statusUpper === 'FAILED' ? `${this.hookStep} - FAILED\n\n` : '';
}
if (text) {
const colouredText = this.colorFns[result.status](text);
this.log(colouredText);
}
}
logSeparator() {
this.log('\n');
}
logTestRunResult({ result }) {
if (result.success) {
this.log(this.colorFns.passed('---PASS---'));
} else {
this.log(this.colorFns.failed('---FAIL---'));
}
}
}
module.exports = CucumberStepFormatter;