Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(refactor) Update testCase to include pickle object #947

Merged
merged 3 commits into from
Oct 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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