Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

fix: support `--X` one-char aliases (#6391)

Mark Wiemer12279398f989
diff --git a/lib/cli/parse-args.js b/lib/cli/parse-args.js
index 41fa3198..56ae26c8 100644
--- a/lib/cli/parse-args.js
+++ b/lib/cli/parse-args.js
@@ -174,7 +174,11 @@ const preprocessArgs = (allArgs) => {
const negated = name.startsWith("no-");
const prefix = arg.startsWith("--") ? "--" : arg.startsWith("-") ? "-" : "";
- if (!prefix || name === canonical || name.length === 1) {
+ if (
+ !prefix ||
+ name === canonical ||
+ (prefix === "-" && name.length === 1)
+ ) {
return arg;
}
diff --git a/test/node-unit/cli/parse-args.spec.js b/test/node-unit/cli/parse-args.spec.js
index 8d13a625..cd485437 100644
--- a/test/node-unit/cli/parse-args.spec.js
+++ b/test/node-unit/cli/parse-args.spec.js
@@ -42,6 +42,15 @@ describe("parse-args", function () {
});
});
+ it("canonicalizes single-character aliases with a long-option prefix", function () {
+ [["--t", "0"], ["--t=0"]].forEach((args) => {
+ expect(parseMochaArgs(args, defaults), "to satisfy", {
+ _: [],
+ timeout: "0",
+ });
+ });
+ });
+
it("uses the last value for repeated scalar options across aliases", function () {
expect(
parseMochaArgs(["--timeout", "100", "-t", "10"], defaults),