Skip to content

Commit

Permalink
hooks: update parameter to include pickle (#947)
Browse files Browse the repository at this point in the history
  • Loading branch information
gd46 authored and charlierudolph committed Oct 14, 2017
1 parent ed8fbef commit ca74e8d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
5 changes: 3 additions & 2 deletions docs/support_files/api_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ Defines a hook which is run after each scenario.
* `tags`: string tag expression used to apply this hook to only specific scenarios. See [cucumber-tag-expressions](https://docs.cucumber.io/tag-expressions/) for more information
* `timeout`: A hook-specific timeout, to override the default timeout.
* `fn`: A function, defined as follows:
* The first argument will be an object of the form `{sourceLocation: {line, uri}, result: {duration, status}}` matching the event data for `test-case-finished`
* The first argument will be an object of the form `{sourceLocation: {line, uri}, result: {duration, status}, pickle}`
* The pickle object comes from the [gherkin](https://github.com/cucumber/cucumber/tree/gherkin-v4.1.3/gherkin) library. See `testdata/good/*.pickles.ndjson` for examples of its structure.
* When using the asynchronous callback interface, have one final argument for the callback function.

`options` can also be a string as a shorthand for specifying `tags`.
Expand All @@ -60,7 +61,7 @@ Multiple `AfterAll` hooks are executed in the **reverse** order that they are de

#### `Before([options,] fn)`

Defines a hook which is run before each scenario. Same interface as `After` except the first argument passed to `fn` will be an object of the form `{sourceLocation: {line, uri}}` matching the event data for `test-case-started`.
Defines a hook which is run before each scenario. Same interface as `After` except the first argument passed to `fn` will not have the `result` property.

Multiple `Before` hooks are executed in the order that they are defined.

Expand Down
10 changes: 10 additions & 0 deletions features/hook_parameter.feature
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ Feature: Hook Parameters
defineSupportCode(({Before}) => {
Before(function(testCase) {
console.log(testCase.sourceLocation.uri + ":" + testCase.sourceLocation.line)
console.log('tags: ', testCase.pickle.tags);
console.log('name: ', testCase.pickle.name);
})
})
"""
When I run cucumber.js
Then the output contains the text:
"""
features/my_feature.feature:2
tags: []
name: a scenario
"""

@spawn
Expand Down Expand Up @@ -65,6 +69,8 @@ Feature: Hook Parameters
message += "did not fail"
}
console.log(message)
console.log('tags: ', testCase.pickle.tags);
console.log('name: ', testCase.pickle.name);
})
})
"""
Expand All @@ -73,8 +79,12 @@ Feature: Hook Parameters
And the output contains the text:
"""
features/my_feature.feature:2 did not fail
tags: []
name: a scenario
"""
And the output contains the text:
"""
features/my_feature.feature:5 failed
tags: []
name: another scenario
"""
4 changes: 3 additions & 1 deletion src/runtime/test_case_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,13 @@ export default class TestCaseRunner {
this.emitPrepared()
this.emit('test-case-started', {})
await this.runHooks(this.beforeHookDefinitions, {
sourceLocation: this.testCaseSourceLocation
sourceLocation: this.testCaseSourceLocation,
pickle: this.testCase.pickle
})
await this.runSteps()
await this.runHooks(this.afterHookDefinitions, {
sourceLocation: this.testCaseSourceLocation,
pickle: this.testCase.pickle,
result: this.result
})
this.emit('test-case-finished', { result: this.result })
Expand Down

0 comments on commit ca74e8d

Please sign in to comment.