Skip to content

build: add support for common typos in yarn test #18770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion scripts/run-component-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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(' ')}`);
Expand Down Expand Up @@ -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, '/');
Expand Down