Skip to content

Commit

Permalink
test(@schematics/angular): update version 8 migration to use NPM pack…
Browse files Browse the repository at this point in the history
…ages

This is needed as otherwise the installation of older packages will fai.
  • Loading branch information
alan-agius4 committed Mar 17, 2021
1 parent 0199170 commit b1fa5bd
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 21 deletions.
3 changes: 1 addition & 2 deletions tests/legacy-cli/e2e/assets/8.0-project/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"compilerOptions": {
"outDir": "./out-tsc/spec",
"types": [
"jasmine",
"node"
"jasmine"
]
},
"files": [
Expand Down
10 changes: 2 additions & 8 deletions tests/legacy-cli/e2e/setup/500-create-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { join } from 'path';
import { getGlobalVariable } from '../utils/env';
import { expectFileToExist, writeFile } from '../utils/fs';
import { gitClean } from '../utils/git';
import { setRegistry as setNPMConfigRegistry } from '../utils/packages';
import { ng, npm } from '../utils/process';
import { prepareProjectForE2e, updateJsonFile } from '../utils/project';

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

// Ensure local test registry is used when outside a project
if (isCI) {
// Safe to set a user configuration on CI
await npm('config', 'set', 'registry', testRegistry);
} else {
// Yarn does not use the environment variable so an .npmrc file is also required
await writeFile('.npmrc', `registry=${testRegistry}`);
process.env['NPM_CONFIG_REGISTRY'] = testRegistry;
}
await setNPMConfigRegistry(true);

await ng('new', 'test-project', '--skip-install', ...extraArgs);
await expectFileToExist(join(process.cwd(), 'test-project'));
Expand Down
44 changes: 34 additions & 10 deletions tests/legacy-cli/e2e/tests/update/update-8.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,47 @@
import { createProjectFromAsset } from '../../utils/assets';
import { expectFileMatchToExist } from '../../utils/fs';
import { installWorkspacePackages } from '../../utils/packages';
import { ng, noSilentNg, silentNpm } from '../../utils/process';
import { getGlobalVariable } from '../../utils/env';
import { expectFileMatchToExist, rimraf, writeFile } from '../../utils/fs';
import { installWorkspacePackages, setRegistry } from '../../utils/packages';
import { ng, noSilentNg } from '../../utils/process';
import { isPrereleaseCli, useBuiltPackages, useCIChrome, useCIDefaults } from '../../utils/project';

export default async function() {
await createProjectFromAsset('8.0-project');
await ng('update', '@angular/cli', '--migrate-only', '--from=8');
export default async function () {
await createProjectFromAsset('8.0-project', true, true);

// We need to use the public registry because in the local NPM server we don't have
// older versions @angular/cli packages which would cause `npm install` during `ng update` to fail.
try {
await setRegistry(false);

await useBuiltPackages();
await installWorkspacePackages();

// Update Angular CLI.
await ng('update', '@angular/cli', '--migrate-only', '--from=8');
} finally {
await setRegistry(true);
}

if (!getGlobalVariable('ci')) {
const testRegistry = getGlobalVariable('package-registry');
await writeFile('.npmrc', `registry=${testRegistry}`);
}

// Update Angular.
const extraUpdateArgs = await isPrereleaseCli() ? ['--next', '--force'] : [];
await ng('update', '@angular/core', ...extraUpdateArgs);

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

// Update Angular.
const extraUpdateArgs = await isPrereleaseCli() ? ['--next', '--force'] : [];
await ng('update', '@angular/core', ...extraUpdateArgs);
// This is needed as otherwise causes local modules not to override already present modules
await rimraf('node_modules/@angular-devkit');
await rimraf('node_modules/@angular/cli');

await installWorkspacePackages();

// Run CLI commands.
await ng('generate', 'component', 'my-comp');
Expand Down
21 changes: 20 additions & 1 deletion tests/legacy-cli/e2e/utils/packages.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getGlobalVariable } from './env';
import { ProcessOutput, silentNpm, silentYarn } from './process';
import { writeFile } from './fs';
import { ProcessOutput, npm, silentNpm, silentYarn } from './process';

export function getActivePackageManager(): 'npm' | 'yarn' {
const value = getGlobalVariable('package-manager');
Expand Down Expand Up @@ -39,3 +40,21 @@ export async function uninstallPackage(name: string): Promise<ProcessOutput> {
return silentYarn('remove', name);
}
}

export async function setRegistry(useTestRegistry: boolean): Promise<void> {
const url = useTestRegistry
? getGlobalVariable('package-registry')
: 'https://registry.npmjs.org';

const isCI = getGlobalVariable('ci');

// Ensure local test registry is used when outside a project
if (isCI) {
// Safe to set a user configuration on CI
await npm('config', 'set', 'registry', url);
} else {
// Yarn does not use the environment variable so an .npmrc file is also required
await writeFile('.npmrc', `registry=${url}`);
process.env['NPM_CONFIG_REGISTRY'] = url;
}
}

0 comments on commit b1fa5bd

Please sign in to comment.