nodejs / nodejs/node

[Test Runner] `run()` ignores `testNamePatterns` / `testSkipPatterns` when `isolation: 'none'

オープン
#64,359 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
JavaScript
スター
122k
フォーク
37.3k
平均マージ
4日 2時間
マージ済み PR(30日)
283

説明

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 runner run() can filter tests by name with testNamePatterns (only run matching) and testSkipPatterns (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() describe testNamePatterns and testSkipPatterns plainly, with no "doesn't work under isolation" note.
  • The same options table explicitly says execArgv, argv, and inspectPort have "No effect if isolation is '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 a run() option — see the Run it section below for the exact commands.
  • So the filtering machinery works under 'none'; only the run() option path ignores it.
  • The flag must be present when the process starts. Pushing it onto process.execArgv at 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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず repro.mjs を a.test.mjs とともに実行し、run({ isolation: 'process' }) と run({ isolation: 'none' }) を比較します。次に、testNamePatterns と testSkipPatterns に対する node:test の run() オプションの経路を追跡し、'none' で両方のフィルターが機能することを示すリグレッションテストのカバレッジを追加します。その際、期待されるプロセス分離の動作を維持します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, node.js
領域
testing-qa
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
静か
明瞭さ
明確に書かれている
初心者へのやさしさ
55/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。