|
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
|
@@ -43,31 +44,48 @@ const {_: components, local, firefox, watch} = minimist(args, {
|
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 |
| -} |
| 47 | +// Whether tests for all components should be run. |
| 48 | +const all = components.length === 1 && components[0] === 'all'; |
53 | 49 |
|
54 | 50 | // We can only run a single target with "--local". Running multiple targets within the
|
55 | 51 | // 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)) { |
57 | 53 | console.error(chalk.red(
|
58 | 54 | 'Unable to run multiple components tests in local mode. ' +
|
59 | 55 | 'Only one component at a time can be run with "--local"'));
|
60 | 56 | process.exit(1);
|
61 | 57 | }
|
62 | 58 |
|
63 |
| -const bazelBinary = watch ? 'ibazel' : 'bazel'; |
64 |
| -const bazelAction = local ? 'run' : 'test'; |
| 59 | +const bazelBinary = `yarn -s ${watch ? 'ibazel' : 'bazel'}`; |
65 | 60 | const testTargetName =
|
66 | 61 | `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'; |
67 | 85 | const testLabels = components.map(t => `${getBazelPackageOfComponentName(t)}:${testTargetName}`);
|
68 | 86 |
|
69 | 87 | // Runs Bazel for the determined test labels.
|
70 |
| -shelljs.exec(`yarn -s ${bazelBinary} ${bazelAction} ${testLabels.join(' ')}`); |
| 88 | +shelljs.exec(`${bazelBinary} ${bazelAction} ${testLabels.join(' ')}`); |
71 | 89 |
|
72 | 90 | /**
|
73 | 91 | * Gets the Bazel package label for the specified component name. Throws if
|
|
0 commit comments