Skip to content

Commit 71a5f32

Browse files
committed
ignore empty Before steps
Prevent "undefined" being displayed in step name (fix for #13)
1 parent d7965b6 commit 71a5f32

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/html_formatter.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ module.exports = (function () {
3838
return step.keyword.trim() === 'After' && step.name === undefined && step.embeddings === undefined;
3939
}
4040

41+
/**
42+
* Checks if the step is an empty Before step
43+
* @param step - object which contains step data
44+
* @returns boolean
45+
*/
46+
function isEmptyBeforeStep(step) {
47+
return step.keyword.trim() === 'Before' && step.name === undefined && step.embeddings === undefined;
48+
}
49+
4150
/**
4251
* Checks if the step is an After step containing a screenshot
4352
* @param step - object which contains step data
@@ -62,7 +71,7 @@ module.exports = (function () {
6271
return compiled({
6372
status: step.result ? step.result.status : '',
6473
errorDetails: step.result ? toHtmlEntities(step.result.error_message) : '',
65-
name: step.keyword + step.name,
74+
name: step.keyword + (step.name ? step.name : ''),
6675
dataTable: step.rows ? step.rows : ''
6776
});
6877
}
@@ -178,7 +187,7 @@ module.exports = (function () {
178187
for (var k = 0; k < testResults[i].elements[j].steps.length; k++) {
179188
step = testResults[i].elements[j].steps[k];
180189

181-
if(isEmptyAfterStep(step)) {
190+
if(isEmptyAfterStep(step) || isEmptyBeforeStep(step)) {
182191
continue;
183192
}
184193

test/data/cucumber_report.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@
1616
"description": "",
1717
"type": "scenario",
1818
"steps": [
19+
{
20+
"keyword": "Before ",
21+
"hidden": true,
22+
"result": {
23+
"status": "passed",
24+
"duration": 11258903
25+
},
26+
"match": {
27+
"location": "...\\src\\test\\hooks.js:2"
28+
}
29+
},
1930
{
2031
"name": "I login as teacher",
2132
"line": 4,

0 commit comments

Comments
 (0)