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

Support Node.js 23 #2446

Merged
merged 4 commits into from
Nov 16, 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
6 changes: 3 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- ubuntu-latest
- windows-latest
# these versions must be kept in sync with enginesTested.node in package.json
node-version: [18.x, 20.x, 22.6]
node-version: [18.x, 20.x, 22.x, 23.x]
fail-fast: false

steps:
Expand All @@ -37,7 +37,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 22.6
node-version: 22.x
- run: npm install
- run: npm run test-coverage
- uses: coverallsapp/github-action@master
Expand All @@ -54,5 +54,5 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 22.6
node-version: 22.x
- run: npm audit --groups dependencies --audit-level high
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
Please see [CONTRIBUTING.md](./CONTRIBUTING.md) on how to contribute to Cucumber.

## [Unreleased]
### Added
- Add support for Node.js 23 ([#2446](https://github.com/cucumber/cucumber-js/pull/2446))

### Changed
- Replace JUnit formatter with messages-based package ([#2445](https://github.com/cucumber/cucumber-js/pull/2445))

Expand Down
23 changes: 23 additions & 0 deletions features/esm.feature
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Feature: ES modules support
Then it runs 2 scenarios
And it passes

@without-require-esm
Scenario: ES module invoked with --require
Given a file named "features/a.feature" with:
"""
Expand All @@ -102,3 +103,25 @@ Feature: ES modules support
"""
Error: Cucumber expected a CommonJS module
"""

Scenario: ES module with top-level await invoked with --require
Given a file named "features/a.feature" with:
"""
Feature:
Scenario: one
Given a step passes
"""
And a file named "features/step_definitions/cucumber_steps.js" with:
"""
import {Given} from '@cucumber/cucumber'

await Promise.resolve()

Given(/^a step passes$/, function() {});
"""
When I run cucumber-js with `--require features/**/*.js`
Then it fails
And the error output contains the text:
"""
Error: Cucumber expected a CommonJS module
"""
8 changes: 8 additions & 0 deletions features/support/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ Before('@esm', function (this: World) {
})
})

Before('@without-require-esm', function (this: World) {
// @ts-expect-error require_module flag not in @types/node yet
if (process.features.require_module) {
return 'skipped'
}
return undefined
})

After(async function (this: World) {
if (this.reportServer?.started) {
await this.reportServer.stop()
Expand Down
5 changes: 3 additions & 2 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@
},
"types": "./lib/index.d.ts",
"engines": {
"node": "18 || 20 || >=22"
"node": "18 || 20 || 22 || >=23"
},
"enginesTested": {
"node": "18 || 20 || 22"
"node": "18 || 20 || 22 || 23"
},
"dependencies": {
"@cucumber/ci-environment": "10.0.1",
Expand Down
6 changes: 6 additions & 0 deletions src/try_require.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ export default function tryRequire(path: string) {
Either change the file to CommonJS syntax or use the --import directive instead of --require.`,
{ cause: error }
)
} else if (error.code === 'ERR_REQUIRE_ASYNC_MODULE') {
throw Error(
`Cucumber expected a CommonJS module or simple ES module at '${path}' but found an async ES module.
Either change the file so it can be required or use the --import directive instead of --require.`,
{ cause: error }
)
} else {
throw error
}
Expand Down
Loading