Skip to content

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

@broofa

Description

@broofa

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 without and with the --test flag:

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

# ... now add the `--test` fla
$ 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions