From ca74e8d7c0c78c6683a6a60cf6c59a9ecf7d7c7e Mon Sep 17 00:00:00 2001 From: Giuseppe DiBella Date: Sat, 14 Oct 2017 11:33:39 -0400 Subject: [PATCH] hooks: update parameter to include pickle (#947) --- docs/support_files/api_reference.md | 5 +++-- features/hook_parameter.feature | 10 ++++++++++ src/runtime/test_case_runner.js | 4 +++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/docs/support_files/api_reference.md b/docs/support_files/api_reference.md index 243dc5506..1a67972a6 100644 --- a/docs/support_files/api_reference.md +++ b/docs/support_files/api_reference.md @@ -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`. @@ -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. diff --git a/features/hook_parameter.feature b/features/hook_parameter.feature index 445bcbb59..11b2923ff 100644 --- a/features/hook_parameter.feature +++ b/features/hook_parameter.feature @@ -23,6 +23,8 @@ 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); }) }) """ @@ -30,6 +32,8 @@ Feature: Hook Parameters Then the output contains the text: """ features/my_feature.feature:2 + tags: [] + name: a scenario """ @spawn @@ -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); }) }) """ @@ -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 """ diff --git a/src/runtime/test_case_runner.js b/src/runtime/test_case_runner.js index d97f73845..8341296b5 100644 --- a/src/runtime/test_case_runner.js +++ b/src/runtime/test_case_runner.js @@ -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 })