Skip to content

Commit b4cf626

Browse files
authored
Reverse AfterAll execution order (#2456)
1 parent f0122a3 commit b4cf626

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Please see [CONTRIBUTING.md](./CONTRIBUTING.md) on how to contribute to Cucumber
1010
## [Unreleased]
1111
### Fixed
1212
- Correctly report error in publish plugin ([#2454](https://github.com/cucumber/cucumber-js/pull/2454))
13+
- Reverse AfterAll execution order ([#2456](https://github.com/cucumber/cucumber-js/pull/2456))
1314

1415
## [11.1.0] - 2024-11-17
1516
### Added

features/before_after_all_hooks.feature

+17-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ Feature: Environment Hooks
1515
"""
1616

1717
Scenario: before all / after all hooks
18+
19+
BeforeAll hooks run once each before any scenarios, in declaration order
20+
AfterAll hooks run once each after all scenarios, in reverse declaration order
21+
1822
Given a file named "features/support/hooks.js" with:
1923
"""
2024
const {AfterAll, BeforeAll, Given} = require('@cucumber/cucumber')
@@ -27,20 +31,30 @@ Feature: Environment Hooks
2731
counter += counter
2832
})
2933
30-
Given('first step', function() {
34+
BeforeAll(function() {
3135
expect(counter).to.eql(2)
3236
counter += counter
3337
})
3438
35-
Given('second step', function() {
39+
Given('first step', function() {
3640
expect(counter).to.eql(4)
3741
counter += counter
3842
})
3943
40-
AfterAll(function() {
44+
Given('second step', function() {
4145
expect(counter).to.eql(8)
4246
counter += counter
4347
})
48+
49+
AfterAll(function() {
50+
expect(counter).to.eql(32)
51+
counter += counter
52+
})
53+
54+
AfterAll(function() {
55+
expect(counter).to.eql(16)
56+
counter += counter
57+
})
4458
"""
4559
When I run cucumber-js
4660
Then it passes

package-lock.json

+5-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/runtime/worker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class Worker {
6464

6565
async runAfterAllHooks() {
6666
await this.runTestRunHooks(
67-
this.supportCodeLibrary.afterTestRunHookDefinitions,
67+
this.supportCodeLibrary.afterTestRunHookDefinitions.slice(0).reverse(),
6868
'an AfterAll'
6969
)
7070
}

0 commit comments

Comments
 (0)