-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add BeforeAll / AfterAll hooks (#878)
- Loading branch information
1 parent
93df609
commit 9499817
Showing
17 changed files
with
617 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,251 @@ | ||
Feature: before / after all hook interfaces | ||
|
||
Rules: | ||
- before / after all hooks can be synchronous, return a promise, or accept a callback | ||
|
||
Background: | ||
Given a file named "features/a.feature" with: | ||
""" | ||
Feature: some feature | ||
Scenario: first scenario | ||
Given first step | ||
Scenario: second scenario | ||
Given second step | ||
""" | ||
And a file named "features/step_definitions/my_steps.js" with: | ||
""" | ||
import {defineSupportCode} from 'cucumber' | ||
defineSupportCode(({Given}) => { | ||
Given('first step', function() {}) | ||
Given('second step', function() {}) | ||
}) | ||
""" | ||
|
||
Scenario Outline: synchronous | ||
Given a file named "features/support/hooks.js" with: | ||
""" | ||
import {defineSupportCode} from 'cucumber' | ||
defineSupportCode(({<TYPE>}) => { | ||
<TYPE>(function() {}) | ||
}) | ||
""" | ||
When I run cucumber.js | ||
Then it passes | ||
|
||
Examples: | ||
| TYPE | | ||
| BeforeAll | | ||
| AfterAll | | ||
|
||
Scenario Outline: synchronously throws | ||
Given a file named "features/support/hooks.js" with: | ||
""" | ||
import {defineSupportCode} from 'cucumber' | ||
defineSupportCode(({<TYPE>}) => { | ||
<TYPE>(function() { | ||
throw new Error('my error') | ||
}) | ||
}) | ||
""" | ||
When I run cucumber.js | ||
Then it fails | ||
|
||
Examples: | ||
| TYPE | | ||
| BeforeAll | | ||
| AfterAll | | ||
|
||
Scenario Outline: callback without error | ||
Given a file named "features/support/hooks.js" with: | ||
""" | ||
import {defineSupportCode} from 'cucumber' | ||
defineSupportCode(({<TYPE>}) => { | ||
<TYPE>(function(callback) { | ||
setTimeout(callback) | ||
}) | ||
}) | ||
""" | ||
When I run cucumber.js | ||
Then it passes | ||
|
||
Examples: | ||
| TYPE | | ||
| BeforeAll | | ||
| AfterAll | | ||
|
||
Scenario Outline: callback with error | ||
Given a file named "features/support/hooks.js" with: | ||
""" | ||
import {defineSupportCode} from 'cucumber' | ||
defineSupportCode(({<TYPE>}) => { | ||
<TYPE>(function(callback) { | ||
setTimeout(() => { | ||
callback(new Error('my error')) | ||
}) | ||
}) | ||
}) | ||
""" | ||
When I run cucumber.js | ||
Then it fails | ||
And the error output contains the text: | ||
""" | ||
my error | ||
""" | ||
|
||
Examples: | ||
| TYPE | | ||
| BeforeAll | | ||
| AfterAll | | ||
|
||
@spawn | ||
Scenario Outline: callback asynchronously throws | ||
Given a file named "features/support/hooks.js" with: | ||
""" | ||
import {defineSupportCode} from 'cucumber' | ||
defineSupportCode(({<TYPE>}) => { | ||
<TYPE>(function(callback) { | ||
setTimeout(() => { | ||
throw new Error('my error') | ||
}) | ||
}) | ||
}) | ||
""" | ||
When I run cucumber.js | ||
Then it fails | ||
And the error output contains the text: | ||
""" | ||
my error | ||
""" | ||
|
||
Examples: | ||
| TYPE | | ||
| BeforeAll | | ||
| AfterAll | | ||
|
||
Scenario Outline: callback - returning a promise | ||
Given a file named "features/step_definitions/failing_steps.js" with: | ||
""" | ||
import {defineSupportCode} from 'cucumber' | ||
import Promise from 'bluebird' | ||
defineSupportCode(({<TYPE>}) => { | ||
<TYPE>(function(callback) { | ||
return Promise.resolve() | ||
}) | ||
}) | ||
""" | ||
When I run cucumber.js | ||
Then it fails | ||
And the error output contains the text: | ||
""" | ||
function uses multiple asynchronous interfaces: callback and promise | ||
""" | ||
|
||
Examples: | ||
| TYPE | | ||
| BeforeAll | | ||
| AfterAll | | ||
|
||
Scenario Outline: promise resolves | ||
Given a file named "features/support/hooks.js" with: | ||
""" | ||
import {defineSupportCode} from 'cucumber' | ||
import Promise from 'bluebird' | ||
defineSupportCode(({<TYPE>}) => { | ||
<TYPE>(function() { | ||
return Promise.resolve() | ||
}) | ||
}) | ||
""" | ||
When I run cucumber.js | ||
Then it passes | ||
|
||
Examples: | ||
| TYPE | | ||
| BeforeAll | | ||
| AfterAll | | ||
|
||
Scenario Outline: promise rejects with error | ||
Given a file named "features/support/hooks.js" with: | ||
""" | ||
import {defineSupportCode} from 'cucumber' | ||
import Promise from 'bluebird' | ||
defineSupportCode(({<TYPE>}) => { | ||
<TYPE>(function() { | ||
return Promise.reject(new Error('my error')) | ||
}) | ||
}) | ||
""" | ||
When I run cucumber.js | ||
Then it fails | ||
And the error output contains the text: | ||
""" | ||
my error | ||
""" | ||
|
||
Examples: | ||
| TYPE | | ||
| BeforeAll | | ||
| AfterAll | | ||
|
||
Scenario Outline: promise rejects without error | ||
Given a file named "features/support/hooks.js" with: | ||
""" | ||
import {defineSupportCode} from 'cucumber' | ||
import Promise from 'bluebird' | ||
defineSupportCode(({<TYPE>}) => { | ||
<TYPE>(function() { | ||
return Promise.reject() | ||
}) | ||
}) | ||
""" | ||
When I run cucumber.js | ||
Then it fails | ||
And the error output contains the text: | ||
""" | ||
Promise rejected without a reason | ||
""" | ||
|
||
Examples: | ||
| TYPE | | ||
| BeforeAll | | ||
| AfterAll | | ||
|
||
@spawn | ||
Scenario Outline: promise asynchronously throws | ||
Given a file named "features/support/hooks.js" with: | ||
""" | ||
import {defineSupportCode} from 'cucumber' | ||
import Promise from 'bluebird' | ||
defineSupportCode(({<TYPE>}) => { | ||
<TYPE>(function() { | ||
return new Promise(function() { | ||
setTimeout(() => { | ||
throw new Error('my error') | ||
}) | ||
}) | ||
}) | ||
}) | ||
""" | ||
When I run cucumber.js | ||
Then it fails | ||
And the error output contains the text: | ||
""" | ||
my error | ||
""" | ||
|
||
Examples: | ||
| TYPE | | ||
| BeforeAll | | ||
| AfterAll | |
Oops, something went wrong.