Skip to content

Commit 6b21196

Browse files
committed
(refactor) Update testCase to include pickle object
1 parent 6c8bad2 commit 6b21196

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

docs/support_files/api_reference.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ Defines a hook which is run after each scenario.
3636
* `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
3737
* `timeout`: A hook-specific timeout, to override the default timeout.
3838
* `fn`: A function, defined as follows:
39-
* The first argument will be an object of the form `{sourceLocation: {line, uri}, result: {duration, status}}` matching the event data for `test-case-finished`
39+
* The first argument will be an object of the form `{sourceLocation: {line, uri}, result: {duration, status}, pickle: { tags: [{ name, location: { line, column } }], name, language, locations: [{ line, column }], steps: [{ text, arguments: [], locations: [{ line, column }] }]}}` matching the event data for `test-case-finished`
4040
* When using the asynchronous callback interface, have one final argument for the callback function.
41+
* The pickle object comes from [gherkin](https://github.com/cucumber/cucumber/tree/gherkin-v4.1.3/gherkin) library
4142

4243
`options` can also be a string as a shorthand for specifying `tags`.
4344

@@ -60,7 +61,7 @@ Multiple `AfterAll` hooks are executed in the **reverse** order that they are de
6061

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

63-
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`.
64+
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}, pickle: { tags: [{ name, location: { line, column } }], name, language, locations: [{ line, column }], steps: [{ text, arguments: [], locations: [{ line, column }] }]}}` matching the event data for `test-case-started`.
6465

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

features/hook_parameter.feature

+10
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@ Feature: Hook Parameters
2323
defineSupportCode(({Before}) => {
2424
Before(function(testCase) {
2525
console.log(testCase.sourceLocation.uri + ":" + testCase.sourceLocation.line)
26+
console.log('tags: ', testCase.pickle.tags);
27+
console.log('name: ', testCase.pickle.name);
2628
})
2729
})
2830
"""
2931
When I run cucumber.js
3032
Then the output contains the text:
3133
"""
3234
features/my_feature.feature:2
35+
tags: []
36+
name: a scenario
3337
"""
3438

3539
@spawn
@@ -65,6 +69,8 @@ Feature: Hook Parameters
6569
message += "did not fail"
6670
}
6771
console.log(message)
72+
console.log('tags: ', testCase.pickle.tags);
73+
console.log('name: ', testCase.pickle.name);
6874
})
6975
})
7076
"""
@@ -73,8 +79,12 @@ Feature: Hook Parameters
7379
And the output contains the text:
7480
"""
7581
features/my_feature.feature:2 did not fail
82+
tags: []
83+
name: a scenario
7684
"""
7785
And the output contains the text:
7886
"""
7987
features/my_feature.feature:5 failed
88+
tags: []
89+
name: another scenario
8090
"""

src/runtime/test_case_runner.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,13 @@ export default class TestCaseRunner {
154154
this.emitPrepared()
155155
this.emit('test-case-started', {})
156156
await this.runHooks(this.beforeHookDefinitions, {
157-
sourceLocation: this.testCaseSourceLocation
157+
sourceLocation: this.testCaseSourceLocation,
158+
pickle: this.testCase.pickle
158159
})
159160
await this.runSteps()
160161
await this.runHooks(this.afterHookDefinitions, {
161162
sourceLocation: this.testCaseSourceLocation,
163+
pickle: this.testCase.pickle,
162164
result: this.result
163165
})
164166
this.emit('test-case-finished', { result: this.result })

0 commit comments

Comments
 (0)