Repository navigation
Method to run Node test-runner ignoring/rejecting any test.only/test(..., { only: true }, ... filters #60917
Description
Activity
- addedfeature requestIssues requesting new Node.js features.Issues requesting new Node.js features.
on Dec 1, 2025 - changed the title
[-]Method to run Node test-runner without any filters[/-][+]Method to run Node test-runner without any test (only) filters[/+]on Dec 1, 2025 - changed the title
[-]Method to run Node test-runner without any test (only) filters[/-][+]Method to run Node test-runner ignoring/rejecting any `test.only`/`test(..., { only: true }, ...` filters[/+]on Dec 1, 2025 - addedtest_runnerIssues and PRs related to the test runner subsystem.Issues and PRs related to the test runner subsystem.
on Dec 2, 2025 This issue has been marked as stale due to 210 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.- addedstaleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
on Jul 1, 2026 As far as I can tell, nothing has changed.
-
Configures the test runner to only execute top level tests that have the only option set. This flag is not necessary when test isolation is disabled.
-
Node 26.x
node:testTest Runn docsIf Node.js is started with the --test-only command-line option, or test isolation is disabled, it is possible to skip all tests except for a selected subset by passing the only option to the tests that should run. When a test with the only option is set, all subtests are also run. If a suite has the only option set, all tests within the suite are run, unless it has descendants with the only option set, in which case only those tests are run.
This feature request remains open and relevant.
Reacted by David Thornton-
- removedstaleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
on Jul 2, 2026 I believe I am also experiencing this behaviour. Is there any assistance I can render to address this issue?
- added a commit that references this issue
on Oct 8, 2026 github-actions commented
on Oct 10, 2026 on Oct 10, 2026 – with GitHub ActionsContributorMore actionsThis issue has been marked as stale due to 90 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.- addedstaleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
on Oct 10, 2026
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsAwaiting Triage
What is the problem this feature will solve?
Since the resolution of #47945,
node --testwill automatically filter tests which are not marked.only, ifonly: true--test-onlyis passed a command line flag--test-isolation=noneIn addition, since #51383, filtered tests/suites are not passed to test-reporters at all.
When developing locally, this is convenient. However, when running tests in CI, it means there is no way to detect whether or not test-filtering is occurring when
--test-isolation=none. This means it's possible for someone to accidentally push a.onlycall, which will silently disable the rest of the tests.It appears that this logic is defined here:
main: https://github.com/nodejs/node/blame/f9f343fb8dda773b749db4dee00704f8bbe79c19/lib/internal/test_runner/harness.js#L47which forces
isFilteringByOnlyto betruewhenglobalOptions.isolation === 'process' || process.env.NODE_TEST_CONTEXTisfalse(note that this presents a partial workaround for Node 24, but not Node 22 which is still supported until April 2027)What is the feature you are proposing to solve the problem?
A command-line option that allows running tests in a way that detects accidental inclusions of
{ only: true }/it.only/describe.only/ etc.additional
--test-onlyflag featuresI think the simplest & best option would be to introduce 2 new possible values for the
--test-onlyflag:--test-only/--test-only=true: The current behavior--test-only=false:{ only: true }, tests are NOT filtered out for having{ only: false }.--test-only=error:{ only: true }?{ only: true }?.onlyso the difference is probably negligible)onlytests in the stead of that test?only?onlyoverall (either before/after running all tests) or only at the end/beginning as a count of filtered tests only?additional test-reporter events
While I think
--test-only=error's behavior would generally be desirable to essentially all Node programs using thenode:testrunner when running tests in CI, configuration for it in different test-reporters may become complicated over time.A more customizable alternative would be to emit an additional event for filtered tests, which indicates what caused the test to be filtered. Handling of this event could be added to either custom-reporters, a new build-in test-reporter, or the existing test-reporters, to emit an error in the case that filtered test-cases are undesirable.
What alternatives have you considered?
From reading the documentation of test runners and the command-line arguments, it seems the current version of Node does not have a way to cause this kind of behavior when running the test runner via the
node --testCLI.Because filtered tests do not emit events to test-reporters (#51383), a custom test-reporter cannot be used to detect this.
I can see several ways to workaround this right now:
lint against
.only/{ only: true }invocations ofnode:testThis is probably the most straightforward, but it is very complex, and cannot be complete. It cannot detect non-textual references to these, for example, in the (admittedly undesirable) case these flags are computed dynamically, or tests are imported from another library.
(Node 24+) use the undocumented
NODE_TEST_CONTEXT=_workaroundIt seems this parameter is used for process-isolation; however, when not using process-isolation, it also triggers the branch that allows the
isFilteringByOnlyto default tofalse/undefinedin Node 24+.This seems likely unintentional and the behavior is documented to be unpredictable
This workaround does not support the
--test-only=erroruse case.enable test-isolation
Enabling process isolation for tests will effectively disable the
{ only: true }filtering logicThis workaround does not support the
--test-only=erroruse case.introduce a "canary" test to detect filtering
To ensure tests aren't filtered, I can introduce a dummy
test("ensure not filtered", () => {});and ensure that this test is reported.This mostly works, but it is indirect and incomplete. For example, if a
.onlycall is added to the canary test, any.onlycalls become allowed anywhere else.manually construct
runtests instead of using thenode --testCLIWhile the CLI does not seem to currently support the proposed
--test-only=falseflag, therunmethod exposed innode:testdoes:This workaround does not appear to support the
--test-only=erroruse case, although it may be possible