Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverse AfterAll execution order #2456

Merged
merged 4 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Please see [CONTRIBUTING.md](./CONTRIBUTING.md) on how to contribute to Cucumber
## [Unreleased]
### Fixed
- Correctly report error in publish plugin ([#2454](https://github.com/cucumber/cucumber-js/pull/2454))
- Reverse AfterAll execution order ([#2456](https://github.com/cucumber/cucumber-js/pull/2456))

## [11.1.0] - 2024-11-17
### Added
Expand Down
20 changes: 17 additions & 3 deletions features/before_after_all_hooks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Feature: Environment Hooks
"""

Scenario: before all / after all hooks

BeforeAll hooks run once each before any scenarios, in declaration order
AfterAll hooks run once each after all scenarios, in reverse declaration order

Given a file named "features/support/hooks.js" with:
"""
const {AfterAll, BeforeAll, Given} = require('@cucumber/cucumber')
Expand All @@ -27,20 +31,30 @@ Feature: Environment Hooks
counter += counter
})

Given('first step', function() {
BeforeAll(function() {
expect(counter).to.eql(2)
counter += counter
})

Given('second step', function() {
Given('first step', function() {
expect(counter).to.eql(4)
counter += counter
})

AfterAll(function() {
Given('second step', function() {
expect(counter).to.eql(8)
counter += counter
})

AfterAll(function() {
expect(counter).to.eql(32)
counter += counter
})

AfterAll(function() {
expect(counter).to.eql(16)
counter += counter
})
"""
When I run cucumber-js
Then it passes
Expand Down
9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/runtime/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class Worker {

async runAfterAllHooks() {
await this.runTestRunHooks(
this.supportCodeLibrary.afterTestRunHookDefinitions,
this.supportCodeLibrary.afterTestRunHookDefinitions.slice(0).reverse(),
'an AfterAll'
)
}
Expand Down
Loading