4
4
* Script that simplifies the workflow of running unit tests for a component
5
5
* using Bazel. Here are a few examples:
6
6
*
7
+ * node ./scripts/run-component-tests all | Runs tests for all components
7
8
* node ./scripts/run-component-tests button | Runs Material button tests
8
9
* node ./scripts/run-component-tests overlay | Runs CDK overlay tests
9
10
* node ./scripts/run-component-tests src/cdk/a11y | Runs CDK a11y tests
14
15
* --local | If specified, no browser will be launched.
15
16
* --firefox | Instead of Chrome being used for tests, Firefox will be used.
16
17
* --no-watch | Watch mode is enabled by default. This flag opts-out to standard Bazel.
17
- * --all | Runs tests for all components in the project.
18
18
*/
19
19
20
20
const minimist = require ( 'minimist' ) ;
@@ -39,11 +39,14 @@ shelljs.set('-e');
39
39
shelljs . cd ( projectDir ) ;
40
40
41
41
// Extracts the supported command line options.
42
- const { _ : components , local, firefox, watch, all } = minimist ( args , {
43
- boolean : [ 'local' , 'firefox' , 'watch' , 'all' ] ,
42
+ const { _ : components , local, firefox, watch} = minimist ( args , {
43
+ boolean : [ 'local' , 'firefox' , 'watch' ] ,
44
44
default : { watch : true } ,
45
45
} ) ;
46
46
47
+ // Whether tests for all components should be run.
48
+ const all = components . length === 1 && components [ 0 ] === 'all' ;
49
+
47
50
// We can only run a single target with "--local". Running multiple targets within the
48
51
// same Karma server is not possible since each test target runs isolated from the others.
49
52
if ( local && ( components . length > 1 || all ) ) {
@@ -57,14 +60,9 @@ const bazelBinary = `yarn -s ${watch ? 'ibazel' : 'bazel'}`;
57
60
const testTargetName =
58
61
`unit_tests_${ local ? 'local' : firefox ? 'firefox-local' : 'chromium-local' } ` ;
59
62
60
- // If the `-- all` flag has been specified, we run tests for all components in the
61
- // repository. The `--firefox` flag can be still specified.
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.
62
65
if ( all ) {
63
- if ( components . length ) {
64
- console . error (
65
- chalk . red ( 'Script cannot be run with `--all` if individual components are specified.' ) ) ;
66
- process . exit ( 1 ) ;
67
- }
68
66
shelljs . exec (
69
67
`${ bazelBinary } test //src/... --test_tag_filters=-e2e,-browser:${ testTargetName } ` +
70
68
`--build_tag_filters=-browser:${ testTargetName } --build_tests_only` ) ;
@@ -74,10 +72,10 @@ if (all) {
74
72
// Exit if no component has been specified.
75
73
if ( ! components . length ) {
76
74
console . error ( chalk . red (
77
- 'No component specified. Please either specify individual components, or pass the "-- all" ' +
78
- 'flag in order to run tests for all components.' ) ) ;
75
+ 'No component specified. Please either specify individual components, or pass " all" ' +
76
+ 'in order to run tests for all components.' ) ) ;
79
77
console . info ( chalk . yellow ( 'Below are a few examples of how the script can be run:' ) ) ;
80
- console . info ( chalk . yellow ( ` - yarn test -- all` ) ) ;
78
+ console . info ( chalk . yellow ( ` - yarn test all` ) ) ;
81
79
console . info ( chalk . yellow ( ` - yarn test cdk/overlay material/stepper` ) ) ;
82
80
console . info ( chalk . yellow ( ` - yarn test button toolbar` ) ) ;
83
81
process . exit ( 1 ) ;
0 commit comments