Skip to content

Commit 1c4d9c5

Browse files
authored
Support Node.js 23 (#2446)
1 parent 03a57a5 commit 1c4d9c5

File tree

7 files changed

+48
-7
lines changed

7 files changed

+48
-7
lines changed

.github/workflows/build.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- ubuntu-latest
2121
- windows-latest
2222
# these versions must be kept in sync with enginesTested.node in package.json
23-
node-version: [18.x, 20.x, 22.6]
23+
node-version: [18.x, 20.x, 22.x, 23.x]
2424
fail-fast: false
2525

2626
steps:
@@ -37,7 +37,7 @@ jobs:
3737
- uses: actions/checkout@v3
3838
- uses: actions/setup-node@v3
3939
with:
40-
node-version: 22.6
40+
node-version: 22.x
4141
- run: npm install
4242
- run: npm run test-coverage
4343
- uses: coverallsapp/github-action@master
@@ -54,5 +54,5 @@ jobs:
5454
- uses: actions/checkout@v3
5555
- uses: actions/setup-node@v3
5656
with:
57-
node-version: 22.6
57+
node-version: 22.x
5858
- run: npm audit --groups dependencies --audit-level high

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
Please see [CONTRIBUTING.md](./CONTRIBUTING.md) on how to contribute to Cucumber.
99

1010
## [Unreleased]
11+
### Added
12+
- Add support for Node.js 23 ([#2446](https://github.com/cucumber/cucumber-js/pull/2446))
13+
1114
### Changed
1215
- Replace JUnit formatter with messages-based package ([#2445](https://github.com/cucumber/cucumber-js/pull/2445))
1316

features/esm.feature

+23
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ Feature: ES modules support
8383
Then it runs 2 scenarios
8484
And it passes
8585

86+
@without-require-esm
8687
Scenario: ES module invoked with --require
8788
Given a file named "features/a.feature" with:
8889
"""
@@ -102,3 +103,25 @@ Feature: ES modules support
102103
"""
103104
Error: Cucumber expected a CommonJS module
104105
"""
106+
107+
Scenario: ES module with top-level await invoked with --require
108+
Given a file named "features/a.feature" with:
109+
"""
110+
Feature:
111+
Scenario: one
112+
Given a step passes
113+
"""
114+
And a file named "features/step_definitions/cucumber_steps.js" with:
115+
"""
116+
import {Given} from '@cucumber/cucumber'
117+
118+
await Promise.resolve()
119+
120+
Given(/^a step passes$/, function() {});
121+
"""
122+
When I run cucumber-js with `--require features/**/*.js`
123+
Then it fails
124+
And the error output contains the text:
125+
"""
126+
Error: Cucumber expected a CommonJS module
127+
"""

features/support/hooks.ts

+8
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ Before('@esm', function (this: World) {
5252
})
5353
})
5454

55+
Before('@without-require-esm', function (this: World) {
56+
// @ts-expect-error require_module flag not in @types/node yet
57+
if (process.features.require_module) {
58+
return 'skipped'
59+
}
60+
return undefined
61+
})
62+
5563
After(async function (this: World) {
5664
if (this.reportServer?.started) {
5765
await this.reportServer.stop()

package-lock.json

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

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,10 @@
208208
},
209209
"types": "./lib/index.d.ts",
210210
"engines": {
211-
"node": "18 || 20 || >=22"
211+
"node": "18 || 20 || 22 || >=23"
212212
},
213213
"enginesTested": {
214-
"node": "18 || 20 || 22"
214+
"node": "18 || 20 || 22 || 23"
215215
},
216216
"dependencies": {
217217
"@cucumber/ci-environment": "10.0.1",

src/try_require.ts

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ export default function tryRequire(path: string) {
1414
Either change the file to CommonJS syntax or use the --import directive instead of --require.`,
1515
{ cause: error }
1616
)
17+
} else if (error.code === 'ERR_REQUIRE_ASYNC_MODULE') {
18+
throw Error(
19+
`Cucumber expected a CommonJS module or simple ES module at '${path}' but found an async ES module.
20+
Either change the file so it can be required or use the --import directive instead of --require.`,
21+
{ cause: error }
22+
)
1723
} else {
1824
throw error
1925
}

0 commit comments

Comments
 (0)