Skip to content

Commit dfe15ad

Browse files
committed
build: add option for running all component tests
Adds a `--all` option to the `yarn test` script. This option can be used to run _all_ component tests in the repository. Flags like `--no-watch` and `--firefox` can be used in combination with the new `-all` flag.
1 parent 68a2f89 commit dfe15ad

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

scripts/run-component-tests.js

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Script that simplifies the workflow of running unit tests for a component
55
* using Bazel. Here are a few examples:
66
*
7+
* node ./scripts/run-component-tests all | Runs tests for all components
78
* node ./scripts/run-component-tests button | Runs Material button tests
89
* node ./scripts/run-component-tests overlay | Runs CDK overlay tests
910
* node ./scripts/run-component-tests src/cdk/a11y | Runs CDK a11y tests
@@ -43,31 +44,48 @@ const {_: components, local, firefox, watch} = minimist(args, {
4344
default: {watch: true},
4445
});
4546

46-
// Exit if no component has been specified.
47-
if (!components.length) {
48-
console.error(chalk.red(
49-
'No component specified. Specify a component name, or pass a ' +
50-
'path to the component directory.'));
51-
process.exit(1);
52-
}
47+
// Whether tests for all components should be run.
48+
const all = components.length === 1 && components[0] === 'all';
5349

5450
// We can only run a single target with "--local". Running multiple targets within the
5551
// same Karma server is not possible since each test target runs isolated from the others.
56-
if (local && components.length > 1) {
52+
if (local && (components.length > 1 || all)) {
5753
console.error(chalk.red(
5854
'Unable to run multiple components tests in local mode. ' +
5955
'Only one component at a time can be run with "--local"'));
6056
process.exit(1);
6157
}
6258

63-
const bazelBinary = watch ? 'ibazel' : 'bazel';
64-
const bazelAction = local ? 'run' : 'test';
59+
const bazelBinary = `yarn -s ${watch ? 'ibazel' : 'bazel'}`;
6560
const testTargetName =
6661
`unit_tests_${local ? 'local' : firefox ? 'firefox-local' : 'chromium-local'}`;
62+
63+
// If `all` has been specified as component, we run tests for all components
64+
// in the repository. The `--firefox` flag can be still specified.
65+
if (all) {
66+
shelljs.exec(
67+
`${bazelBinary} test //src/... --test_tag_filters=-e2e,-browser:${testTargetName} ` +
68+
`--build_tag_filters=-browser:${testTargetName} --build_tests_only`);
69+
return;
70+
}
71+
72+
// Exit if no component has been specified.
73+
if (!components.length) {
74+
console.error(chalk.red(
75+
'No component specified. Please either specify individual components, or pass "all" ' +
76+
'in order to run tests for all components.'));
77+
console.info(chalk.yellow('Below are a few examples of how the script can be run:'));
78+
console.info(chalk.yellow(` - yarn test all`));
79+
console.info(chalk.yellow(` - yarn test cdk/overlay material/stepper`));
80+
console.info(chalk.yellow(` - yarn test button toolbar`));
81+
process.exit(1);
82+
}
83+
84+
const bazelAction = local ? 'run' : 'test';
6785
const testLabels = components.map(t => `${getBazelPackageOfComponentName(t)}:${testTargetName}`);
6886

6987
// Runs Bazel for the determined test labels.
70-
shelljs.exec(`yarn -s ${bazelBinary} ${bazelAction} ${testLabels.join(' ')}`);
88+
shelljs.exec(`${bazelBinary} ${bazelAction} ${testLabels.join(' ')}`);
7189

7290
/**
7391
* Gets the Bazel package label for the specified component name. Throws if

0 commit comments

Comments
 (0)