From 1cff51ccabc7490339831223e15b133a7ca2ccfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Victor?= Date: Wed, 7 Oct 2026 17:47:56 -0300 Subject: [PATCH 1/3] test_runner: add option to forbid exclusive tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add --test-forbid-only and the forbidOnly run() option to detect accidentally committed exclusive tests. Reject only declarations and runOnly(true) in both isolation modes, and record a run-level failure so TODO and expected failures cannot absorb the error. Document the runtime-only detection and add regression coverage for filtering, option inheritance, both isolation modes, and disabled guards. Refs: https://github.com/nodejs/node/issues/60917 Assisted-by: a coding agent Signed-off-by: João Victor --- doc/api/cli.md | 17 +++ doc/api/test.md | 12 ++ doc/node.1 | 12 ++ lib/internal/test_runner/runner.js | 13 ++ lib/internal/test_runner/test.js | 15 +++ lib/internal/test_runner/utils.js | 2 + src/node_options.cc | 6 + src/node_options.h | 1 + test/parallel/test-runner-forbid-only.js | 149 +++++++++++++++++++++++ 9 files changed, 227 insertions(+) create mode 100644 test/parallel/test-runner-forbid-only.js diff --git a/doc/api/cli.md b/doc/api/cli.md index 3822685d3d50..b9f6de0b8169 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -3222,6 +3222,22 @@ added: v22.8.0 Require a minimum percent of covered lines. If code coverage does not reach the threshold specified, the process will exit with code `1`. +### `--test-forbid-only` + + + +Fails the test run if a test or suite is declared with `only: true`, including +the `test.only()`, `it.only()`, `suite.only()`, and `describe.only()` shorthands, +or if `testContext.runOnly(true)` is called. This is useful in CI to prevent +accidentally committing exclusive tests that exclude the rest of a test suite. + +This option applies with either test isolation mode and takes precedence over +`--test-only`. Name filtering, TODO markers, and expected failures do not suppress +detected violations. Only declarations evaluated during the run are checked; +code inside a skipped test callback is not evaluated. + ### `--test-force-exit`