mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-22 15:02:11 +08:00
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:
parent
fd4755d406
commit
8112d7bae0
@ -1,6 +1,5 @@
|
||||
import { createProjectFromAsset } from '../../utils/assets';
|
||||
import { moveFile, replaceInFile } from '../../utils/fs';
|
||||
import { setRegistry } from '../../utils/packages';
|
||||
import { noSilentNg } from '../../utils/process';
|
||||
import { useCIChrome, useCIDefaults } from '../../utils/project';
|
||||
import { expectToFail } from '../../utils/utils';
|
||||
@ -12,11 +11,12 @@ import { expectToFail } from '../../utils/utils';
|
||||
*/
|
||||
|
||||
export default async function () {
|
||||
let restoreRegistry: (() => Promise<void>) | undefined;
|
||||
|
||||
try {
|
||||
// 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.
|
||||
await setRegistry(false);
|
||||
await createProjectFromAsset('13.0-project', true);
|
||||
restoreRegistry = await createProjectFromAsset('13.0-project', true);
|
||||
|
||||
// A missing stylesheet error will trigger the stuck process issue with v13 when building
|
||||
await moveFile('src/styles.css', 'src/styles.scss');
|
||||
@ -30,6 +30,6 @@ export default async function () {
|
||||
await useCIDefaults('thirteen-project');
|
||||
await noSilentNg('test', '--watch=false');
|
||||
} finally {
|
||||
await setRegistry(true);
|
||||
await restoreRegistry?.();
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,7 @@ import { execWithEnv } from '../../../utils/process';
|
||||
|
||||
export default async function () {
|
||||
const webpackCLIBin = normalize('node_modules/.bin/webpack-cli');
|
||||
|
||||
await createProjectFromAsset('webpack/test-app');
|
||||
const restoreRegistry = await createProjectFromAsset('webpack/test-app');
|
||||
|
||||
// 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
|
||||
@ -30,4 +29,5 @@ export default async function () {
|
||||
'DISABLE_V8_COMPILE_CACHE': '1',
|
||||
});
|
||||
await expectFileToMatch('dist/app.main.js', 'AppModule');
|
||||
await restoreRegistry();
|
||||
}
|
||||
|
@ -1,14 +1,13 @@
|
||||
import { createProjectFromAsset } from '../../utils/assets';
|
||||
import { installWorkspacePackages, setRegistry } from '../../utils/packages';
|
||||
import { setRegistry } from '../../utils/packages';
|
||||
import { ng } from '../../utils/process';
|
||||
import { isPrereleaseCli } from '../../utils/project';
|
||||
import { expectToFail } from '../../utils/utils';
|
||||
|
||||
export default async function () {
|
||||
let restoreRegistry: (() => Promise<void>) | undefined;
|
||||
try {
|
||||
await createProjectFromAsset('12.0-project', true, true);
|
||||
await setRegistry(false);
|
||||
await installWorkspacePackages();
|
||||
restoreRegistry = await createProjectFromAsset('12.0-project', true);
|
||||
await setRegistry(true);
|
||||
|
||||
const extraArgs = ['--force'];
|
||||
@ -38,6 +37,6 @@ export default async function () {
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
await setRegistry(true);
|
||||
await restoreRegistry?.();
|
||||
}
|
||||
}
|
||||
|
@ -2,16 +2,17 @@ import { appendFile } from 'fs/promises';
|
||||
import { SemVer } from 'semver';
|
||||
import { createProjectFromAsset } from '../../utils/assets';
|
||||
import { expectFileMatchToExist, readFile } from '../../utils/fs';
|
||||
import { getActivePackageManager, setRegistry } from '../../utils/packages';
|
||||
import { getActivePackageManager } from '../../utils/packages';
|
||||
import { ng, noSilentNg } from '../../utils/process';
|
||||
import { isPrereleaseCli, useCIChrome, useCIDefaults, NgCLIVersion } from '../../utils/project';
|
||||
|
||||
export default async function () {
|
||||
let restoreRegistry: (() => Promise<void>) | undefined;
|
||||
|
||||
try {
|
||||
// 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.
|
||||
await setRegistry(false);
|
||||
await createProjectFromAsset('12.0-project', true);
|
||||
restoreRegistry = await createProjectFromAsset('12.0-project', true);
|
||||
|
||||
// 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:
|
||||
@ -49,7 +50,7 @@ export default async function () {
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
await setRegistry(true);
|
||||
await restoreRegistry?.();
|
||||
}
|
||||
|
||||
// Update Angular current build
|
||||
|
@ -2,10 +2,10 @@ import { join } from 'path';
|
||||
import { chmod } from 'fs/promises';
|
||||
import glob from 'glob';
|
||||
import { getGlobalVariable } from './env';
|
||||
import { relative, resolve } from 'path';
|
||||
import { copyFile, writeFile } from './fs';
|
||||
import { installWorkspacePackages } from './packages';
|
||||
import { useBuiltPackages } from './project';
|
||||
import { resolve } from 'path';
|
||||
import { copyFile } from './fs';
|
||||
import { installWorkspacePackages, setRegistry } from './packages';
|
||||
import { useBuiltPackagesVersions } from './project';
|
||||
|
||||
export function assetDir(assetName: string) {
|
||||
return join(__dirname, '../assets', assetName);
|
||||
@ -42,24 +42,26 @@ export function copyAssets(assetName: string, to?: string) {
|
||||
.then(() => tempRoot);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns a method that once called will restore the environment
|
||||
* to use the local NPM registry.
|
||||
* */
|
||||
export async function createProjectFromAsset(
|
||||
assetName: string,
|
||||
useNpmPackages = false,
|
||||
skipInstall = false,
|
||||
) {
|
||||
): Promise<() => Promise<void>> {
|
||||
const dir = await copyAssets(assetName);
|
||||
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) {
|
||||
await installWorkspacePackages();
|
||||
}
|
||||
|
||||
return dir;
|
||||
return () => setRegistry(true /** useTestRegistry */);
|
||||
}
|
||||
|
@ -94,16 +94,16 @@ export async function prepareProjectForE2e(name: string) {
|
||||
await gitCommit('prepare-project-for-e2e');
|
||||
}
|
||||
|
||||
export function useBuiltPackages(): Promise<void> {
|
||||
export function useBuiltPackagesVersions(): Promise<void> {
|
||||
return updateJsonFile('package.json', (json) => {
|
||||
json['dependencies'] ??= {};
|
||||
json['devDependencies'] ??= {};
|
||||
|
||||
for (const packageName of Object.keys(packages)) {
|
||||
if (packageName in json['dependencies']) {
|
||||
json['dependencies'][packageName] = packages[packageName].tar;
|
||||
json['dependencies'][packageName] = packages[packageName].version;
|
||||
} else if (packageName in json['devDependencies']) {
|
||||
json['devDependencies'][packageName] = packages[packageName].tar;
|
||||
json['devDependencies'][packageName] = packages[packageName].version;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user