-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Raise an error when the version of node is older than package.json's …
…engines.node (#1922) * Raise an error when the version of node is older than v12 * Update CHANGELOG * Move engine check to cli runner * Simplify * Extract to own file and add tests * Read minimum version from package.json * Make semver a production dependency
- Loading branch information
Showing
6 changed files
with
58 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
import semver from 'semver' | ||
|
||
type PackageJSON = { | ||
engines: { node: string } | ||
} | ||
|
||
const readActualPackageJSON: () => PackageJSON = () => | ||
JSON.parse( | ||
fs | ||
.readFileSync(path.resolve(__dirname, '..', '..', 'package.json')) | ||
.toString() | ||
) | ||
|
||
export function assertNodeEngineVersion( | ||
currentVersion: string, | ||
readPackageJSON: () => PackageJSON = readActualPackageJSON | ||
): void { | ||
const requiredVersion = readPackageJSON().engines.node | ||
if (!semver.satisfies(currentVersion, requiredVersion)) { | ||
const message = `Cucumber can only run on Node.js versions ${requiredVersion}. This Node.js version is ${currentVersion}` | ||
throw new Error(message) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import assert from 'assert' | ||
import { assertNodeEngineVersion } from './assert_node_engine_version' | ||
|
||
describe(assertNodeEngineVersion.name, () => { | ||
it('fails when the version is lower than specified in package.json', () => { | ||
assert.throws(() => | ||
assertNodeEngineVersion('v11.0.0', () => ({ | ||
engines: { | ||
node: '>=12', | ||
}, | ||
})) | ||
) | ||
}) | ||
|
||
it('passes when the version is greater than specified in package.json', () => { | ||
assertNodeEngineVersion('v17.0.0') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters