Skip to content

Commit c3298f6

Browse files
devversionandrewseguin
authored andcommitted
build: use shared karma web test suite from dev-infra
We recently moved the karma web test suite debug tooling to the dev-infra repository, allowing for the code to be used in framwork as well. This dedupes the logic in the COMP repo.
1 parent eae3cfa commit c3298f6

File tree

3 files changed

+20
-38
lines changed

3 files changed

+20
-38
lines changed

DEV_ENVIRONMENT.md

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ To run unit tests, run `yarn test <target>`. The `target` can be either a short
2222
To run the e2e tests, run `yarn e2e`.
2323
To run lint, run `yarn lint`.
2424

25+
You can debug unit tests by running `yarn test` with the `--debug` option. This will allow you to
26+
manually connect a browser to the Karma server.
27+
2528
### Getting Packages from Build Artifacts
2629
Each CI run for a Pull Request stores the built Angular packages as
2730
[build artifacts](https://circleci.com/docs/2.0/artifacts). The artifacts are not guaranteed to be

scripts/run-component-tests.js

+14-13
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
*
1313
* Supported command line flags:
1414
*
15-
* --local | If specified, no browser will be launched.
16-
* --firefox | Instead of Chrome being used for tests, Firefox will be used.
17-
* --no-watch | Watch mode is enabled by default. This flag opts-out to standard Bazel.
15+
* --debug | If specified, no browser will be launched.
16+
* --firefox | Instead of Chrome being used for tests, Firefox will be used.
17+
* --no-watch | Watch mode is enabled by default. This flag opts-out to standard Bazel.
1818
*/
1919

2020
const yargs = require('yargs');
@@ -35,13 +35,14 @@ shelljs.set('-e');
3535
shelljs.cd(projectDir);
3636

3737
// Extracts the supported command line options.
38-
const {components, local, firefox, watch} = yargs(args)
38+
const {components, debug, firefox, watch} = yargs(args)
3939
.command('* <components..>', 'Run tests for specified components', args =>
4040
args.positional('components', {type: 'array'}),
4141
)
42-
.option('local', {
42+
.option('debug', {
43+
alias: 'local',
4344
type: 'boolean',
44-
description: 'Whether test should run in local mode. You can manually connect a browser then.',
45+
description: 'Whether test should run in debug mode. You can manually connect a browser then.',
4546
})
4647
.option('firefox', {
4748
type: 'boolean',
@@ -58,13 +59,13 @@ const {components, local, firefox, watch} = yargs(args)
5859
// Whether tests for all components should be run.
5960
const all = components.length === 1 && components[0] === 'all';
6061

61-
// We can only run a single target with "--local". Running multiple targets within the
62+
// We can only run a single target with "--debug". Running multiple targets within the
6263
// same Karma server is not possible since each test target runs isolated from the others.
63-
if (local && (components.length > 1 || all)) {
64+
if (debug && (components.length > 1 || all)) {
6465
console.error(
6566
chalk.red(
66-
'Unable to run multiple components tests in local mode. ' +
67-
'Only one component at a time can be run with "--local"',
67+
'Unable to run multiple components tests in debug mode. ' +
68+
'Only one component at a time can be run with "--debug"',
6869
),
6970
);
7071
process.exit(1);
@@ -105,7 +106,7 @@ if (!components.length) {
105106
process.exit(1);
106107
}
107108

108-
const bazelAction = local ? 'run' : 'test';
109+
const bazelAction = debug ? 'run' : 'test';
109110
const testLabels = components.map(t => `${getBazelPackageOfComponentName(t)}:${getTargetName(t)}`);
110111

111112
// Runs Bazel for the determined test labels.
@@ -152,10 +153,10 @@ function convertPathToBazelLabel(name) {
152153

153154
/** Gets the name of the target that should be run. */
154155
function getTargetName(packageName) {
155-
// Schematics don't have _local and browser targets.
156+
// Schematics don't have _debug and browser targets.
156157
if (packageName && packageName.endsWith('schematics')) {
157158
return 'unit_tests';
158159
}
159160

160-
return `unit_tests_${local ? 'local' : browserName}`;
161+
return `unit_tests_${debug ? 'debug' : browserName}`;
161162
}

tools/defaults.bzl

+3-25
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ load("@build_bazel_rules_nodejs//:index.bzl", _pkg_npm = "pkg_npm")
55
load("@io_bazel_rules_sass//:defs.bzl", _npm_sass_library = "npm_sass_library", _sass_binary = "sass_binary", _sass_library = "sass_library")
66
load("@npm//@angular/bazel:index.bzl", _ng_module = "ng_module", _ng_package = "ng_package")
77
load("@npm//@angular/dev-infra-private/bazel/integration:index.bzl", _integration_test = "integration_test")
8+
load("@npm//@angular/dev-infra-private/bazel/karma:index.bzl", _karma_web_test_suite = "karma_web_test_suite")
89
load("@npm//@angular/dev-infra-private/bazel/esbuild:index.bzl", _esbuild = "esbuild", _esbuild_config = "esbuild_config")
910
load("@npm//@angular/dev-infra-private/bazel/spec-bundling:index.bzl", _spec_bundle = "spec_bundle")
1011
load("@npm//@angular/dev-infra-private/bazel/http-server:index.bzl", _http_server = "http_server")
1112
load("@npm//@angular/dev-infra-private/bazel:extract_js_module_output.bzl", "extract_js_module_output")
1213
load("@npm//@bazel/jasmine:index.bzl", _jasmine_node_test = "jasmine_node_test")
13-
load("@npm//@bazel/concatjs:index.bzl", _karma_web_test = "karma_web_test", _karma_web_test_suite = "karma_web_test_suite")
1414
load("@npm//@bazel/protractor:index.bzl", _protractor_web_test_suite = "protractor_web_test_suite")
1515
load("@npm//@bazel/typescript:index.bzl", _ts_library = "ts_library")
1616
load("@npm//tsec:index.bzl", _tsec_test = "tsec_test")
@@ -305,30 +305,8 @@ def karma_web_test_suite(name, **kwargs):
305305
"@npm//@angular/dev-infra-private/bazel/browsers/firefox:firefox",
306306
]
307307

308-
for opt_name in kwargs.keys():
309-
# Filter out options which are specific to "karma_web_test" targets. We cannot
310-
# pass options like "browsers" to the local web test target.
311-
if not opt_name in ["wrapped_test_tags", "browsers", "wrapped_test_tags", "tags"]:
312-
web_test_args[opt_name] = kwargs[opt_name]
313-
314-
# Custom standalone web test that can be run to test against any browser
315-
# that is manually connected to.
316-
_karma_web_test(
317-
name = "%s_local_bin" % name,
318-
config_file = "//test:bazel-karma-local-config.js",
319-
tags = ["manual"],
320-
**web_test_args
321-
)
322-
323-
# Workaround for: https://github.com/bazelbuild/rules_nodejs/issues/1429
324-
native.sh_test(
325-
name = "%s_local" % name,
326-
srcs = ["%s_local_bin" % name],
327-
tags = ["manual", "local", "ibazel_notify_changes"],
328-
testonly = True,
329-
)
330-
331-
# Default test suite with all configured browsers.
308+
# Default test suite with all configured browsers, and the debug target being
309+
# setup from `@angular/dev-infra-private`.
332310
_karma_web_test_suite(
333311
name = name,
334312
**kwargs

0 commit comments

Comments
 (0)