nodejs / nodejs/node

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

Open
#61,852 5 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
122k
Forks
37.3k
Avg merge
4d 2h
Merged PRs (30d)
283

Description

Version

v25.6.1

Platform
Darwin MacBookPro.lan 25.0.0 Darwin Kernel Version 25.0.0: Wed Sep 17 21:41:45 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T6000 arm64
Subsystem

node:test

What steps will reproduce the bug?

Create a file, "foo.js":

console.log(process.argv);

... then invoke node with a custom CLI flag (--hello), and both with and without the --test flag:

# Run script with a custom CLI flag (without --test):
$ node foo.js --hello
[
  '/Users/kieffer/.nvm/versions/node/v25.6.1/bin/node',
  '/Users/kieffer/codepen/codewatch/packages/foo.js',
  '--hello'
]

# ... now add `--test`:
$ node --test foo.js --hello
[
  '/Users/kieffer/.nvm/versions/node/v25.6.1/bin/node',
  '/Users/kieffer/codepen/codewatch/packages/foo.js'
]
✔ foo.js (35.9505ms)
<snip>

[!NOTE]
Running with the "--" flag (e.g. node foo.js -- --hello or node --test foo.js -- --hello) yields the same behavior.

How often does it reproduce? Is there a required condition?

Consistent.

What is the expected behavior? Why is that the expected behavior?

process.argv should include the user-provided CLI flag in both cases.

What do you see instead?

When running with --test, process.argv omits the user-supplied --hello flag.

This makes testing code that depends on process.argv problematic, obviously.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the foo.js reproduction and compare process.argv when running node foo.js --hello with node --test foo.js --hello. Trace how node:test handles script arguments, then add a regression test showing that --hello remains in process.argv and run the relevant test-runner tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.