Skip to content

Commit 28813b3

Browse files
Mykhailo BodnarchukMykhailo Bodnarchuk
Mykhailo Bodnarchuk
authored and
Mykhailo Bodnarchuk
committed
Merge branch 'codeceptjs-v3.0' of github.com:Codeception/CodeceptJS into codeceptjs-v3.0
2 parents 5b835f3 + 499df6e commit 28813b3

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

docs/hooks.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,12 +374,14 @@ Available events:
374374
* `event.suite.before(suite)` - *async* before a suite
375375
* `event.suite.after(suite)` - *async* after a suite
376376
* `event.step.before(step)` - *async* when the step is scheduled for execution
377-
* `event.step.after(step)`- *async* after a step
377+
* `event.step.after(step)` - *async* after a step
378378
* `event.step.started(step)` - *sync* when step starts.
379379
* `event.step.passed(step)` - *sync* when step passed.
380380
* `event.step.failed(step, err)` - *sync* when step failed.
381381
* `event.step.finished(step)` - *sync* when step finishes.
382382
* `event.step.comment(step)` - *sync* fired for comments like `I.say`.
383+
* `event.bddStep.before(bddStep)` - *async* when the gherkin step is scheduled for execution
384+
* `event.bddStep.after(bddStep)` - *async* after a gherkin step
383385
* `event.all.before` - before running tests
384386
* `event.all.after` - after running tests
385387
* `event.all.result` - when results are printed

lib/event.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ module.exports = {
7878
finished: 'step.finish', // sync
7979
comment: 'step.comment',
8080
},
81+
/**
82+
* @type {object}
83+
* @constant
84+
* @inner
85+
* @property {'suite.before'} before
86+
* @property {'suite.after'} after
87+
*/
88+
bddStep: {
89+
before: 'bddStep.before',
90+
after: 'bddStep.after',
91+
},
8192
/**
8293
* @type {object}
8394
* @constant

lib/interfaces/gherkin.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module.exports = (text) => {
2828

2929
const runSteps = async (steps) => {
3030
for (const step of steps) {
31+
event.emit(event.bddStep.before, step);
3132
const metaStep = new Step.MetaStep(null, step.text);
3233
metaStep.actor = step.keyword.trim();
3334
const setMetaStep = (step) => {
@@ -49,6 +50,7 @@ module.exports = (text) => {
4950
} finally {
5051
event.dispatcher.removeListener(event.step.before, setMetaStep);
5152
}
53+
event.emit(event.bddStep.after, step);
5254
}
5355
};
5456

test/unit/bdd_test.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const run = require('../../lib/interfaces/gherkin');
1111
const recorder = require('../../lib/recorder');
1212
const container = require('../../lib/container');
1313
const actor = require('../../lib/actor');
14+
const event = require('../../lib/event');
1415

1516
const text = `
1617
Feature: checkout process
@@ -168,6 +169,25 @@ describe('BDD', () => {
168169
assert.equal('bird', fn.params[0]);
169170
});
170171

172+
it('should produce step events', (done) => {
173+
const text = `
174+
Feature: Emit step event
175+
176+
Scenario:
177+
Then I emit step events
178+
`;
179+
Then('I emit step events', () => {});
180+
let listeners = 0;
181+
event.dispatcher.addListener(event.bddStep.before, () => listeners++);
182+
event.dispatcher.addListener(event.bddStep.after, () => listeners++);
183+
184+
const suite = run(text);
185+
suite.tests[0].fn(() => {
186+
listeners.should.eql(2);
187+
done();
188+
});
189+
});
190+
171191
it('should use shortened form for step definitions', () => {
172192
let fn;
173193
Given('I am a {word}', params => params[0]);
@@ -214,7 +234,7 @@ describe('BDD', () => {
214234
Given I have product with price <price>$ in my cart
215235
And discount is 10 %
216236
Then I should see price is "<total>" $
217-
237+
218238
Examples:
219239
| price | total |
220240
| 10 | 9 |

0 commit comments

Comments
 (0)