Cucumber / Cucumber Js / Docs
BeforeAll/AfterAll hooks and the parallel runtime
Background:
- Given a file named "
features/a.feature" with:gherkinFeature: some feature Scenario: first scenario Given a step Scenario: second scenario Given a step - And a file named "
features/steps.js" with:rubyconst {Given} = require('@cucumber/cucumber') Given('a step', () => {})
Scenario: global hooks run only on worker by default
- Given a file named "
features/support/hooks.js" with:rubyconst {AfterAll, BeforeAll} = require('@cucumber/cucumber') BeforeAll({name: 'Before test run'}, () => {}) AfterAll({name: 'After test run'}, () => {}) - When I run cucumber-js with `--parallel 2`
- Then it passes
- And the global hook "
Before test run" has 2 executions - And the global hook "
After test run" has 2 executions
Scenario: global hooks run only on worker when specified
- Given a file named "
features/support/hooks.js" with:rubyconst {AfterAll, BeforeAll, HookTarget} = require('@cucumber/cucumber') BeforeAll({name: 'Before test run', on: HookTarget.WORKER}, () => {}) AfterAll({name: 'After test run', on: HookTarget.WORKER}, () => {}) - When I run cucumber-js with `--parallel 2`
- Then it passes
- And the global hook "
Before test run" has 2 executions - And the global hook "
After test run" has 2 executions
Scenario: global hooks run only on coordinator when specified
- Given a file named "
features/support/hooks.js" with:rubyconst {AfterAll, BeforeAll, HookTarget} = require('@cucumber/cucumber') BeforeAll({name: 'Before test run', on: HookTarget.COORDINATOR}, () => {}) AfterAll({name: 'After test run', on: HookTarget.COORDINATOR}, () => {}) - When I run cucumber-js with `--parallel 2`
- Then it passes
- And the global hook "
Before test run" has 1 executions - And the global hook "
After test run" has 1 executions
Source: features/before_after_all_hooks_parallel.feature at commit 3ac6ecda, Cucumber Js (MIT license).