Skip to content

Commit de674f2

Browse files
alan-agius4filipesilva
authored andcommitted
test: 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 6152689 commit de674f2

File tree

3 files changed

+15
-24
lines changed

3 files changed

+15
-24
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: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import { ng, noSilentNg } from '../../utils/process';
55
import { isPrereleaseCli, useCIChrome, useCIDefaults } from '../../utils/project';
66

77
export default async function () {
8-
const extraUpdateArgs = await isPrereleaseCli() || true ? ['--next', '--force'] : [];
9-
108
// We need to use the public registry because in the local NPM server we don't have
119
// older versions @angular/cli packages which would cause `npm install` during `ng update` to fail.
1210
try {
@@ -32,7 +30,12 @@ export default async function () {
3230
}
3331

3432
// Update Angular current build
35-
await ng('update', '@angular/cli', '@angular/core', ...extraUpdateArgs);
33+
const extraUpdateArgs = isPrereleaseCli() ? ['--next', '--force'] : [];
34+
// For the latest/next release we purposely don't add `@angular/core`.
35+
// This is due to our bumping strategy, which causes a period were `@angular/cli@latest` (v12.0.0) `@angular/core@latest` (v11.2.x)
36+
// are of different major/minor version on the local NPM server. This causes `ng update` to fail.
37+
// NB: `ng update @angula/cli` will still cause `@angular/core` packages to be updated.
38+
await ng('update', '@angular/cli', ...extraUpdateArgs);
3639

3740
// Setup testing to use CI Chrome.
3841
await useCIChrome('./');

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

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

11-
const tsConfigPath = 'tsconfig.json';
12-
13-
1411
export function updateJsonFile(filePath: string, fn: (json: any) => any | void) {
1512
return readFile(filePath)
1613
.then(tsConfigJson => {
@@ -24,7 +21,7 @@ export function updateJsonFile(filePath: string, fn: (json: any) => any | void)
2421

2522

2623
export function updateTsConfig(fn: (json: any) => any | void) {
27-
return updateJsonFile(tsConfigPath, fn);
24+
return updateJsonFile('tsconfig.json', fn);
2825
}
2926

3027

@@ -263,9 +260,8 @@ export async function useCIChrome(projectDir: string = ''): Promise<void> {
263260
}
264261
}
265262

266-
export async function isPrereleaseCli() {
267-
const angularCliPkgJson = JSON.parse(await readFile('node_modules/@angular/cli/package.json'));
268-
const pre = prerelease(angularCliPkgJson.version);
263+
export function isPrereleaseCli(): boolean {
264+
const pre = prerelease(packages['@angular/cli'].version);
269265

270266
return pre && pre.length > 0;
271267
}

0 commit comments

Comments
 (0)