Skip to content

Commit 97adcfe

Browse files
committed
test: ensure npm 7 E2E test reset global version back to the actual initial version
The `misc/npm-7` E2E test previously assumed the initial version of npm was 6.x and would then always install 6.x after the test was complete. With newer Node.js versions this assumption is no longer true. The test now records the initial version present prior to starting the test and restores that recorded version at completion.
1 parent dfff175 commit 97adcfe

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

tests/legacy-cli/e2e/tests/misc/npm-7.ts

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import * as assert from 'assert';
2+
import { execSync } from 'child_process';
3+
import { valid as validSemVer } from 'semver';
14
import { rimraf } from '../../utils/fs';
25
import { getActivePackageManager } from '../../utils/packages';
36
import { ng, npm } from '../../utils/process';
@@ -17,6 +20,23 @@ export default async function () {
1720
return;
1821
}
1922

23+
// Get current package manager version to restore after tests
24+
const initialVersionText = execSync('npm --version', {
25+
encoding: 'utf8',
26+
stdio: ['ignore', 'pipe', 'ignore'],
27+
env: {
28+
...process.env,
29+
// NPM updater notifier will prevent the child process from closing until it timeouts after 3 minutes.
30+
NO_UPDATE_NOTIFIER: '1',
31+
NPM_CONFIG_UPDATE_NOTIFIER: 'false',
32+
},
33+
}).trim();
34+
const initialVersion = validSemVer(initialVersionText);
35+
assert.ok(
36+
initialVersion,
37+
`Invalid npm version string returned from "npm --version" [${initialVersionText}]`,
38+
);
39+
2040
const currentDirectory = process.cwd();
2141

2242
const extraArgs = [];
@@ -89,7 +109,7 @@ export default async function () {
89109
// Change directory back
90110
process.chdir(currentDirectory);
91111

92-
// Reset version back to 6.x
93-
await npm('install', '--global', 'npm@6');
112+
// Reset version back to initial version
113+
await npm('install', '--global', `npm@${initialVersion}`);
94114
}
95115
}

0 commit comments

Comments
 (0)