From 29f8ac3f8f7afcd9bd18212cbf1746dd4be6041e Mon Sep 17 00:00:00 2001 From: Jeremy Elbourn Date: Mon, 9 Mar 2020 15:36:29 -0700 Subject: [PATCH] build: add support for common typos in `yarn test` --- scripts/run-component-tests.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/scripts/run-component-tests.js b/scripts/run-component-tests.js index d8171d1c9f22..beaf2c0ee5c8 100644 --- a/scripts/run-component-tests.js +++ b/scripts/run-component-tests.js @@ -34,6 +34,11 @@ const packagesDir = path.join(projectDir, 'src/'); // e.g. "button" will become "material/button", and "overlay" becomes "cdk/overlay". const orderedGuessPackages = ['material', 'cdk', 'material-experimental', 'cdk-experimental']; +/** Map of common typos in target names. The key is the typo, the value is the correct form. */ +const commonTypos = new Map([ + ['snackbar', 'snack-bar'], +]); + // ShellJS should exit if any command fails. shelljs.set('-e'); shelljs.cd(projectDir); @@ -82,7 +87,9 @@ if (!components.length) { } const bazelAction = local ? 'run' : 'test'; -const testLabels = components.map(t => `${getBazelPackageOfComponentName(t)}:${testTargetName}`); +const testLabels = components + .map(t => correctTypos(t)) + .map(t => `${getBazelPackageOfComponentName(t)}:${testTargetName}`); // Runs Bazel for the determined test labels. shelljs.exec(`${bazelBinary} ${bazelAction} ${testLabels.join(' ')}`); @@ -121,6 +128,16 @@ function convertPathToBazelLabel(name) { return null; } +/** Correct common typos in a target name */ +function correctTypos(target) { + let correctedTarget = target; + for (const [typo, correction] of commonTypos) { + correctedTarget = correctedTarget.replace(typo, correction); + } + + return correctedTarget; +} + /** Converts an arbitrary path to a Posix path. */ function convertPathToPosix(pathName) { return pathName.replace(/\\/g, '/');