Skip to content

Commit 7dd8228

Browse files
jbedardclydin
authored andcommitted
test: do not depend on a global npm binary
1 parent f5e6259 commit 7dd8228

File tree

7 files changed

+564
-31
lines changed

7 files changed

+564
-31
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@
174174
"minimatch": "5.1.0",
175175
"ng-packagr": "14.0.0",
176176
"node-fetch": "^2.2.0",
177+
"npm": "^8.11.0",
177178
"npm-package-arg": "9.0.2",
178179
"open": "8.4.0",
179180
"ora": "5.4.1",

tests/legacy-cli/e2e/setup/010-local-publish.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { getGlobalVariable } from '../utils/env';
2-
import { execWithEnv, extractNpmEnv } from '../utils/process';
2+
import { globalNpm, extractNpmEnv } from '../utils/process';
33
import { isPrereleaseCli } from '../utils/project';
44

55
export default async function () {
66
const testRegistry: string = getGlobalVariable('package-registry');
7-
await execWithEnv(
8-
'npm',
7+
await globalNpm(
98
[
109
'run',
1110
'admin',

tests/legacy-cli/e2e/setup/100-global-cli.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getGlobalVariable } from '../utils/env';
2-
import { silentNpm } from '../utils/process';
2+
import { globalNpm } from '../utils/process';
33

44
const NPM_VERSION = '7.24.0';
55
const YARN_VERSION = '1.22.18';
@@ -13,12 +13,12 @@ export default async function () {
1313
const testRegistry: string = getGlobalVariable('package-registry');
1414

1515
// Install global Angular CLI being tested, npm+yarn used by e2e tests.
16-
await silentNpm(
16+
await globalNpm([
1717
'install',
1818
'--global',
1919
`--registry=${testRegistry}`,
2020
'@angular/cli',
2121
`npm@${NPM_VERSION}`,
2222
`yarn@${YARN_VERSION}`,
23-
);
23+
]);
2424
}

tests/legacy-cli/e2e/utils/BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ts_library(
1414
"@npm//@types/yargs-parser",
1515
"@npm//ansi-colors",
1616
"@npm//glob",
17+
"@npm//npm",
1718
"@npm//protractor",
1819
"@npm//puppeteer",
1920
"@npm//rxjs",

tests/legacy-cli/e2e/utils/process.ts

+10
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,16 @@ export function silentYarn(...args: string[]) {
322322
return _exec({ silent: true }, 'yarn', args);
323323
}
324324

325+
export function globalNpm(args: string[], env?: NodeJS.ProcessEnv) {
326+
if (!process.env.LEGACY_CLI_RUNNER) {
327+
throw new Error(
328+
'The global npm cli should only be executed from the primary e2e runner process',
329+
);
330+
}
331+
332+
return _exec({ silent: true, env }, 'node', [require.resolve('npm'), ...args]);
333+
}
334+
325335
export function npm(...args: string[]) {
326336
return _exec({}, 'npm', args);
327337
}

tests/legacy-cli/e2e_runner.ts

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ const argv = yargsParser(process.argv.slice(2), {
5555
*/
5656
process.exitCode = 255;
5757

58+
/**
59+
* Mark this process as the main e2e_runner
60+
*/
61+
process.env.LEGACY_CLI_RUNNER = '1';
62+
5863
const logger = createConsoleLogger(argv.verbose, process.stdout, process.stderr, {
5964
info: (s) => s,
6065
debug: (s) => s,

0 commit comments

Comments
 (0)