Skip to content

test_runner: preserve user flags in argv#61858

Open
Han5991 wants to merge 1 commit intonodejs:mainfrom
Han5991:fix/test-runner-argv
Open

test_runner: preserve user flags in argv#61858
Han5991 wants to merge 1 commit intonodejs:mainfrom
Han5991:fix/test-runner-argv

Conversation

@Han5991
Copy link
Contributor

@Han5991 Han5991 commented Feb 16, 2026

Fixes: #61852

This PR fixes an issue where user-specified flags were being stripped from process.argv when running with the --test flag.

Previously, the test runner treated all arguments as potential file patterns, ignoring flags that weren't specific to the test runner. This made it impossible to pass custom flags (e.g., --hello) to test files.

This change ensures that:

  1. Arguments following -- are correctly treated as user arguments.
  2. Arguments starting with - (that are not consumed by Node.js or the test runner) are preserved and passed to the test process.

Added new tests in test/parallel/test-runner-cli-args.js to verify:

  • Implicit flag passing: node --test fixture.js --hello
  • Explicit flag passing: node --test fixture.js -- --hello
  • Mixed usage: node --test fixture.js --hello -- world

This commit fixes an issue where user-specified flags were being

stripped from process.argv when running with the --test flag.

It ensures that arguments following '--' or starting with '-' (that are

not consumed by Node.js options) are correctly passed to the test

process.

Fixes: nodejs#61852
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/test_runner

@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Feb 16, 2026
@codecov
Copy link

codecov bot commented Feb 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.73%. Comparing base (4f13746) to head (24a021f).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #61858      +/-   ##
==========================================
+ Coverage   89.72%   89.73%   +0.01%     
==========================================
  Files         675      675              
  Lines      204806   204826      +20     
  Branches    39355    39358       +3     
==========================================
+ Hits       183761   183803      +42     
+ Misses      13330    13295      -35     
- Partials     7715     7728      +13     
Files with missing lines Coverage Δ
lib/internal/main/test_runner.js 100.00% <100.00%> (ø)

... and 35 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using --test causes process.argv[] to lose user-specified CLI flags

2 participants