-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Feature: shared context in beforeAll and afterAll hooks (#1770)
Co-authored-by: Mona Ghassemi <[email protected]> Co-authored-by: Matt Wynne <[email protected]> Co-authored-by: Matt Wynne <[email protected]> Co-authored-by: Mona Ghassemi <[email protected]> Co-authored-by: David Goss <[email protected]>
- Loading branch information
1 parent
96a65ca
commit 739fca6
Showing
10 changed files
with
159 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
Feature: Before/After All Hooks Context | ||
|
||
It should be possible to preserve context from a BeforeAll hook | ||
and have the context be available to the scenarios in the World | ||
|
||
Background: | ||
Given a file named "cucumber.json" with: | ||
""" | ||
{ | ||
"default": { | ||
"worldParameters": { | ||
"widgets": true | ||
} | ||
} | ||
} | ||
""" | ||
And a file named "features/a.feature" with: | ||
""" | ||
Feature: some feature | ||
Scenario: first scenario | ||
Given first step | ||
Scenario: second scenario | ||
Given second step | ||
""" | ||
|
||
Scenario: BeforeAll hooks can update world parameters before tests start | ||
Given a file named "features/support/hooks.js" with: | ||
""" | ||
const {AfterAll, BeforeAll, Given} = require('@cucumber/cucumber') | ||
const {expect} = require('chai') | ||
BeforeAll(function() { | ||
expect(this.parameters).to.deep.eq({ | ||
widgets: true | ||
}) | ||
this.parameters.foo = 1 | ||
}) | ||
Given('first step', function() { | ||
expect(this.parameters).to.deep.eq({ | ||
widgets: true, | ||
foo: 1 | ||
}) | ||
}) | ||
Given('second step', function() { | ||
expect(this.parameters).to.deep.eq({ | ||
widgets: true, | ||
foo: 1 | ||
}) | ||
}) | ||
AfterAll(function() { | ||
expect(this.parameters).to.deep.eq({ | ||
widgets: true, | ||
foo: 1 | ||
}) | ||
}) | ||
""" | ||
When I run cucumber-js | ||
Then it passes | ||
|
||
Scenario: Many BeforeAll hooks can accumulate updates to the world parameters | ||
Given a file named "features/support/hooks.js" with: | ||
""" | ||
const {AfterAll, BeforeAll, Given} = require('@cucumber/cucumber') | ||
const {expect} = require('chai') | ||
BeforeAll(function() { | ||
this.parameters.foo = 1 | ||
}) | ||
BeforeAll(function() { | ||
this.parameters.bar = 2 | ||
}) | ||
Given('first step', function() { | ||
expect(this.parameters).to.deep.eq({ | ||
widgets: true, | ||
foo: 1, | ||
bar: 2 | ||
}) | ||
}) | ||
Given('second step', function() {}) | ||
""" | ||
When I run cucumber-js | ||
Then it passes | ||
|
||
Scenario: Works the same way on the parallel runtime | ||
Given a file named "features/support/hooks.js" with: | ||
""" | ||
const {AfterAll, BeforeAll, Given} = require('@cucumber/cucumber') | ||
const {expect} = require('chai') | ||
BeforeAll(function() { | ||
this.parameters.foo = 1 | ||
}) | ||
Given('first step', function() { | ||
expect(this.parameters).to.deep.eq({ | ||
widgets: true, | ||
foo: 1 | ||
}) | ||
}) | ||
Given('second step', function() {}) | ||
""" | ||
When I run cucumber-js with `--parallel 2` | ||
Then it passes | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,6 +123,7 @@ | |
"Michael Lloyd Morris (https://github.com/michael-lloyd-morris)", | ||
"Michael Zedeler <[email protected]>", | ||
"Miika Hänninen <[email protected]>", | ||
"Mona Ghassemi (https://github.com/BlueMona)", | ||
"nebehr <[email protected]>", | ||
"Nico Jansen <[email protected]>", | ||
"Niklas Närhinen <[email protected]>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters