Skip to content

Commit

Permalink
pass step specific options to definition function wrapper (#838)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgandecki authored and charlierudolph committed Jun 10, 2017
1 parent 142ca56 commit ac33ce6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
40 changes: 40 additions & 0 deletions features/step_wrapper_with_options.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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

Background:
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:
"""
import {defineSupportCode} from 'cucumber'
defineSupportCode(({Then, When}) => {
When(/^I run a step with options$/, {wrapperOptions: {retry: 2}}, function () {})
})
"""
And a file named "features/support/setup.js" with:
"""
import {defineSupportCode} from 'cucumber'
defineSupportCode(({setDefinitionFunctionWrapper}) => {
setDefinitionFunctionWrapper(function (fn, options = {}) {
if (options.retry) {
console.log("Max retries: ", options.retry);
}
return fn;
})
})
"""

Scenario: options passed to the step definitions wrapper
When I run cucumber-js
Then the output contains the text:
"""
Max retries: 2
"""
2 changes: 1 addition & 1 deletion src/support_code_library/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function wrapDefinitions({cwd, definitionFunctionWrapper, definitions}) {
if (definitionFunctionWrapper) {
definitions.forEach((definition) => {
const codeLength = definition.code.length
const wrappedFn = definitionFunctionWrapper(definition.code)
const wrappedFn = definitionFunctionWrapper(definition.code, definition.options.wrapperOptions)
if (wrappedFn !== definition.code) {
definition.code = arity(codeLength, wrappedFn)
}
Expand Down

0 comments on commit ac33ce6

Please sign in to comment.