test: remove reliance on built tarballs in E2E tests

Remove reliance on tarballs during E2E. Instead we always download the package from the private NPM server.
This commit is contained in:
Alan Agius 2022-08-12 13:33:13 +00:00 committed by Charles
parent fd4755d406
commit 8112d7bae0
6 changed files with 33 additions and 31 deletions

View File

@ -1,6 +1,5 @@
import { createProjectFromAsset } from '../../utils/assets'; import { createProjectFromAsset } from '../../utils/assets';
import { moveFile, replaceInFile } from '../../utils/fs'; import { moveFile, replaceInFile } from '../../utils/fs';
import { setRegistry } from '../../utils/packages';
import { noSilentNg } from '../../utils/process'; import { noSilentNg } from '../../utils/process';
import { useCIChrome, useCIDefaults } from '../../utils/project'; import { useCIChrome, useCIDefaults } from '../../utils/project';
import { expectToFail } from '../../utils/utils'; import { expectToFail } from '../../utils/utils';
@ -12,11 +11,12 @@ import { expectToFail } from '../../utils/utils';
*/ */
export default async function () { export default async function () {
let restoreRegistry: (() => Promise<void>) | undefined;
try { try {
// We need to use the public registry because in the local NPM server we don't have // 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. // older versions @angular/cli packages which would cause `npm install` during `ng update` to fail.
await setRegistry(false); restoreRegistry = await createProjectFromAsset('13.0-project', true);
await createProjectFromAsset('13.0-project', true);
// A missing stylesheet error will trigger the stuck process issue with v13 when building // A missing stylesheet error will trigger the stuck process issue with v13 when building
await moveFile('src/styles.css', 'src/styles.scss'); await moveFile('src/styles.css', 'src/styles.scss');
@ -30,6 +30,6 @@ export default async function () {
await useCIDefaults('thirteen-project'); await useCIDefaults('thirteen-project');
await noSilentNg('test', '--watch=false'); await noSilentNg('test', '--watch=false');
} finally { } finally {
await setRegistry(true); await restoreRegistry?.();
} }
} }

View File

@ -5,8 +5,7 @@ import { execWithEnv } from '../../../utils/process';
export default async function () { export default async function () {
const webpackCLIBin = normalize('node_modules/.bin/webpack-cli'); const webpackCLIBin = normalize('node_modules/.bin/webpack-cli');
const restoreRegistry = await createProjectFromAsset('webpack/test-app');
await createProjectFromAsset('webpack/test-app');
// DISABLE_V8_COMPILE_CACHE=1 is required to disable the `v8-compile-cache` package. // DISABLE_V8_COMPILE_CACHE=1 is required to disable the `v8-compile-cache` package.
// It currently does not support dynamic import expressions which are now required by the // It currently does not support dynamic import expressions which are now required by the
@ -30,4 +29,5 @@ export default async function () {
'DISABLE_V8_COMPILE_CACHE': '1', 'DISABLE_V8_COMPILE_CACHE': '1',
}); });
await expectFileToMatch('dist/app.main.js', 'AppModule'); await expectFileToMatch('dist/app.main.js', 'AppModule');
await restoreRegistry();
} }

View File

@ -1,14 +1,13 @@
import { createProjectFromAsset } from '../../utils/assets'; import { createProjectFromAsset } from '../../utils/assets';
import { installWorkspacePackages, setRegistry } from '../../utils/packages'; import { setRegistry } from '../../utils/packages';
import { ng } from '../../utils/process'; import { ng } from '../../utils/process';
import { isPrereleaseCli } from '../../utils/project'; import { isPrereleaseCli } from '../../utils/project';
import { expectToFail } from '../../utils/utils'; import { expectToFail } from '../../utils/utils';
export default async function () { export default async function () {
let restoreRegistry: (() => Promise<void>) | undefined;
try { try {
await createProjectFromAsset('12.0-project', true, true); restoreRegistry = await createProjectFromAsset('12.0-project', true);
await setRegistry(false);
await installWorkspacePackages();
await setRegistry(true); await setRegistry(true);
const extraArgs = ['--force']; const extraArgs = ['--force'];
@ -38,6 +37,6 @@ export default async function () {
); );
} }
} finally { } finally {
await setRegistry(true); await restoreRegistry?.();
} }
} }

View File

@ -2,16 +2,17 @@ import { appendFile } from 'fs/promises';
import { SemVer } from 'semver'; import { SemVer } from 'semver';
import { createProjectFromAsset } from '../../utils/assets'; import { createProjectFromAsset } from '../../utils/assets';
import { expectFileMatchToExist, readFile } from '../../utils/fs'; import { expectFileMatchToExist, readFile } from '../../utils/fs';
import { getActivePackageManager, setRegistry } from '../../utils/packages'; import { getActivePackageManager } from '../../utils/packages';
import { ng, noSilentNg } from '../../utils/process'; import { ng, noSilentNg } from '../../utils/process';
import { isPrereleaseCli, useCIChrome, useCIDefaults, NgCLIVersion } from '../../utils/project'; import { isPrereleaseCli, useCIChrome, useCIDefaults, NgCLIVersion } from '../../utils/project';
export default async function () { export default async function () {
let restoreRegistry: (() => Promise<void>) | undefined;
try { try {
// We need to use the public registry because in the local NPM server we don't have // 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. // older versions @angular/cli packages which would cause `npm install` during `ng update` to fail.
await setRegistry(false); restoreRegistry = await createProjectFromAsset('12.0-project', true);
await createProjectFromAsset('12.0-project', true);
// If using npm, enable legacy peer deps mode to avoid defects in npm 7+'s peer dependency resolution // If using npm, enable legacy peer deps mode to avoid defects in npm 7+'s peer dependency resolution
// Example error where 11.2.14 satisfies the SemVer range ^11.0.0 but still fails: // Example error where 11.2.14 satisfies the SemVer range ^11.0.0 but still fails:
@ -49,7 +50,7 @@ export default async function () {
} }
} }
} finally { } finally {
await setRegistry(true); await restoreRegistry?.();
} }
// Update Angular current build // Update Angular current build

View File

@ -2,10 +2,10 @@ import { join } from 'path';
import { chmod } from 'fs/promises'; import { chmod } from 'fs/promises';
import glob from 'glob'; import glob from 'glob';
import { getGlobalVariable } from './env'; import { getGlobalVariable } from './env';
import { relative, resolve } from 'path'; import { resolve } from 'path';
import { copyFile, writeFile } from './fs'; import { copyFile } from './fs';
import { installWorkspacePackages } from './packages'; import { installWorkspacePackages, setRegistry } from './packages';
import { useBuiltPackages } from './project'; import { useBuiltPackagesVersions } from './project';
export function assetDir(assetName: string) { export function assetDir(assetName: string) {
return join(__dirname, '../assets', assetName); return join(__dirname, '../assets', assetName);
@ -42,24 +42,26 @@ export function copyAssets(assetName: string, to?: string) {
.then(() => tempRoot); .then(() => tempRoot);
} }
/**
* @returns a method that once called will restore the environment
* to use the local NPM registry.
* */
export async function createProjectFromAsset( export async function createProjectFromAsset(
assetName: string, assetName: string,
useNpmPackages = false, useNpmPackages = false,
skipInstall = false, skipInstall = false,
) { ): Promise<() => Promise<void>> {
const dir = await copyAssets(assetName); const dir = await copyAssets(assetName);
process.chdir(dir); process.chdir(dir);
if (!useNpmPackages) {
await useBuiltPackages();
if (!getGlobalVariable('ci')) {
const testRegistry = getGlobalVariable('package-registry');
await writeFile('.npmrc', `registry=${testRegistry}`);
}
}
await setRegistry(!useNpmPackages /** useTestRegistry */);
if (!useNpmPackages) {
await useBuiltPackagesVersions();
}
if (!skipInstall) { if (!skipInstall) {
await installWorkspacePackages(); await installWorkspacePackages();
} }
return dir; return () => setRegistry(true /** useTestRegistry */);
} }

View File

@ -94,16 +94,16 @@ export async function prepareProjectForE2e(name: string) {
await gitCommit('prepare-project-for-e2e'); await gitCommit('prepare-project-for-e2e');
} }
export function useBuiltPackages(): Promise<void> { export function useBuiltPackagesVersions(): Promise<void> {
return updateJsonFile('package.json', (json) => { return updateJsonFile('package.json', (json) => {
json['dependencies'] ??= {}; json['dependencies'] ??= {};
json['devDependencies'] ??= {}; json['devDependencies'] ??= {};
for (const packageName of Object.keys(packages)) { for (const packageName of Object.keys(packages)) {
if (packageName in json['dependencies']) { if (packageName in json['dependencies']) {
json['dependencies'][packageName] = packages[packageName].tar; json['dependencies'][packageName] = packages[packageName].version;
} else if (packageName in json['devDependencies']) { } else if (packageName in json['devDependencies']) {
json['devDependencies'][packageName] = packages[packageName].tar; json['devDependencies'][packageName] = packages[packageName].version;
} }
} }
}); });