From 45849ed80839b7a0cabc63733e7eecca234963ec Mon Sep 17 00:00:00 2001 From: gd46 Date: Sat, 7 Oct 2017 19:00:22 -0400 Subject: [PATCH 1/3] (refactor) Update testCase to include pickle object --- 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 d7f867bba..664b6abe8 100644 --- a/docs/support_files/api_reference.md +++ b/docs/support_files/api_reference.md @@ -36,8 +36,9 @@ 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: { tags: [{ name, location: { line, column } }], name, language, locations: [{ line, column }], steps: [{ text, arguments: [], locations: [{ line, column }] }]}}` * When using the asynchronous callback interface, have one final argument for the callback function. + * The pickle object comes from [gherkin](https://github.com/cucumber/cucumber/tree/gherkin-v4.1.3/gherkin) library `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 be an object of the form `{sourceLocation, pickle} (see after hook for object structure)`. 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 }) From 573ef7173359209b81a96a88f367a28f123a6fe3 Mon Sep 17 00:00:00 2001 From: Charlie Rudolph Date: Sat, 14 Oct 2017 09:31:59 -0600 Subject: [PATCH 2/3] Update api_reference.md --- docs/support_files/api_reference.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/support_files/api_reference.md b/docs/support_files/api_reference.md index 664b6abe8..f435ec8b7 100644 --- a/docs/support_files/api_reference.md +++ b/docs/support_files/api_reference.md @@ -36,9 +36,10 @@ 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}, pickle: { tags: [{ name, location: { line, column } }], name, language, locations: [{ line, column }], steps: [{ text, arguments: [], locations: [{ line, column }] }]}}` + * 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. - * The pickle object comes from [gherkin](https://github.com/cucumber/cucumber/tree/gherkin-v4.1.3/gherkin) library + `options` can also be a string as a shorthand for specifying `tags`. @@ -61,7 +62,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, pickle} (see after hook for object structure)`. +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. From 23a40719a2008c7f027f9414a7a181413e39cd26 Mon Sep 17 00:00:00 2001 From: Charlie Rudolph Date: Sat, 14 Oct 2017 09:32:23 -0600 Subject: [PATCH 3/3] Update api_reference.md --- docs/support_files/api_reference.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/support_files/api_reference.md b/docs/support_files/api_reference.md index f435ec8b7..7d4e4f722 100644 --- a/docs/support_files/api_reference.md +++ b/docs/support_files/api_reference.md @@ -39,7 +39,6 @@ Defines a hook which is run after each scenario. * 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`.