[Test Runner] `run()` ignores `testNamePatterns` / `testSkipPatterns` when `isolation: 'none'
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 122k
- 派生
- 37.4k
- 平均合并
- 4 天 3 小时
- 30 天内合并 PR
- 272
描述
Version
Latest v26.5.0, but also v24 and v22
Platform
Linux
Subsystem
No response
What steps will reproduce the bug?
How to reproduce
Create these two files in the same folder (no dependencies):
a.test.mjs
import { test } from "node:test";
test("keep_alpha", () => {});
test("drop_beta", () => {});
repro.mjs
import { run } from "node:test";
const files = ["./a.test.mjs"];
// Run the same name filter and return the names of the tests that actually ran.
async function main(isolation) {
const names = [];
for await (const e of run({ files, isolation, testNamePatterns: ["keep"] })) {
if (e.type === "test:pass" || e.type === "test:fail")
names.push(e.data.name);
}
return names.sort();
}
console.log("process:", await main("process")); // expect only keep_alpha
console.log("none: ", await main("none")); // expect only keep_alpha
process.exit(0);
Command (run from that folder):
node repro.mjs
Expected result:
process: [ 'keep_alpha' ]
none: [ 'keep_alpha' ]
Actual result:
process: [ 'keep_alpha' ] <- correct: filter applied
none: [ 'drop_beta', 'keep_alpha' ] <- BUG: filter ignored, drop_beta ran
The same filter works as a CLI flag under isolation: none
Command (run from that folder):
node --test --experimental-test-isolation=none --test-name-pattern=keep a.test.mjs
Expected result: only keep_alpha runs — drop_beta is correctly filtered out even though isolation is none:
✔ keep_alpha
ℹ tests 1
ℹ pass 1
ℹ skipped 0
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
testNamePatterns in run method should work also when isolation is set to none, not only when it is set to process
What do you see instead?
The testNamePatterns is NOT applied
Additional information
TL;DR
node:test's programmatic runnerrun()can filter tests by name withtestNamePatterns(only run matching) andtestSkipPatterns(skip matching).- Those two options do nothing when you pass
isolation: 'none'. Every test runs, filter or not. - With the default
isolation: 'process', the exact same options work fine. Only'none'is broken.
Why this is a bug, not intended behavior
- The docs for
run()describetestNamePatternsandtestSkipPatternsplainly, with no "doesn't work under isolation" note. - The same options table explicitly says
execArgv,argv, andinspectPorthave "No effect ifisolationis'none'." — but says nothing like that for the two pattern options. - So the docs promise these filters work everywhere. Under
'none', they don't.
Extra clue: the runtime can do this under 'none'
- The same filtering works under
'none'when requested as a startup flag (--test-name-pattern/--test-skip-pattern) instead of arun()option — see the Run it section below for the exact commands. - So the filtering machinery works under
'none'; only therun()option path ignores it. - The flag must be present when the process starts. Pushing it onto
process.execArgvat runtime does nothing.
NOTE
This seems like a duplicate of https://github.com/nodejs/node/issues/57399, but this issue has not been fixed, apparently.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先使用 a.test.mjs 运行 repro.mjs,并比较 run({ isolation: 'process' }) 与 run({ isolation: 'none' })。然后跟踪 node:test 中针对 testNamePatterns 和 testSkipPatterns 的 run() 选项路径,并添加回归覆盖,表明两个过滤器在 'none' 下都能正常工作,同时保留预期的进程隔离行为。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, node.js
- 领域
- testing-qa
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 冷清
- 描述清晰度
- 描述清楚
- 新手友好度
- 55/100