Skip to content

Commit 406aaa0

Browse files
Evgeniy LukoyanovDavertMik
authored andcommitted
Fix steps output for CLI for async/arrow functions (#1329)
* fix steps output for cli * fix bdd steps cli output, fixed within_test
1 parent babf9ae commit 406aaa0

5 files changed

Lines changed: 59 additions & 35 deletions

File tree

‎lib/output.js‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,15 @@ module.exports = {
7777
step(step) {
7878
if (outputLevel === 0) return;
7979
if (!step) return;
80+
// Avoid to print non-gherkin steps, when gherkin is running for --steps mode
81+
if (outputLevel === 1) {
82+
if (!step.isMetaStep() && step.hasBDDAncestor()) {
83+
return;
84+
}
85+
}
86+
8087
let stepLine = step.toString();
81-
if (step.metaStep) {
82-
if (outputLevel < 2) return;
88+
if (step.metaStep && outputLevel >= 2) {
8389
this.stepShift += 2;
8490
stepLine = colors.green(truncate(stepLine, this.spaceShift));
8591
}

‎lib/step.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,22 @@ class Step {
100100
isMetaStep() {
101101
return this.constructor.name === 'MetaStep';
102102
}
103+
104+
hasBDDAncestor() {
105+
let hasBDD = false;
106+
let processingStep;
107+
processingStep = this;
108+
109+
while (processingStep.metaStep) {
110+
if (processingStep.metaStep.actor.match(/^(Given|When|Then|And)/)) {
111+
hasBDD = true;
112+
break;
113+
} else {
114+
processingStep = processingStep.metaStep;
115+
}
116+
}
117+
return hasBDD;
118+
}
103119
}
104120

105121

‎test/data/sandbox/within_helper.js‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11

22
const Helper = require('../../../lib/helper');
33
const output = require('../../../lib/output');
4+
const Step = require('../../../lib/step');
45

5-
class Whithin extends Helper {
6+
class Within extends Helper {
67
_withinBegin(testStr) {
7-
output.step(`Hey! I am within Begin. I get ${testStr}`);
8+
output.step(new Step(this.constructor.name, `Hey! I am within Begin. I get ${testStr}`));
89
}
910

1011
_withinEnd() {
11-
output.step('oh! I am within end(');
12+
output.step(new Step(this.constructor.name, 'oh! I am within end('));
1213
}
1314

1415
_failed() {
@@ -24,12 +25,12 @@ class Whithin extends Helper {
2425
setTimeout(() => {
2526
resolve('result');
2627
}, 100);
27-
}).then(() => output.step('small Promise was finished'));
28+
}).then(() => output.step(new Step(this.constructor.name, 'small Promise was finished')));
2829
}
2930

3031
errorStep() {
3132
throw new Error('ups, error');
3233
}
3334
}
3435

35-
module.exports = Whithin;
36+
module.exports = Within;

‎test/runner/bdd_test.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ describe('BDD Gherkin', () => {
2121
stdout.should.include('And I have product with $1000 price');
2222
stdout.should.include('Then I should see that total number of products is 2');
2323
stdout.should.include('And my order amount is $1600');
24-
stdout.should.not.include('I add item 600');
24+
stdout.should.not.include('I add item 600'); // 'Given' actor's non-gherkin step check
25+
stdout.should.not.include('I see sum 1600'); // 'And' actor's non-gherkin step check
2526
assert(!err);
2627
done();
2728
});

‎test/runner/within_test.js‎

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ describe('CodeceptJS within', function () {
2424
testStatus.should.include('OK');
2525
withoutGeneratorList.should.eql([
2626
'I small promise ',
27-
'small Promise was finished',
28-
'Hey! I am within Begin. I get blabla',
27+
'I small Promise was finished ',
28+
'I Hey! I am within Begin. I get blabla ',
2929
'Within "blabla" ',
3030
'I small promise ',
31-
'small Promise was finished',
32-
'oh! I am within end(',
31+
'I small Promise was finished ',
32+
'I oh! I am within end( ',
3333
], 'check steps execution order');
3434
done();
3535
});
@@ -44,16 +44,16 @@ describe('CodeceptJS within', function () {
4444
testStatus.should.include('OK');
4545
withGeneratorList.should.eql([
4646
'I small promise ',
47-
'small Promise was finished',
47+
'I small Promise was finished ',
4848
'I small yield ',
4949
'I am small yield string',
50-
'Hey! I am within Begin. I get blabla',
50+
'I Hey! I am within Begin. I get blabla ',
5151
'Within "blabla" ',
5252
'I small yield ',
5353
'I am small yield string',
5454
'I small promise ',
55-
'small Promise was finished',
56-
'oh! I am within end(',
55+
'I small Promise was finished ',
56+
'I oh! I am within end( ',
5757
], 'check steps execution order');
5858

5959
done();
@@ -69,16 +69,16 @@ describe('CodeceptJS within', function () {
6969
testStatus.should.include('OK');
7070
withGeneratorListOtherOrder.should.eql([
7171
'I small promise ',
72-
'small Promise was finished',
72+
'I small Promise was finished ',
7373
'I small yield ',
7474
'I am small yield string',
75-
'Hey! I am within Begin. I get blabla',
75+
'I Hey! I am within Begin. I get blabla ',
7676
'Within "blabla" ',
7777
'I small promise ',
78-
'small Promise was finished',
78+
'I small Promise was finished ',
7979
'I small yield ',
8080
'I am small yield string',
81-
'oh! I am within end(',
81+
'I oh! I am within end( ',
8282
], 'check steps execution order');
8383

8484
done();
@@ -94,16 +94,16 @@ describe('CodeceptJS within', function () {
9494
testStatus.should.include('OK');
9595
withGeneratorList.should.eql([
9696
'I small promise ',
97-
'small Promise was finished',
97+
'I small Promise was finished ',
9898
'I small yield ',
9999
'I am small yield string await',
100-
'Hey! I am within Begin. I get blabla',
100+
'I Hey! I am within Begin. I get blabla ',
101101
'Within "blabla" ',
102102
'I small yield ',
103103
'I am small yield string await',
104104
'I small promise ',
105-
'small Promise was finished',
106-
'oh! I am within end(',
105+
'I small Promise was finished ',
106+
'I oh! I am within end( ',
107107
], 'check steps execution order');
108108

109109
done();
@@ -119,16 +119,16 @@ describe('CodeceptJS within', function () {
119119
testStatus.should.include('OK');
120120
withGeneratorList.should.eql([
121121
'I small promise ',
122-
'small Promise was finished',
122+
'I small Promise was finished ',
123123
'I small yield ',
124124
'I am small yield string await',
125-
'Hey! I am within Begin. I get blabla',
125+
'I Hey! I am within Begin. I get blabla ',
126126
'Within "blabla" ',
127127
'I small promise ',
128-
'small Promise was finished',
128+
'I small Promise was finished ',
129129
'I small yield ',
130130
'I am small yield string await',
131-
'oh! I am within end(',
131+
'I oh! I am within end( ',
132132
], 'check steps execution order');
133133

134134
done();
@@ -146,15 +146,15 @@ describe('CodeceptJS within', function () {
146146
withGeneratorListWithContinued.should.eql([
147147
'I small yield ',
148148
'I am small yield string',
149-
'Hey! I am within Begin. I get blabla',
149+
'I Hey! I am within Begin. I get blabla ',
150150
'Within "blabla" ',
151151
'I small yield ',
152152
'I am small yield string',
153153
'I small promise ',
154-
'small Promise was finished',
155-
'oh! I am within end(',
154+
'I small Promise was finished ',
155+
'I oh! I am within end( ',
156156
'I small promise ',
157-
'small Promise was finished',
157+
'I small Promise was finished ',
158158
], 'check steps execution order');
159159
done();
160160
});
@@ -170,10 +170,10 @@ describe('CodeceptJS within', function () {
170170
errorInWithinList.should.eql([
171171
'I small yield ',
172172
'I am small yield string',
173-
'Hey! I am within Begin. I get blabla',
173+
'I Hey! I am within Begin. I get blabla ',
174174
'Within "blabla" ',
175175
'I error step ',
176-
'oh! I am within end(',
176+
'I oh! I am within end( ',
177177
], 'check steps execution order');
178178

179179
done();
@@ -189,7 +189,7 @@ describe('CodeceptJS within', function () {
189189
testStatus.should.include('FAILED');
190190
errorInTestList.should.eql([
191191
'I error step ',
192-
'oh! I am within end(',
192+
'I oh! I am within end( ',
193193
], 'check steps execution order');
194194

195195
done();

0 commit comments

Comments
 (0)