Skip to content

Commit d002bb7

Browse files
alan-agius4clydin
authored andcommitted
test(@angular/cli): several fixes to update-8 E2E test
Previously in `update-8` test we used the Angular CLI in node_modules which caused incorrect result. We now don't run `ng update @angular/core --next` or `ng update @angular/core`. This is due to our bumping strategy, which causes a period were `@angular/cli@latest` (v12.0.0) `@angular/core@latest` (v11.2.x) are of different major/minor version on the local NPM server. This causes `ng update` to fail. NB: `ng update @angula/cli` will still cause `@angular/core` packages to be updated. (cherry picked from commit 6d5043b)
1 parent 1031557 commit d002bb7

File tree

4 files changed

+62
-35
lines changed

4 files changed

+62
-35
lines changed
Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
1-
import { prerelease } from 'semver';
2-
import { packages } from '../../../../lib/packages';
31
import { getGlobalVariable } from '../utils/env';
42
import { npm } from '../utils/process';
3+
import { isPrereleaseCli } from '../utils/project';
54

6-
export default async function() {
5+
export default async function () {
76
const testRegistry = getGlobalVariable('package-registry');
8-
const publishArgs = [
7+
await npm(
98
'run',
109
'admin',
1110
'--',
1211
'publish',
1312
'--no-versionCheck',
1413
'--no-branchCheck',
1514
`--registry=${testRegistry}`,
16-
];
17-
18-
const pre = prerelease(packages['@angular/cli'].version);
19-
if (pre && pre.length > 0) {
20-
publishArgs.push('--tag', 'next');
21-
} else {
22-
publishArgs.push('--tag', 'latest');
23-
}
24-
25-
await npm(...publishArgs);
15+
'--tag',
16+
isPrereleaseCli() ? 'next' : 'latest',
17+
);
2618
}

tests/legacy-cli/e2e/tests/update/update-8.ts

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,43 @@
11
import { createProjectFromAsset } from '../../utils/assets';
22
import { expectFileMatchToExist } from '../../utils/fs';
3-
import { installWorkspacePackages } from '../../utils/packages';
4-
import { ng, noSilentNg, silentNpm } from '../../utils/process';
5-
import { isPrereleaseCli, useBuiltPackages, useCIChrome, useCIDefaults } from '../../utils/project';
3+
import { installPackage, installWorkspacePackages, setRegistry } from '../../utils/packages';
4+
import { ng, noSilentNg } from '../../utils/process';
5+
import { isPrereleaseCli, useCIChrome, useCIDefaults } from '../../utils/project';
66

7-
export default async function() {
8-
await createProjectFromAsset('8.0-project');
9-
await ng('update', '@angular/cli', '--migrate-only', '--from=8');
7+
export default async function () {
8+
// We need to use the public registry because in the local NPM server we don't have
9+
// older versions @angular/cli packages which would cause `npm install` during `ng update` to fail.
10+
try {
11+
await createProjectFromAsset('8.0-project', true, true);
1012

11-
// Use the packages we are building in this commit, and CI Chrome.
12-
await useBuiltPackages();
13+
await setRegistry(false);
14+
await installWorkspacePackages();
15+
16+
// Update Angular to 9
17+
await installPackage('@angular/cli@8');
18+
const { stdout } = await ng('update', '@angular/[email protected]', '@angular/[email protected]');
19+
if (!stdout.includes("Executing migrations of package '@angular/cli'")) {
20+
throw new Error('Update did not execute migrations. OUTPUT: \n' + stdout);
21+
}
22+
23+
// Update Angular to 10
24+
await ng('update', '@angular/cli@10', '@angular/core@10');
25+
} finally {
26+
await setRegistry(true);
27+
}
28+
29+
// Update Angular current build
30+
const extraUpdateArgs = isPrereleaseCli() ? ['--next', '--force'] : ['--force'];
31+
// For the latest/next release we purposely don't add `@angular/core`.
32+
// This is due to our bumping strategy, which causes a period were `@angular/cli@latest` (v12.0.0) `@angular/core@latest` (v11.2.x)
33+
// are of different major/minor version on the local NPM server. This causes `ng update` to fail.
34+
// NB: `ng update @angula/cli` will still cause `@angular/core` packages to be updated.
35+
await ng('update', '@angular/cli', ...extraUpdateArgs);
36+
37+
// Setup testing to use CI Chrome.
1338
await useCIChrome('./');
1439
await useCIChrome('./e2e/');
1540
await useCIDefaults('eight-project');
16-
await installWorkspacePackages();
17-
18-
// Update Angular.
19-
const extraUpdateArgs = await isPrereleaseCli() ? ['--next', '--force'] : [];
20-
await ng('update', '@angular/core', ...extraUpdateArgs);
2141

2242
// Run CLI commands.
2343
await ng('generate', 'component', 'my-comp');

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { getGlobalVariable } from './env';
2-
import { ProcessOutput, silentNpm, silentYarn } from './process';
2+
import { writeFile } from './fs';
3+
import { npm, ProcessOutput, silentNpm, silentYarn } from './process';
34

45
export function getActivePackageManager(): 'npm' | 'yarn' {
56
const value = getGlobalVariable('package-manager');
@@ -39,3 +40,21 @@ export async function uninstallPackage(name: string): Promise<ProcessOutput> {
3940
return silentYarn('remove', name);
4041
}
4142
}
43+
44+
export async function setRegistry(useTestRegistry: boolean): Promise<void> {
45+
const url = useTestRegistry
46+
? getGlobalVariable('package-registry')
47+
: 'https://registry.npmjs.org';
48+
49+
const isCI = getGlobalVariable('ci');
50+
51+
// Ensure local test registry is used when outside a project
52+
if (isCI) {
53+
// Safe to set a user configuration on CI
54+
await npm('config', 'set', 'registry', url);
55+
} else {
56+
// Yarn does not use the environment variable so an .npmrc file is also required
57+
await writeFile('.npmrc', `registry=${url}`);
58+
process.env['NPM_CONFIG_REGISTRY'] = url;
59+
}
60+
}

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import { gitCommit } from './git';
77
import { installWorkspacePackages } from './packages';
88
import { execAndWaitForOutputToMatch, git, ng, npm } from './process';
99

10-
const tsConfigPath = 'tsconfig.json';
11-
12-
1310
export function updateJsonFile(filePath: string, fn: (json: any) => any | void) {
1411
return readFile(filePath)
1512
.then(tsConfigJson => {
@@ -23,7 +20,7 @@ export function updateJsonFile(filePath: string, fn: (json: any) => any | void)
2320

2421

2522
export function updateTsConfig(fn: (json: any) => any | void) {
26-
return updateJsonFile(tsConfigPath, fn);
23+
return updateJsonFile('tsconfig.json', fn);
2724
}
2825

2926

@@ -293,9 +290,8 @@ export function useCIChrome(projectDir: string) {
293290
});
294291
}
295292

296-
export async function isPrereleaseCli() {
297-
const angularCliPkgJson = JSON.parse(await readFile('node_modules/@angular/cli/package.json'));
298-
const pre = prerelease(angularCliPkgJson.version);
293+
export function isPrereleaseCli(): boolean {
294+
const pre = prerelease(packages['@angular/cli'].version);
299295

300296
return pre && pre.length > 0;
301297
}

0 commit comments

Comments
 (0)