14
14
* --local | If specified, no browser will be launched.
15
15
* --firefox | Instead of Chrome being used for tests, Firefox will be used.
16
16
* --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.
17
18
*/
18
19
19
20
const minimist = require ( 'minimist' ) ;
@@ -38,36 +39,51 @@ shelljs.set('-e');
38
39
shelljs . cd ( projectDir ) ;
39
40
40
41
// Extracts the supported command line options.
41
- const { _ : components , local, firefox, watch} = minimist ( args , {
42
- boolean : [ 'local' , 'firefox' , 'watch' ] ,
42
+ const { _ : components , local, firefox, watch, all } = minimist ( args , {
43
+ boolean : [ 'local' , 'firefox' , 'watch' , 'all' ] ,
43
44
default : { watch : true } ,
44
45
} ) ;
45
46
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
- }
53
-
54
47
// We can only run a single target with "--local". Running multiple targets within the
55
48
// same Karma server is not possible since each test target runs isolated from the others.
56
- if ( local && components . length > 1 ) {
49
+ if ( local && ( components . length > 1 || all ) ) {
57
50
console . error ( chalk . red (
58
51
'Unable to run multiple components tests in local mode. ' +
59
52
'Only one component at a time can be run with "--local"' ) ) ;
60
53
process . exit ( 1 ) ;
61
54
}
62
55
63
- const bazelBinary = watch ? 'ibazel' : 'bazel' ;
64
- const bazelAction = local ? 'run' : 'test' ;
56
+ const bazelBinary = `yarn -s ${ watch ? 'ibazel' : 'bazel' } ` ;
65
57
const testTargetName =
66
58
`unit_tests_${ local ? 'local' : firefox ? 'firefox-local' : 'chromium-local' } ` ;
59
+
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.
62
+ 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
+ shelljs . exec (
69
+ `${ bazelBinary } test //src/... --test_tag_filters=-e2e,-browser:${ testTargetName } ` +
70
+ `--build_tag_filters=-browser:${ testTargetName } --build_tests_only` ) ;
71
+ return ;
72
+ }
73
+
74
+ // Exit if no component has been specified.
75
+ if ( ! components . length ) {
76
+ console . error ( chalk . red (
77
+ 'No component specified. Specify a component name, or pass a ' +
78
+ 'path to the component directory.' ) ) ;
79
+ process . exit ( 1 ) ;
80
+ }
81
+
82
+ const bazelAction = local ? 'run' : 'test' ;
67
83
const testLabels = components . map ( t => `${ getBazelPackageOfComponentName ( t ) } :${ testTargetName } ` ) ;
68
84
69
85
// Runs Bazel for the determined test labels.
70
- shelljs . exec ( `yarn -s ${ bazelBinary } ${ bazelAction } ${ testLabels . join ( ' ' ) } ` ) ;
86
+ shelljs . exec ( `${ bazelBinary } ${ bazelAction } ${ testLabels . join ( ' ' ) } ` ) ;
71
87
72
88
/**
73
89
* Gets the Bazel package label for the specified component name. Throws if
@@ -89,8 +105,9 @@ function getBazelPackageOfComponentName(name) {
89
105
return guessTargetName ;
90
106
}
91
107
}
92
- throw Error ( chalk . red ( `Could not find test target for specified component: ` +
93
- `${ chalk . yellow ( name ) } . Looked in packages: ${ orderedGuessPackages . join ( ', ' ) } ` ) ) ;
108
+ throw Error ( chalk . red (
109
+ `Could not find test target for specified component: ` +
110
+ `${ chalk . yellow ( name ) } . Looked in packages: ${ orderedGuessPackages . join ( ', ' ) } ` ) ) ;
94
111
}
95
112
96
113
/** Converts a path to a Bazel label. */
0 commit comments