From 7ce365e8b3c3f72a500b36ccdd7f4447aa04858e Mon Sep 17 00:00:00 2001 From: David Goss Date: Mon, 21 Mar 2022 09:33:43 +0000 Subject: [PATCH 1/3] warn if node version not tested --- package.json | 3 ++ src/cli/run.ts | 12 ++++-- src/cli/validate_node_engine_version.ts | 13 ++++-- src/cli/validate_node_engine_version_spec.ts | 45 +++++++++++--------- 4 files changed, 45 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index 79686baa6..ecd9113eb 100644 --- a/package.json +++ b/package.json @@ -188,6 +188,9 @@ "engines": { "node": "12 || 14 || >=16" }, + "enginesTested": { + "node": "12 || 14 || 16 || 17" + }, "dependencies": { "@cspotcode/source-map-support": "^0.7.0", "@cucumber/ci-environment": "9.0.0", diff --git a/src/cli/run.ts b/src/cli/run.ts index eff95a6ea..99c02b0bf 100644 --- a/src/cli/run.ts +++ b/src/cli/run.ts @@ -16,10 +16,14 @@ function displayPublishAdvertisementBanner(): void { } export default async function run(): Promise { - validateNodeEngineVersion(process.version, (error) => { - console.error(error) - process.exit(1) - }) + validateNodeEngineVersion( + process.version, + (error) => { + console.error(error) + process.exit(1) + }, + console.warn + ) const cli = new Cli({ argv: process.argv, diff --git a/src/cli/validate_node_engine_version.ts b/src/cli/validate_node_engine_version.ts index 664d8b524..e52fa7196 100644 --- a/src/cli/validate_node_engine_version.ts +++ b/src/cli/validate_node_engine_version.ts @@ -4,6 +4,7 @@ import semver from 'semver' type PackageJSON = { engines: { node: string } + enginesTested: { node: string } } const readActualPackageJSON: () => PackageJSON = () => @@ -16,12 +17,18 @@ const readActualPackageJSON: () => PackageJSON = () => export function validateNodeEngineVersion( currentVersion: string, onError: (message: string) => void, + onWarning: (message: string) => void, readPackageJSON: () => PackageJSON = readActualPackageJSON ): void { - const requiredVersion = readPackageJSON().engines.node - if (!semver.satisfies(currentVersion, requiredVersion)) { + const requiredVersions = readPackageJSON().engines.node + const testedVersions = readPackageJSON().enginesTested.node + if (!semver.satisfies(currentVersion, requiredVersions)) { onError( - `Cucumber can only run on Node.js versions ${requiredVersion}. This Node.js version is ${currentVersion}` + `Cucumber can only run on Node.js versions ${requiredVersions}. This Node.js version is ${currentVersion}` + ) + } else if (!semver.satisfies(currentVersion, testedVersions)) { + onWarning( + `This Node.js version (${currentVersion}) has not been tested with this version of Cucumber; it should work normally, but please raise an issue if you see anything unexpected.` ) } } diff --git a/src/cli/validate_node_engine_version_spec.ts b/src/cli/validate_node_engine_version_spec.ts index 2ea2d1334..cdf0852ec 100644 --- a/src/cli/validate_node_engine_version_spec.ts +++ b/src/cli/validate_node_engine_version_spec.ts @@ -3,66 +3,69 @@ import * as sinon from 'sinon' import { validateNodeEngineVersion } from './validate_node_engine_version' describe(validateNodeEngineVersion.name, () => { + const readPackageJSON = () => ({ + engines: { + node: '12 || 14 || >=16', + }, + enginesTested: { + node: '12 || 14 || 16 || 17', + }, + }) + it('calls the onError callback when the version is lower than any of our supported versions', () => { // Arrange const errorSpy = sinon.spy() + const warningSpy = sinon.spy() // Act - validateNodeEngineVersion('v11.1.2', errorSpy, () => ({ - engines: { - node: '12 || 14 || >=16', - }, - })) + validateNodeEngineVersion('v11.1.2', errorSpy, warningSpy, readPackageJSON) // Assert expect(errorSpy).to.have.been.calledOnceWith( 'Cucumber can only run on Node.js versions 12 || 14 || >=16. This Node.js version is v11.1.2' ) + expect(warningSpy).not.to.have.been.called() }) it('calls the onError callback when the version is between our supported versions', () => { // Arrange const errorSpy = sinon.spy() + const warningSpy = sinon.spy() - validateNodeEngineVersion('v13.1.2', errorSpy, () => ({ - engines: { - node: '12 || 14 || >=16', - }, - })) + validateNodeEngineVersion('v13.1.2', errorSpy, warningSpy, readPackageJSON) // Assert expect(errorSpy).to.have.been.calledOnceWith( 'Cucumber can only run on Node.js versions 12 || 14 || >=16. This Node.js version is v13.1.2' ) + expect(warningSpy).not.to.have.been.called() }) - it('does not call the onError when the version is one of our supported versions', () => { + it('does not call onError or onWarning when the version is one of our supported versions', () => { // Arrange const errorSpy = sinon.spy() + const warningSpy = sinon.spy() // Act - validateNodeEngineVersion('v17.1.2', errorSpy, () => ({ - engines: { - node: '12 || 14 || >=16', - }, - })) + validateNodeEngineVersion('v17.1.2', errorSpy, warningSpy, readPackageJSON) // Assert expect(errorSpy).not.to.have.been.called() + expect(warningSpy).not.to.have.been.called() }) it('does not call onError when the version is a version that isnt out yet at time of release', () => { // Arrange const errorSpy = sinon.spy() + const warningSpy = sinon.spy() // Act - validateNodeEngineVersion('v18.0.0', errorSpy, () => ({ - engines: { - node: '12 || 14 || >=16', - }, - })) + validateNodeEngineVersion('v18.0.0', errorSpy, warningSpy, readPackageJSON) // Assert expect(errorSpy).not.to.have.been.called() + expect(warningSpy).to.have.been.calledOnceWith( + `This Node.js version (v18.0.0) has not been tested with this version of Cucumber; it should work normally, but please raise an issue if you see anything unexpected.` + ) }) }) From 0f57f0bc7ebdd6aa409efdde12248b764817a716 Mon Sep 17 00:00:00 2001 From: David Goss Date: Mon, 21 Mar 2022 09:34:34 +0000 Subject: [PATCH 2/3] add note to workflows file --- .github/workflows/build.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 579add4be..5cfc4fe4d 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -19,6 +19,7 @@ jobs: os: - ubuntu-latest - windows-latest + # these versions must be kept in sync with enginesTested.node in package.json node-version: [12.x, 14.x, 16.x, 17.x] fail-fast: false From d6bccc0ee504fb3ec96770d31bcc224d39ad6326 Mon Sep 17 00:00:00 2001 From: David Goss Date: Fri, 25 Mar 2022 09:19:37 +0000 Subject: [PATCH 3/3] update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a858920c..b00ba49cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CO ### Fixed - Allow `file://` URLs to be used as formatter/snippet paths in options ([#1963](https://github.com/cucumber/cucumber-js/pull/1963) [#1920](https://github.com/cucumber/cucumber-js/issues/1920)) +### Changed +- Emit a warning when using a Node.js version that's untested with Cucumber ([#1959](https://github.com/cucumber/cucumber-js/pull/1959)) + ## [8.0.0-rc.3] - 2022-03-21 ### Added - Cucumber Expressions now support a wider array of parameter types (see [documentation](https://github.com/cucumber/cucumber-expressions#parameter-types))