Refine prepare-test-for-legacy-nodejs script (#17591)

This commit is contained in:
fisker Cheung authored and GitHub committed 2025-06-10 20:30:26 +08:00
1 parent d6845a30d5
commit 948a54bdbf
2 files changed
+19 -8

No files matched your search

+1 -1
View File
@@ -105,7 +105,7 @@ jobs:
- name: Downgrade Jest
if: ${{ matrix.node == '14' || matrix.node == '16' }}
run: node ./scripts/prepare-test-for-legacy-nodejs.js
run: node ./scripts/prepare-test-for-legacy-nodejs.js --node-version ${{ matrix.node }}
- name: Install Dependencies(yarn@3,mutable)
if: ${{ matrix.node == '14' || matrix.node == '16' }}
+18 -7
View File
@@ -1,15 +1,26 @@
import fs from "node:fs";
const nodejsMajorVersion = Number(process.versions.node.split(".")[0]);
const packageJsonFile = new URL("../package.json", import.meta.url);
const packageJson = JSON.parse(fs.readFileSync(packageJsonFile));
const jestVersion =
nodejsMajorVersion === 14
? // `jest@30.0.0-alpha.2` is the last version that supports Node.js v14
"30.0.0-alpha.2"
: // `jest@30.0.0-alpha.7` is the last version that supports Node.js v16
"30.0.0-alpha.7";
const argv = process.argv.slice(2);
const nodeVersion = Number(argv[1]);
if (argv[0] !== "--node-version" || !Number.isInteger(nodeVersion)) {
throw new Error("Expect `--node-version` argument.");
}
let jestVersion;
if (nodeVersion === 14) {
// `jest@30.0.0-alpha.2` is the last version that supports Node.js v14
jestVersion = "30.0.0-alpha.2";
} else if (nodeVersion === 16) {
// `jest@30.0.0-alpha.7` is the last version that supports Node.js v16
jestVersion = "30.0.0-alpha.7";
} else {
throw new Error("Unexpected `--node-version`.");
}
// Script to get dependencies
// console.log(