Skip to content

Commit da5f8b5

Browse files
committed
test(@angular/cli): centralize E2E test registry configuration
E2E test registry configuration to ensure that package managers use the test registry during tests is now moved out of the tests and into the setup phase. (cherry picked from commit 32a0173)
1 parent 475d920 commit da5f8b5

File tree

14 files changed

+52
-29
lines changed

14 files changed

+52
-29
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import { prerelease } from 'semver';
22
import { packages } from '../../../../lib/packages';
3+
import { getGlobalVariable } from '../utils/env';
34
import { npm } from '../utils/process';
45

56
export default async function() {
7+
const testRegistry = getGlobalVariable('package-registry');
68
const publishArgs = [
79
'run',
810
'admin',
911
'--',
1012
'publish',
1113
'--no-versionCheck',
1214
'--no-branchCheck',
13-
'--registry=http://localhost:4873',
15+
`--registry=${testRegistry}`,
1416
];
1517

1618
const pre = prerelease(packages['@angular/cli'].version);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ export default async function() {
77
return;
88
}
99

10+
const testRegistry = getGlobalVariable('package-registry');
11+
1012
// Install global Angular CLI.
1113
await silentNpm(
1214
'install',
1315
'--global',
1416
'@angular/cli',
15-
'--registry=http://localhost:4873',
17+
`--registry=${testRegistry}`,
1618
);
1719

1820
try {

tests/legacy-cli/e2e/setup/500-create-project.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { join } from 'path';
22
import { getGlobalVariable } from '../utils/env';
3-
import { expectFileToExist } from '../utils/fs';
3+
import { expectFileToExist, writeFile } from '../utils/fs';
44
import { gitClean } from '../utils/git';
5-
import { ng } from '../utils/process';
5+
import { ng, npm } from '../utils/process';
66
import { prepareProjectForE2e, updateJsonFile } from '../utils/project';
77

88
export default async function() {
@@ -17,11 +17,29 @@ export default async function() {
1717
await gitClean();
1818
} else {
1919
const extraArgs = [];
20+
const testRegistry = getGlobalVariable('package-registry');
21+
const isCI = getGlobalVariable('ci');
22+
23+
// Ensure local test registry is used when outside a project
24+
if (isCI) {
25+
// Safe to set a user configuration on CI
26+
await npm('config', 'set', 'registry', testRegistry);
27+
} else {
28+
// Yarn does not use the environment variable so an .npmrc file is also required
29+
await writeFile('.npmrc', `registry=${testRegistry}`);
30+
process.env['NPM_CONFIG_REGISTRY'] = testRegistry;
31+
}
2032

2133
await ng('new', 'test-project', '--skip-install', ...extraArgs);
2234
await expectFileToExist(join(process.cwd(), 'test-project'));
2335
process.chdir('./test-project');
2436

37+
// If on CI, the user configuration set above will handle project usage
38+
if (!isCI) {
39+
// Ensure local test registry is used inside a project
40+
await writeFile('.npmrc', `registry=${testRegistry}`);
41+
}
42+
2543
if (argv['ve']) {
2644
await updateJsonFile('tsconfig.json', config => {
2745
const { angularCompilerOptions = {} } = config;
Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
1-
import { expectFileToExist, rimraf, writeMultipleFiles } from '../../../utils/fs';
1+
import { getGlobalVariable } from '../../../utils/env';
2+
import { expectFileToExist, writeMultipleFiles } from '../../../utils/fs';
23
import { ng } from '../../../utils/process';
34
import { expectToFail } from '../../../utils/utils';
45

56
export default async function () {
6-
// forcibly remove in case another test doesn't clean itself up
7-
await rimraf('node_modules/@angular/material');
7+
const testRegistry = getGlobalVariable('package-registry');
88

99
// Setup an invalid registry
1010
await writeMultipleFiles({
1111
'.npmrc': 'registry=http://127.0.0.1:9999',
1212
});
13+
// The environment variable has priority over the .npmrc
14+
const originalRegistryVariable = process.env['NPM_CONFIG_REGISTRY'];
15+
process.env['NPM_CONFIG_REGISTRY'] = undefined;
1316

14-
await expectToFail(() => ng('add', '@angular/pwa'));
17+
try {
18+
await expectToFail(() => ng('add', '@angular/pwa'));
1519

16-
await ng('add', '--registry=http://localhost:4873', '@angular/pwa');
17-
await expectFileToExist('src/manifest.webmanifest');
20+
await ng('add', `--registry=${testRegistry}`, '@angular/pwa');
21+
await expectFileToExist('src/manifest.webmanifest');
22+
} finally {
23+
process.env['NPM_CONFIG_REGISTRY'] = originalRegistryVariable;
24+
}
1825
}

tests/legacy-cli/e2e/tests/misc/ask-analytics-install.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default async function() {
1515
// Install the CLI with TTY force enabled
1616
const execution = execWithEnv(
1717
'npm',
18-
['install', '@angular/cli', '--registry=http://localhost:4873'],
18+
['install', '@angular/cli'],
1919
{ ...process.env, 'NG_FORCE_TTY': '1' },
2020
);
2121

tests/legacy-cli/e2e/tests/misc/invalid-schematic-dependencies.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ export default async function () {
1111
'@schematics/angular@7',
1212
'--registry=https://registry.npmjs.org',
1313
);
14-
await silentNpm('publish', stdoutPack1.trim(), '--registry=http://localhost:4873', '--tag=outdated');
14+
await silentNpm('publish', stdoutPack1.trim(), '--tag=outdated');
1515
const { stdout: stdoutPack2 } = await silentNpm(
1616
'pack',
1717
'@angular-devkit/core@7',
1818
'--registry=https://registry.npmjs.org',
1919
);
20-
await silentNpm('publish', stdoutPack2.trim(), '--registry=http://localhost:4873', '--tag=outdated');
20+
await silentNpm('publish', stdoutPack2.trim(), '--tag=outdated');
2121
const { stdout: stdoutPack3 } = await silentNpm(
2222
'pack',
2323
'@angular-devkit/schematics@7',
2424
'--registry=https://registry.npmjs.org',
2525
);
26-
await silentNpm('publish', stdoutPack3.trim(), '--registry=http://localhost:4873', '--tag=outdated');
26+
await silentNpm('publish', stdoutPack3.trim(), '--tag=outdated');
2727

2828
// Install outdated and incompatible version
2929
await installPackage('@schematics/angular@7');

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ export default async function() {
7070

7171
// Ensure `ng new --package-manager=yarn` executes successfully
7272
// Need an additional npmrc file since yarn does not use the NPM registry environment variable
73-
await writeFile('.npmrc', 'registry=http://localhost:4873')
7473
const { stderr: stderrNewYarn } = await ng('new', 'npm-seven-yarn', '--package-manager=yarn');
7574
if (stderrNewYarn.includes(warningText)) {
7675
throw new Error('ng new --package-manager=yarn expected to not show npm version warning.');
@@ -79,7 +78,6 @@ export default async function() {
7978
// Cleanup extra test projects
8079
await rimraf('npm-seven-skip');
8180
await rimraf('npm-seven-yarn');
82-
await rimraf('.npmrc');
8381

8482
// Change directory back
8583
process.chdir(currentDirectory);

tests/legacy-cli/e2e/tests/misc/webpack-5.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getGlobalVariable } from '../../utils/env';
12
import { rimraf } from '../../utils/fs';
23
import { killAllProcesses, ng, silentYarn } from '../../utils/process';
34
import { ngServe, updateJsonFile } from '../../utils/project';
@@ -8,7 +9,8 @@ export default async function() {
89
await updateJsonFile('package.json', (json) => {
910
json.resolutions = { webpack: '5.1.3' };
1011
});
11-
await silentYarn();
12+
const testRegistry = getGlobalVariable('package-registry');
13+
await silentYarn(`--registry=${testRegistry}`);
1214

1315
// Ensure webpack 5 is used
1416
const { stdout } = await silentYarn('list', '--pattern', 'webpack');

tests/legacy-cli/e2e/tests/schematics_cli/basic.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@ export default async function () {
1010
return;
1111
}
1212

13-
process.env['NPM_CONFIG_REGISTRY'] = 'http://localhost:4873';
14-
1513
await silentNpm(
1614
'install',
1715
'-g',
1816
'@angular-devkit/schematics-cli',
19-
'--registry=http://localhost:4873',
2017
);
2118
await exec(process.platform.startsWith('win') ? 'where' : 'which', 'schematics');
2219

tests/legacy-cli/e2e/tests/schematics_cli/blank-test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@ export default async function () {
1111
return;
1212
}
1313

14-
process.env['NPM_CONFIG_REGISTRY'] = 'http://localhost:4873';
15-
1614
await silentNpm(
1715
'install',
1816
'-g',
1917
'@angular-devkit/schematics-cli',
20-
'--registry=http://localhost:4873',
2118
);
2219
await exec(process.platform.startsWith('win') ? 'where' : 'which', 'schematics');
2320

0 commit comments

Comments
 (0)