Title: Method to run Node test-runner ignoring/rejecting any `test.only`/`test(..., { only: true }, ...` filters · Issue #60917 · nodejs/node · GitHub
Open Graph Title: Method to run Node test-runner ignoring/rejecting any `test.only`/`test(..., { only: true }, ...` filters · Issue #60917 · nodejs/node
X Title: Method to run Node test-runner ignoring/rejecting any `test.only`/`test(..., { only: true }, ...` filters · Issue #60917 · nodejs/node
Description: What is the problem this feature will solve? Since the resolution of #47945, node --test will automatically filter tests which are not marked .only, if any test/suite is marked with only: true AND --test-only is passed a command line fla...
Open Graph Description: What is the problem this feature will solve? Since the resolution of #47945, node --test will automatically filter tests which are not marked .only, if any test/suite is marked with only: true AND ...
X Description: What is the problem this feature will solve? Since the resolution of #47945, node --test will automatically filter tests which are not marked .only, if any test/suite is marked with only: true AND ...
Opengraph URL: https://github.com/nodejs/node/issues/60917
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Method to run Node test-runner ignoring/rejecting any `test.only`/`test(..., { only: true }, ...` filters","articleBody":"### What is the problem this feature will solve?\n\nSince the resolution of #47945, `node --test` will automatically filter tests which are not marked `.only`, if\n\n* any test/suite is marked with `only: true`\n* AND \n * `--test-only` is passed a command line flag\n * OR process-isolation is disabled by `--test-isolation=none`\n\nIn addition, since #51383, _filtered_ tests/suites are not passed to test-reporters at all.\n\nWhen 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`.only` call, which will silently disable the rest of the tests.\n\nIt _appears_ that this logic is defined here:\n\n* 24 (current LTS): https://github.com/nodejs/node/blob/v24.x/lib/internal/test_runner/harness.js#L47\n* current `main`: https://github.com/nodejs/node/blame/f9f343fb8dda773b749db4dee00704f8bbe79c19/lib/internal/test_runner/harness.js#L47\n\nwhich forces `isFilteringByOnly` to be `true` when `globalOptions.isolation === 'process' || process.env.NODE_TEST_CONTEXT` is `false` (note that this presents a partial workaround for Node 24, but not Node 22 which is still supported until April 2027)\n\n### What is the feature you are proposing to solve the problem?\n\nA command-line option that allows running tests in a way that detects accidental inclusions of `{ only: true }` / `it.only` / `describe.only` / etc.\n\n#### additional `--test-only` flag features\n\nI think the simplest & best option would be to introduce 2 new possible values for the `--test-only` flag:\n\n* `--test-only` / `--test-only=true`: The current behavior\n* `--test-only=false`:\n * Runs all tests; even if some other tests are marked with `{ only: true }`, tests are NOT filtered out for having `{ only: false }`.\n * Other filtering (from name patterns) still occurs as normal.\n* `--test-only=error`:\n * I think there are several reasonable semantics for this mode, which I don't have strong opinions between:\n * Should it generate an error...\n * ...when the tests are collected?\n * ...when the tests are run?\n * ...after the tests are run?\n * Should it report an error...\n * ....if any test/suite specified `{ only: true }`?\n * ...if a test is _filtered_ because it _didn't_ specify `{ only: true }`?\n * (The difference is only in test-suites that mark EVERY test as `.only` so the difference is probably negligible)\n * Should it run the tests as normal?\n * Should it report an error for filtered/`only` tests _in the stead of_ that test?\n * Or should it report a separate \"sub test\" regarding the unexpected use of `only`?\n * Should it report the unexpected use of `only` overall (either before/after running all tests) or only at the end/beginning as a count of filtered tests only?\n\n#### additional test-reporter events\n\nWhile I think `--test-only=error`'s behavior would generally be desirable to essentially all Node programs using the `node:test` runner when running tests in CI, configuration for it in different test-reporters may become complicated over time.\n\nA 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.\n\n\n### What alternatives have you considered?\n\nFrom reading the documentation of [test runners](https://nodejs.org/api/test.html) and the [command-line arguments](https://nodejs.org/api/cli.html), 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 --test` CLI.\n\nBecause filtered tests do not emit events to test-reporters (#51383), a custom test-reporter cannot be used to detect this.\n\nI can see several ways to workaround this right now:\n\n#### lint against `.only` / `{ only: true }` invocations of `node:test`\n\nThis 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.\n\n#### (Node 24+) use the undocumented `NODE_TEST_CONTEXT=_` workaround\n\nIt seems this parameter is used for process-isolation; however, when not using process-isolation, it also triggers the branch that allows the `isFilteringByOnly` to default to `false`/`undefined` in Node 24+.\n\nThis seems likely unintentional and the behavior is [documented to be unpredictable](https://nodejs.org/api/cli.html#node_test_contextvalue)\n\nThis workaround does not support the `--test-only=error` use case.\n\n#### enable test-isolation\n\nEnabling process isolation for tests will effectively disable the `{ only: true }` filtering logic\n\nThis workaround does not support the `--test-only=error` use case.\n\n#### introduce a \"canary\" test to detect filtering\n\nTo ensure tests aren't filtered, I can introduce a dummy `test(\"ensure not filtered\", () => {});` and ensure that this test is reported.\n\nThis mostly works, but it is indirect and incomplete. For example, if a `.only` call is added to the canary test, any `.only` calls become allowed anywhere else.\n\n#### manually construct `run` tests instead of using the `node --test` CLI\n\nWhile the CLI does not seem to currently support the proposed `--test-only=false` flag, the `run` method exposed in `node:test` does:\n\n```js\n// Only seems to work in Node 22?\nimport nodeTest from \"node:test\";\nimport { spec } from \"node:test/reporters\";\n\nnodeTest\n .run({\n concurrency: false,\n globPatterns: [\"dist/**/*.spec.js\"],\n isolation: \"none\",\n coverage: false,\n /** Milliseconds */\n timeout: 90_000,\n })\n .compose(spec)\n .pipe(process.stdout);\n```\n\nThis workaround does not appear to support the `--test-only=error` use case, although it may be possible","author":{"url":"https://github.com/curtisfennergivery","@type":"Person","name":"curtisfennergivery"},"datePublished":"2025-12-01T07:49:34Z","url":"https://github.com/nodejs/node/issues/60917"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:96d0618c-f68a-be44-a8d5-39d3a1e39037 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 85B2:2E7DFB:2C1BD98:3A4FCF9:6B033857 |
| html-safe-nonce | 4a95075480aae0bf4dce34fa2b52580e50136e96dd3d7c77ac07473cb06790ed |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NUIyOjJFN0RGQjoyQzFCRDk4OjNBNEZDRjk6NkIwMzM4NTciLCJ2aXNpdG9yX2lkIjoiNjYyMDkzNDQ2MjE3MzgyMTAxNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a94ffeb3a3c3124002e81dc4b8a389a06e5f108de9a1754901231b5eebb512ea |
| hovercard-subject-tag | issue:3679718112 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/60917/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8a92f2b524adf7e48550ae96e28a13a8f364c022a4cdd205b16113df52336017/nodejs/node/issues/60917 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8a92f2b524adf7e48550ae96e28a13a8f364c022a4cdd205b16113df52336017/nodejs/node/issues/60917 |
| og:image:alt | What is the problem this feature will solve? Since the resolution of #47945, node --test will automatically filter tests which are not marked .only, if any test/suite is marked with only: true AND ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | curtisfennergivery |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width