Skip to content

Commit b1fa5bd

Browse files
committed
test(@schematics/angular): update version 8 migration to use NPM packages
This is needed as otherwise the installation of older packages will fai.
1 parent 0199170 commit b1fa5bd

File tree

4 files changed

+57
-21
lines changed

4 files changed

+57
-21
lines changed

tests/legacy-cli/e2e/assets/8.0-project/tsconfig.spec.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
"compilerOptions": {
44
"outDir": "./out-tsc/spec",
55
"types": [
6-
"jasmine",
7-
"node"
6+
"jasmine"
87
]
98
},
109
"files": [

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { join } from 'path';
22
import { getGlobalVariable } from '../utils/env';
33
import { expectFileToExist, writeFile } from '../utils/fs';
44
import { gitClean } from '../utils/git';
5+
import { setRegistry as setNPMConfigRegistry } from '../utils/packages';
56
import { ng, npm } from '../utils/process';
67
import { prepareProjectForE2e, updateJsonFile } from '../utils/project';
78

@@ -21,14 +22,7 @@ export default async function() {
2122
const isCI = getGlobalVariable('ci');
2223

2324
// 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-
}
25+
await setNPMConfigRegistry(true);
3226

3327
await ng('new', 'test-project', '--skip-install', ...extraArgs);
3428
await expectFileToExist(join(process.cwd(), 'test-project'));

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

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,47 @@
11
import { createProjectFromAsset } from '../../utils/assets';
2-
import { expectFileMatchToExist } from '../../utils/fs';
3-
import { installWorkspacePackages } from '../../utils/packages';
4-
import { ng, noSilentNg, silentNpm } from '../../utils/process';
2+
import { getGlobalVariable } from '../../utils/env';
3+
import { expectFileMatchToExist, rimraf, writeFile } from '../../utils/fs';
4+
import { installWorkspacePackages, setRegistry } from '../../utils/packages';
5+
import { ng, noSilentNg } from '../../utils/process';
56
import { isPrereleaseCli, useBuiltPackages, useCIChrome, useCIDefaults } from '../../utils/project';
67

7-
export default async function() {
8-
await createProjectFromAsset('8.0-project');
9-
await ng('update', '@angular/cli', '--migrate-only', '--from=8');
8+
export default async function () {
9+
await createProjectFromAsset('8.0-project', true, true);
10+
11+
// We need to use the public registry because in the local NPM server we don't have
12+
// older versions @angular/cli packages which would cause `npm install` during `ng update` to fail.
13+
try {
14+
await setRegistry(false);
15+
16+
await useBuiltPackages();
17+
await installWorkspacePackages();
18+
19+
// Update Angular CLI.
20+
await ng('update', '@angular/cli', '--migrate-only', '--from=8');
21+
} finally {
22+
await setRegistry(true);
23+
}
24+
25+
if (!getGlobalVariable('ci')) {
26+
const testRegistry = getGlobalVariable('package-registry');
27+
await writeFile('.npmrc', `registry=${testRegistry}`);
28+
}
29+
30+
// Update Angular.
31+
const extraUpdateArgs = await isPrereleaseCli() ? ['--next', '--force'] : [];
32+
await ng('update', '@angular/core', ...extraUpdateArgs);
1033

1134
// Use the packages we are building in this commit, and CI Chrome.
1235
await useBuiltPackages();
1336
await useCIChrome('./');
1437
await useCIChrome('./e2e/');
1538
await useCIDefaults('eight-project');
16-
await installWorkspacePackages();
1739

18-
// Update Angular.
19-
const extraUpdateArgs = await isPrereleaseCli() ? ['--next', '--force'] : [];
20-
await ng('update', '@angular/core', ...extraUpdateArgs);
40+
// This is needed as otherwise causes local modules not to override already present modules
41+
await rimraf('node_modules/@angular-devkit');
42+
await rimraf('node_modules/@angular/cli');
43+
44+
await installWorkspacePackages();
2145

2246
// Run CLI commands.
2347
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 { ProcessOutput, npm, 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+
}

0 commit comments

Comments
 (0)