Skip to content

Commit 47af01f

Browse files
authored
build: add support for common typos in yarn test (#18770)
1 parent b91e88f commit 47af01f

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

scripts/run-component-tests.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ const packagesDir = path.join(projectDir, 'src/');
3434
// e.g. "button" will become "material/button", and "overlay" becomes "cdk/overlay".
3535
const orderedGuessPackages = ['material', 'cdk', 'material-experimental', 'cdk-experimental'];
3636

37+
/** Map of common typos in target names. The key is the typo, the value is the correct form. */
38+
const commonTypos = new Map([
39+
['snackbar', 'snack-bar'],
40+
]);
41+
3742
// ShellJS should exit if any command fails.
3843
shelljs.set('-e');
3944
shelljs.cd(projectDir);
@@ -82,7 +87,9 @@ if (!components.length) {
8287
}
8388

8489
const bazelAction = local ? 'run' : 'test';
85-
const testLabels = components.map(t => `${getBazelPackageOfComponentName(t)}:${testTargetName}`);
90+
const testLabels = components
91+
.map(t => correctTypos(t))
92+
.map(t => `${getBazelPackageOfComponentName(t)}:${testTargetName}`);
8693

8794
// Runs Bazel for the determined test labels.
8895
shelljs.exec(`${bazelBinary} ${bazelAction} ${testLabels.join(' ')}`);
@@ -121,6 +128,16 @@ function convertPathToBazelLabel(name) {
121128
return null;
122129
}
123130

131+
/** Correct common typos in a target name */
132+
function correctTypos(target) {
133+
let correctedTarget = target;
134+
for (const [typo, correction] of commonTypos) {
135+
correctedTarget = correctedTarget.replace(typo, correction);
136+
}
137+
138+
return correctedTarget;
139+
}
140+
124141
/** Converts an arbitrary path to a Posix path. */
125142
function convertPathToPosix(pathName) {
126143
return pathName.replace(/\\/g, '/');

0 commit comments

Comments
 (0)