-
-
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.
Revert "remove support for generators (#1725)"
This reverts commit a2dcce6.
- Loading branch information
1 parent
06be59a
commit f568877
Showing
19 changed files
with
400 additions
and
73 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
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,61 @@ | ||
Feature: Generator Step Definitions | ||
In order to use new JavaScript features | ||
As a developer | ||
I want Cucumber to provide the possibility to use ES6 features | ||
|
||
Background: | ||
Given a file named "features/a.feature" with: | ||
""" | ||
Feature: Step is a generator | ||
Scenario: Step generator run successfully | ||
When I call a step which is a generator with return value "ok" | ||
Then I can see the yielded "ok" value in the context | ||
""" | ||
And a file named "features/step_definitions/cucumber_steps.js" with: | ||
""" | ||
const assert = require('assert') | ||
const {setWorldConstructor, Then, When} = require('@cucumber/cucumber') | ||
setWorldConstructor(function () { | ||
this.context = "" | ||
}) | ||
When(/^I call a step which is a generator with return value "([^"]*)"$/, function *(return_value) { | ||
this.context = yield Promise.resolve(return_value); | ||
}) | ||
Then(/^I can see the yielded "([^"]*)" value in the context$/, function(return_value) { | ||
assert.equal(this.context, return_value) | ||
}) | ||
""" | ||
|
||
@spawn | ||
Scenario: without generator function runner | ||
When I run cucumber-js | ||
Then it fails | ||
And the error output contains the text: | ||
""" | ||
The following hook/step definitions use generator functions: | ||
features/step_definitions/cucumber_steps.js:8 | ||
Use 'this.setDefinitionFunctionWrapper(fn)' to wrap them in a function that returns a promise | ||
""" | ||
|
||
Scenario: with generator function wrapper | ||
Given a file named "features/support/setup.js" with: | ||
""" | ||
const isGenerator = require('is-generator') | ||
const {coroutine} = require('bluebird') | ||
const {setDefinitionFunctionWrapper} = require('@cucumber/cucumber') | ||
setDefinitionFunctionWrapper(function (fn) { | ||
if (isGenerator.fn(fn)) { | ||
return coroutine(fn) | ||
} else { | ||
return fn | ||
} | ||
}) | ||
""" | ||
When I run cucumber-js | ||
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
Feature: Step Wrapper with Options | ||
In order to be able to write more complex step definition wrappers | ||
As a developer | ||
I want Cucumber to provide the "options" object to the wrapping function | ||
|
||
@spawn | ||
Scenario: options passed to the step definitions wrapper | ||
Given a file named "features/a.feature" with: | ||
""" | ||
Feature: Step with an option | ||
Scenario: Steps | ||
When I run a step with options | ||
""" | ||
And a file named "features/step_definitions/cucumber_steps.js" with: | ||
""" | ||
const {When} = require('@cucumber/cucumber') | ||
When(/^I run a step with options$/, {wrapperOptions: {retry: 2}}, function () {}) | ||
""" | ||
And a file named "features/support/setup.js" with: | ||
""" | ||
const {setDefinitionFunctionWrapper} = require('@cucumber/cucumber') | ||
setDefinitionFunctionWrapper(function (fn, options = {}) { | ||
if (options.retry) { | ||
console.log("Max retries: ", options.retry); | ||
} | ||
return fn; | ||
}) | ||
""" | ||
When I run cucumber-js | ||
Then the output contains the text: | ||
""" | ||
Max retries: 2 | ||
""" |
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
Oops, something went wrong.