nodejs / nodejs/node

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

未关闭
#61,852 5 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
JavaScript
星标
122k
派生
37.3k
平均合并
4 天 2 小时
30 天内合并 PR
283

描述

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.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 foo.js 的复现开始,比较运行 node foo.js --hello 和 node --test foo.js --hello 时的 process.argv。追踪 node:test 如何处理脚本参数,然后添加一个回归测试,证明 --hello 仍保留在 process.argv 中,并运行相关的 test-runner 测试。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, node.js
领域
testing
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
58/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。