Skip to content

test: reproduce issue with short option (alias) and = - #230

Merged
pi0 merged 6 commits into
unjs:mainfrom
OrbisK:test/alias-equal
Mar 15, 2026
Merged

pi0 merged 6 commits into
unjs:mainfrom
OrbisK:test/alias-equal

Conversation

@OrbisK

@OrbisK OrbisK commented Mar 6, 2026 •

Copy link
Copy Markdown
Contributor

This test reproduces nuxt/nuxt#34430 / #237

Summary by CodeRabbit

  • Tests
    • Added tests verifying parsing of command-line arguments using assignment syntax (e.g., --arg=value), ensuring correct name/value extraction.
    • Added tests confirming short-form aliases with assignment syntax (e.g., -a=value) are recognized and expanded to full option names, producing both alias and full-name mappings.
    • Coverage is additive; no existing behavior or public interfaces were changed.

@OrbisK OrbisK changed the title test: reproduce issue with alias and test: reproduce issue with alias and = Mar 6, 2026
@coderabbitai

coderabbitai Bot commented Mar 6, 2026 •

Copy link
Copy Markdown

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds two unit tests for parseRawArgs: one verifies --name=value parses into the argument name; the other verifies -a=value alias parsing maps the value to both the alias and the full argument name. No source code or public API changes.

Changes

Cohort / File(s) Summary
Parser Test Coverage
test/parser.test.ts
Added two tests for parseRawArgs: one validates --<arg>=<value> parsing to the argument name; the other validates -<alias>=<value> maps the value to both alias and full argument name.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Poem

🐇 I hopped through tests with nimble feet,
Two tiny cases, tidy and neat.
Dashes meet equals, values set free,
Alias and name now sip tea with me. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding tests that reproduce an issue with short option aliases and the equals sign syntax.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread test/parser.test.ts Outdated
})
})

it('handles -<arg>=<value> with alias', ()=>{

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('handles -<arg>=<value> with alias', ()=>{
it.fails('handles -<arg>=<value> with alias', ()=>{

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (3)
test/parser.test.ts (3)

63-64: Remove extra blank lines.

Two consecutive blank lines were added between tests. One blank line is sufficient for separation, consistent with the rest of the file.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/parser.test.ts` around lines 63 - 64, There are two consecutive blank
lines between tests in test/parser.test.ts; remove the extra blank line so there
is only a single blank line separating test blocks to match the file's existing
spacing conventions and keep consistent separation between tests.

18-27: Test looks correct, but formatting is inconsistent with existing tests.

The test for --name=John syntax correctly validates the expected parsing behavior. However, the formatting differs from other tests in this file (e.g., missing spaces around arrow function ()=>{ vs () => {, missing semicolons).

♻️ Suggested formatting for consistency
-  it('handles --<arg>=<value>', ()=>{
-    const result = parseRawArgs(["--name=John"], {
-      string: ["name"]
-    });
+  it("handles --<arg>=<value>", () => {
+    const result = parseRawArgs(["--name=John"], {
+      string: ["name"],
+    });
 
     expect(result).toEqual({
       _: [],
-      name: "John"
-    })
-  })
+      name: "John",
+    });
+  });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/parser.test.ts` around lines 18 - 27, The test for 'handles
--<arg>=<value>' is functionally correct but inconsistent with the project's
test formatting; update the test that calls parseRawArgs to match the file's
style by adding spaces around the arrow function (use "() => { ... }"), ensure
statement terminators (semicolons) are present where other tests use them, and
follow the same brace/spacing conventions as neighboring tests so the test
description, the call to parseRawArgs, and the expect(...) block use consistent
spacing and semicolons.

29-42: Reproduction test expected to fail - consider marking it appropriately.

Based on the relevant context snippets, Node.js's parseArgs does not properly handle -short=value format. For -n=John, it returns the value as "=John" (including the equals sign). The alias propagation logic cannot fix this malformed value.

Since this is a reproduction test for the linked issue (nuxt/nuxt#34430), consider:

  1. Marking the test with it.fails() or it.skip() to document it's a known failing case until fixed
  2. Adding a comment referencing the issue being reproduced
📝 Suggested approach to mark as known failing test
-  it('handles -<arg>=<value> with alias', ()=>{
+  // Reproduces https://github.com/nuxt/nuxt/issues/34430
+  it.fails("handles -<arg>=<value> with alias", () => {
     const result = parseRawArgs(["-n=John"], {
       string: ["name"],
       alias: {
-        n: ["name"]
-      }
-    })
+        n: ["name"],
+      },
+    });
 
     expect(result).toEqual({
       _: [],
       n: "John",
       name: "John",
-    })
-  })
+    });
+  });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/parser.test.ts` around lines 29 - 42, This test is a known reproduction
of a Node.js parseArgs bug where "-n=John" yields a malformed value; update the
test case in parser.test.ts (the "handles -<arg>=<value> with alias" spec that
calls parseRawArgs) to mark it as a known failing case (e.g., change it(...) to
it.fails(...) or it.skip(...)) and add a short inline comment referencing the
upstream issue (nuxt/nuxt#34430) so it’s clear this is an intentional
reproduction until parseRawArgs or the alias handling in parseRawArgs is fixed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@test/parser.test.ts`:
- Around line 63-64: There are two consecutive blank lines between tests in
test/parser.test.ts; remove the extra blank line so there is only a single blank
line separating test blocks to match the file's existing spacing conventions and
keep consistent separation between tests.
- Around line 18-27: The test for 'handles --<arg>=<value>' is functionally
correct but inconsistent with the project's test formatting; update the test
that calls parseRawArgs to match the file's style by adding spaces around the
arrow function (use "() => { ... }"), ensure statement terminators (semicolons)
are present where other tests use them, and follow the same brace/spacing
conventions as neighboring tests so the test description, the call to
parseRawArgs, and the expect(...) block use consistent spacing and semicolons.
- Around line 29-42: This test is a known reproduction of a Node.js parseArgs
bug where "-n=John" yields a malformed value; update the test case in
parser.test.ts (the "handles -<arg>=<value> with alias" spec that calls
parseRawArgs) to mark it as a known failing case (e.g., change it(...) to
it.fails(...) or it.skip(...)) and add a short inline comment referencing the
upstream issue (nuxt/nuxt#34430) so it’s clear this is an intentional
reproduction until parseRawArgs or the alias handling in parseRawArgs is fixed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 78f2fb6e-bc82-48f3-a8ae-4c37f90f9e6c

📥 Commits

Reviewing files that changed from the base of the PR and between 29dfd29 and 75b043e.

📒 Files selected for processing (1)
  • test/parser.test.ts

Comment thread test/parser.test.ts Resolved
@OrbisK OrbisK changed the title test: reproduce issue with alias and = test: reproduce issue with short option (alias) and = Mar 7, 2026
@OrbisK

OrbisK commented Mar 7, 2026 •

Copy link
Copy Markdown
Contributor Author

FWIW: This seems to be native node parseArgs behavior. (maybe wont-fix)

Comment thread test/parser.test.ts Resolved
@pi0

pi0 commented Mar 15, 2026

Copy link
Copy Markdown
Member

I guess we need to revert back from node arg parser to allow -foo=bar. Have to do little more research how standard is this convention.

Do you mind to please convert it to an issue to track @OrbisK ? 🙏🏼

Comment thread test/parser.test.ts Resolved
Comment thread test/parser.test.ts Resolved
@OrbisK

OrbisK commented Mar 15, 2026

Copy link
Copy Markdown
Contributor Author

I have added the issue and prepared this pr so it includes the reproduction as failing test, so it is mergeable if needed.

@pi0 pi0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thnx!

Comment thread test/parser.test.ts Resolved
@shadowspawn

Copy link
Copy Markdown

For interest, supporting short option and = was considered during parseArgs development, but not added:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants