forked from NomicFoundation/hardhat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: separate out node warning check
Separate out the node version warning rule to its own function and add tests to cover the cases.
- Loading branch information
Showing
3 changed files
with
62 additions
and
3 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
16 changes: 16 additions & 0 deletions
16
packages/hardhat-core/src/internal/cli/is-node-version-to-warn-on.ts
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,16 @@ | ||
import semver from "semver"; | ||
|
||
import { SUPPORTED_NODE_VERSIONS } from "./constants"; | ||
|
||
/** | ||
* Determine if the node version is unsupported by Hardhat | ||
* and so a warning message should be shown. | ||
* | ||
* The current rule is that Hardhat supports all `Current`, | ||
* `Active LTS`, and `Maintenance LTS` versions of Node.js | ||
* as defined in the Node.js release schedule and encoded | ||
* in the `SUPPORTED_NODE_VERSIONS` constant. | ||
*/ | ||
export function isNodeVersionToWarnOn(nodeVersion: string): boolean { | ||
return !semver.satisfies(nodeVersion, SUPPORTED_NODE_VERSIONS.join(" || ")); | ||
} |
43 changes: 43 additions & 0 deletions
43
packages/hardhat-core/test/internal/cli/is-node-version-to-warn-on.ts
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,43 @@ | ||
import { assert } from "chai"; | ||
import { isNodeVersionToWarnOn } from "../../../src/internal/cli/is-node-version-to-warn-on"; | ||
|
||
describe("isNodeVersionToWarnOn", function () { | ||
it("Should not warn on supported versions", function () { | ||
assert.isFalse(isNodeVersionToWarnOn("v18.0.0")); | ||
assert.isFalse(isNodeVersionToWarnOn("v18.20.3")); | ||
|
||
assert.isFalse(isNodeVersionToWarnOn("v20.0.0")); | ||
assert.isFalse(isNodeVersionToWarnOn("v20.14.0")); | ||
|
||
assert.isFalse(isNodeVersionToWarnOn("v22.0.0")); | ||
assert.isFalse(isNodeVersionToWarnOn("v22.3.0")); | ||
}); | ||
|
||
it("Should warn on unsupported older node versions", function () { | ||
assert(isNodeVersionToWarnOn("v10.0.0")); | ||
assert(isNodeVersionToWarnOn("v10.24.1")); | ||
|
||
assert(isNodeVersionToWarnOn("v12.0.0")); | ||
assert(isNodeVersionToWarnOn("v12.22.12")); | ||
|
||
assert(isNodeVersionToWarnOn("v14.0.0")); | ||
assert(isNodeVersionToWarnOn("v14.21.3")); | ||
|
||
assert(isNodeVersionToWarnOn("v16.0.0")); | ||
assert(isNodeVersionToWarnOn("v16.20.20")); | ||
}); | ||
|
||
it("Should warn on unsupported newer versions", function () { | ||
assert(isNodeVersionToWarnOn("v24.0.0")); | ||
assert(isNodeVersionToWarnOn("v24.3.0")); | ||
}); | ||
|
||
it("Should warn on unsupported odd number releases", function () { | ||
assert(isNodeVersionToWarnOn("v15.14.0")); | ||
assert(isNodeVersionToWarnOn("v17.9.1")); | ||
assert(isNodeVersionToWarnOn("v19.9.0")); | ||
assert(isNodeVersionToWarnOn("v21.7.3")); | ||
assert(isNodeVersionToWarnOn("v23.0.0")); | ||
assert(isNodeVersionToWarnOn("v25.0.0")); | ||
}); | ||
}); |