Skip to content

Commit 9b8baa6

Browse files
clydinalan-agius4
authored andcommitted
test: use Node.js argument parser for E2E test runner
The `node:util` builtin provides an argument parser that can be leveraged for the E2E test runner that avoids the need for additional third-party packages.
1 parent 75bf115 commit 9b8baa6

File tree

7 files changed

+41
-33
lines changed

7 files changed

+41
-33
lines changed

tests/legacy-cli/BUILD.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ ts_library(
1515
"//packages/angular_devkit/core",
1616
"//packages/angular_devkit/core/node",
1717
"//tests/legacy-cli/e2e/utils",
18-
"@npm//@types/yargs-parser",
1918
"@npm//ansi-colors",
2019
"@npm//fast-glob",
21-
"@npm//yargs-parser",
2220
],
2321
)
2422

tests/legacy-cli/e2e.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ def e2e_suites(name, runner, data):
8383

8484
def _e2e_tests(name, runner, **kwargs):
8585
# Always specify all the npm packages
86-
args = kwargs.pop("templated_args", []) + ["--package"] + [
87-
"$(rootpath %s)" % p
86+
args = kwargs.pop("templated_args", []) + [
87+
"--package $(rootpath %s)" % p
8888
for p in TESTED_PACKAGES
8989
]
9090

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { join } from 'path';
2-
import yargsParser from 'yargs-parser';
32
import { getGlobalVariable } from '../utils/env';
43
import { expectFileToExist } from '../utils/fs';
54
import { gitClean } from '../utils/git';
@@ -8,13 +7,13 @@ import { ng } from '../utils/process';
87
import { prepareProjectForE2e, updateJsonFile } from '../utils/project';
98

109
export default async function () {
11-
const argv = getGlobalVariable<yargsParser.Arguments>('argv');
10+
const argv: Record<string, unknown> = getGlobalVariable('argv');
1211

1312
if (argv.noproject) {
1413
return;
1514
}
1615

17-
if (argv.reuse) {
16+
if (argv.reuse && typeof argv.reuse === 'string') {
1817
process.chdir(argv.reuse);
1918
await gitClean();
2019
} else {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ ts_library(
1010
visibility = ["//visibility:public"],
1111
deps = [
1212
"//tests/legacy-cli/e2e/utils",
13-
"@npm//@types/yargs-parser",
1413
],
1514
)

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ ts_library(
1111
deps = [
1212
"@npm//@types/semver",
1313
"@npm//@types/tar",
14-
"@npm//@types/yargs-parser",
1514
"@npm//ansi-colors",
1615
"@npm//fast-glob",
1716
"@npm//npm",

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as fs from 'fs';
22
import * as path from 'path';
33
import { prerelease, SemVer } from 'semver';
4-
import yargsParser from 'yargs-parser';
54
import { getGlobalVariable } from './env';
65
import { readFile, replaceInFile, writeFile } from './fs';
76
import { gitCommit } from './git';
@@ -39,7 +38,7 @@ export async function ngServe(...args: string[]) {
3938
}
4039

4140
export async function prepareProjectForE2e(name: string) {
42-
const argv: yargsParser.Arguments = getGlobalVariable('argv');
41+
const argv: Record<string, unknown> = getGlobalVariable('argv');
4342

4443
await git('config', 'user.email', 'angular-core+e2e@google.com');
4544
await git('config', 'user.name', 'Angular CLI E2E');

tests/legacy-cli/e2e_runner.ts

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { parseArgs } from 'node:util';
12
import { createConsoleLogger } from '../../packages/angular_devkit/core/node';
23
import colors from 'ansi-colors';
34
import glob from 'fast-glob';
4-
import yargsParser from 'yargs-parser';
55
import * as path from 'path';
66
import { getGlobalVariable, setGlobalVariable } from './e2e/utils/env';
77
import { gitClean } from './e2e/utils/git';
@@ -40,30 +40,44 @@ Error.stackTraceLimit = Infinity;
4040
*
4141
* If unnamed flags are passed in, the list of tests will be filtered to include only those passed.
4242
*/
43-
const argv = yargsParser(process.argv.slice(2), {
44-
boolean: ['debug', 'esbuild', 'ng-snapshots', 'noglobal', 'nosilent', 'noproject', 'verbose'],
45-
string: ['devkit', 'glob', 'reuse', 'ng-tag', 'tmpdir', 'ng-version', 'package-manager'],
46-
number: ['nb-shards', 'shard'],
47-
array: ['package', 'ignore'],
48-
configuration: {
49-
'camel-case-expansion': false,
50-
'dot-notation': false,
51-
},
52-
default: {
53-
'package-manager': 'npm',
54-
'package': ['./dist/_*.tgz'],
55-
'debug': !!process.env.BUILD_WORKSPACE_DIRECTORY,
56-
'glob': process.env.TESTBRIDGE_TEST_ONLY,
57-
'nb-shards':
58-
Number(process.env.E2E_SHARD_TOTAL ?? 1) * Number(process.env.TEST_TOTAL_SHARDS ?? 1) || 1,
59-
'shard':
60-
process.env.E2E_SHARD_INDEX === undefined && process.env.TEST_SHARD_INDEX === undefined
61-
? undefined
62-
: Number(process.env.E2E_SHARD_INDEX ?? 0) * Number(process.env.TEST_TOTAL_SHARDS ?? 1) +
63-
Number(process.env.TEST_SHARD_INDEX ?? 0),
43+
const parsed = parseArgs({
44+
allowPositionals: true,
45+
options: {
46+
'debug': { type: 'boolean', default: !!process.env.BUILD_WORKSPACE_DIRECTORY },
47+
'esbuild': { type: 'boolean' },
48+
'glob': { type: 'string', default: process.env.TESTBRIDGE_TEST_ONLY },
49+
'ignore': { type: 'string', multiple: true },
50+
'ng-snapshots': { type: 'boolean' },
51+
'ng-tag': { type: 'string' },
52+
'ng-version': { type: 'string' },
53+
'noglobal': { type: 'boolean' },
54+
'noproject': { type: 'boolean' },
55+
'nosilent': { type: 'boolean' },
56+
'package': { type: 'string', multiple: true, default: ['./dist/_*.tgz'] },
57+
'package-manager': { type: 'string', default: 'npm' },
58+
'reuse': { type: 'string' },
59+
'tmpdir': { type: 'string' },
60+
'verbose': { type: 'boolean' },
61+
62+
'nb-shards': { type: 'string' },
63+
'shard': { type: 'string' },
6464
},
6565
});
6666

67+
const argv = {
68+
...parsed.values,
69+
_: parsed.positionals,
70+
'nb-shards':
71+
parsed.values['nb-shards'] ??
72+
(Number(process.env.E2E_SHARD_TOTAL ?? 1) * Number(process.env.TEST_TOTAL_SHARDS ?? 1) || 1),
73+
shard:
74+
parsed.values.shard ??
75+
(process.env.E2E_SHARD_INDEX === undefined && process.env.TEST_SHARD_INDEX === undefined
76+
? undefined
77+
: Number(process.env.E2E_SHARD_INDEX ?? 0) * Number(process.env.TEST_TOTAL_SHARDS ?? 1) +
78+
Number(process.env.TEST_SHARD_INDEX ?? 0)),
79+
};
80+
6781
/**
6882
* Set the error code of the process to 255. This is to ensure that if something forces node
6983
* to exit without finishing properly, the error code will be 255. Right now that code is not used.

0 commit comments

Comments
 (0)