Skip to content

Commit 2023138

Browse files
jbedardalan-agius4
authored andcommitted
test: run e2e tests on pre-compiled packages
The NPM packages being tested must be pre-compiled and the tar packages specified via --package. This way the real packages such as snapshots, release artifacts or cached packages can be tested. Previously the e2e tests compiled and packaged during test execution. (cherry picked from commit 2624d89)
1 parent b73521b commit 2023138

File tree

12 files changed

+138
-41
lines changed

12 files changed

+138
-41
lines changed

.circleci/dynamic_config.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ jobs:
264264
# Waits for the Saucelabs tunnel to be ready. This ensures that we don't run tests
265265
# too early without Saucelabs not being ready.
266266
- run: ./scripts/saucelabs/wait-for-tunnel.sh
267-
- run: node ./tests/legacy-cli/run_e2e ./tests/legacy-cli/e2e/tests/misc/browsers.ts
267+
- run: node ./tests/legacy-cli/run_e2e --glob="tests/misc/browsers.ts"
268268
- run: ./scripts/saucelabs/stop-tunnel.sh
269269
- fail_fast
270270

@@ -273,6 +273,10 @@ jobs:
273273
steps:
274274
- custom_attach_workspace
275275
- run: yarn build
276+
- persist_to_workspace:
277+
root: *workspace_location
278+
paths:
279+
- dist/_*.tgz
276280

277281
build-bazel-e2e:
278282
executor: action-executor
@@ -376,6 +380,8 @@ jobs:
376380
# Path where Arsenal Image Mounter files are downloaded.
377381
# Must match path in .circleci/win-ram-disk.ps1
378382
- ./aim
383+
# Build the npm packages for the e2e tests
384+
- run: yarn build
379385
# Run partial e2e suite on PRs only. Release branches will run the full e2e suite.
380386
- run:
381387
name: Execute E2E Tests

docs/DEVELOPER.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ You can find more info about debugging [tests with Bazel in the docs.](https://g
8282

8383
### End to end tests
8484

85-
- Run: `node tests/legacy-cli/run_e2e.js`
85+
- Compile the packages being tested: `yarn build`
86+
- Run all tests: `node tests/legacy-cli/run_e2e.js`
8687
- Run a subset of the tests: `node tests/legacy-cli/run_e2e.js tests/legacy-cli/e2e/tests/i18n/ivy-localize-*`
88+
- Run on a custom set of npm packages (tar files): `node tests/legacy-cli/run_e2e.js --package _angular_cli.tgz _angular_create.tgz dist/*.tgz ...`
8789

8890
When running the debug commands, Node will stop and wait for a debugger to attach.
8991
You can attach your IDE to the debugger to stop on breakpoints and step through the code. Also, see [IDE Specific Usage](#ide-specific-usage) for a

lib/BUILD.bazel

Lines changed: 0 additions & 12 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
"@types/progress": "^2.0.3",
120120
"@types/resolve": "^1.17.1",
121121
"@types/semver": "^7.3.12",
122+
"@types/tar": "^6.1.2",
122123
"@types/text-table": "^0.2.1",
123124
"@types/uuid": "^8.0.0",
124125
"@types/yargs": "^17.0.8",
Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
import { getGlobalVariable } from '../utils/env';
2+
import { PkgInfo } from '../utils/packages';
23
import { globalNpm, extractNpmEnv } from '../utils/process';
34
import { isPrereleaseCli } from '../utils/project';
45

56
export default async function () {
67
const testRegistry: string = getGlobalVariable('package-registry');
7-
await globalNpm(
8-
[
9-
'run',
10-
'admin',
11-
'--',
12-
'publish',
13-
'--no-versionCheck',
14-
'--no-branchCheck',
15-
`--registry=${testRegistry}`,
16-
'--tag',
17-
isPrereleaseCli() ? 'next' : 'latest',
18-
],
19-
{
20-
...extractNpmEnv(),
21-
// Also set an auth token value for the local test registry which is required by npm 7+
22-
// even though it is never actually used.
23-
'NPM_CONFIG__AUTH': 'e2e-testing',
24-
},
8+
const packageTars: PkgInfo[] = Object.values(getGlobalVariable('package-tars'));
9+
10+
// Publish packages specified with --package
11+
await Promise.all(
12+
packageTars.map(({ path: p }) =>
13+
globalNpm(
14+
[
15+
'publish',
16+
`--registry=${testRegistry}`,
17+
'--tag',
18+
isPrereleaseCli() ? 'next' : 'latest',
19+
p,
20+
],
21+
{
22+
...extractNpmEnv(),
23+
// Also set an auth token value for the local test registry which is required by npm 7+
24+
// even though it is never actually used.
25+
'NPM_CONFIG__AUTH': 'e2e-testing',
26+
},
27+
),
28+
),
2529
);
2630
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createProjectFromAsset } from '../../utils/assets';
44
import { expectFileMatchToExist, readFile } from '../../utils/fs';
55
import { getActivePackageManager } from '../../utils/packages';
66
import { ng, noSilentNg } from '../../utils/process';
7-
import { isPrereleaseCli, useCIChrome, useCIDefaults, NgCLIVersion } from '../../utils/project';
7+
import { isPrereleaseCli, useCIChrome, useCIDefaults, getNgCLIVersion } from '../../utils/project';
88

99
export default async function () {
1010
let restoreRegistry: (() => Promise<void>) | undefined;
@@ -32,7 +32,7 @@ export default async function () {
3232
const cliMajorProjectVersion = new SemVer(cliVersion).major;
3333

3434
// CLI current version.
35-
const cliMajorVersion = NgCLIVersion.major;
35+
const cliMajorVersion = getNgCLIVersion().major;
3636

3737
for (let version = cliMajorProjectVersion + 1; version < cliMajorVersion; version++) {
3838
// Run all the migrations until the current build major version - 1.

tests/legacy-cli/e2e/utils/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ ts_library(
66
srcs = glob(["**/*.ts"]),
77
visibility = ["//visibility:public"],
88
deps = [
9-
"//lib",
109
"//tests/legacy-cli/e2e/ng-snapshot",
1110
"@npm//@types/glob",
1211
"@npm//@types/node-fetch",
1312
"@npm//@types/semver",
13+
"@npm//@types/tar",
1414
"@npm//@types/yargs-parser",
1515
"@npm//ansi-colors",
1616
"@npm//glob",
@@ -19,6 +19,7 @@ ts_library(
1919
"@npm//puppeteer",
2020
"@npm//rxjs",
2121
"@npm//semver",
22+
"@npm//tar",
2223
"@npm//tree-kill",
2324
"@npm//verdaccio",
2425
"@npm//verdaccio-auth-memory",

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { getGlobalVariable } from './env';
22
import { ProcessOutput, silentNpm, silentYarn } from './process';
33

4+
export interface PkgInfo {
5+
readonly name: string;
6+
readonly version: string;
7+
readonly path: string;
8+
}
9+
410
export function getActivePackageManager(): 'npm' | 'yarn' {
511
const value = getGlobalVariable('package-manager');
612
if (value && value !== 'npm' && value !== 'yarn') {

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ import * as fs from 'fs';
22
import * as path from 'path';
33
import { prerelease, SemVer } from 'semver';
44
import yargsParser from 'yargs-parser';
5-
import { packages } from '../../../../lib/packages';
65
import { getGlobalVariable } from './env';
76
import { prependToFile, readFile, replaceInFile, writeFile } from './fs';
87
import { gitCommit } from './git';
98
import { findFreePort } from './network';
10-
import { installWorkspacePackages } from './packages';
9+
import { installWorkspacePackages, PkgInfo } from './packages';
1110
import { exec, execAndWaitForOutputToMatch, git, ng } from './process';
1211

1312
export function updateJsonFile(filePath: string, fn: (json: any) => any | void) {
@@ -96,6 +95,8 @@ export async function prepareProjectForE2e(name: string) {
9695
}
9796

9897
export function useBuiltPackagesVersions(): Promise<void> {
98+
const packages: { [name: string]: PkgInfo } = getGlobalVariable('package-tars');
99+
99100
return updateJsonFile('package.json', (json) => {
100101
json['dependencies'] ??= {};
101102
json['devDependencies'] ??= {};
@@ -221,8 +222,12 @@ export async function useCIChrome(projectDir: string = ''): Promise<void> {
221222
}
222223
}
223224

224-
export const NgCLIVersion = new SemVer(packages['@angular/cli'].version);
225+
export function getNgCLIVersion(): SemVer {
226+
const packages: { [name: string]: PkgInfo } = getGlobalVariable('package-tars');
227+
228+
return new SemVer(packages['@angular/cli'].version);
229+
}
225230

226231
export function isPrereleaseCli(): boolean {
227-
return (prerelease(NgCLIVersion)?.length ?? 0) > 0;
232+
return (prerelease(getNgCLIVersion())?.length ?? 0) > 0;
228233
}

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import fs from 'fs';
10+
import { normalize } from 'path';
11+
import { Parse } from 'tar';
12+
13+
/**
14+
* Extract and return the contents of a single file out of a tar file.
15+
*
16+
* @param tarball the tar file to extract from
17+
* @param filePath the path of the file to extract
18+
* @returns the Buffer of file or an error on fs/tar error or file not found
19+
*/
20+
export async function extractFile(tarball: string, filePath: string): Promise<Buffer> {
21+
return new Promise((resolve, reject) => {
22+
fs.createReadStream(tarball)
23+
.pipe(
24+
new Parse({
25+
strict: true,
26+
filter: (p) => normalize(p) === normalize(filePath),
27+
// TODO: @types/tar 'entry' does not have ReadEntry.on
28+
onentry: (entry: any) => {
29+
const chunks: Buffer[] = [];
30+
31+
entry.on('data', (chunk: any) => chunks!.push(chunk));
32+
entry.on('error', reject);
33+
entry.on('finish', () => resolve(Buffer.concat(chunks!)));
34+
},
35+
}),
36+
)
37+
.on('close', () => reject(`${tarball} does not contain ${filePath}`));
38+
});
39+
}

0 commit comments

Comments
 (0)