Skip to content

feat(collect-tests): expand .each and report accurate per-status counts - #16259

Open
alexander-turner wants to merge 11 commits into
jestjs:mainfrom
alexander-turner:claude/gracious-bell-mhlwjf
Open

feat(collect-tests): expand .each and report accurate per-status counts#16259
alexander-turner wants to merge 11 commits into
jestjs:mainfrom
alexander-turner:claude/gracious-bell-mhlwjf

Conversation

@alexander-turner

Copy link
Copy Markdown
Contributor

#16006 added --collectTests to report test counts without actually running (potentially heavy) tests. I enhanced the logic to report correctly in more situations:

  • test.each/describe.each expand to one entry per case
  • skip / describe.skip / focus-deselected / --testNamePattern-deselected → pending; test.todotodo; runnable → passed + new wouldRun flag

The tree also now annotates entries with[skipped]/[todo] and finishes with a summary line.

A suite with it.each([...10 cases...]), some test.skip and test.todo:

Before.each counted as 1, everything lumped as pending, no summary:

my.test.js
  cases
    runs all the rows
  skipped later
  todo me

After — cases expanded, statuses resolved, summary line:

my.test.js
  cases
    runs all the rows: case 1
    ...
    runs all the rows: case 10
  skipped later [skipped]
  todo me [todo]

Test suites: 1
Tests:       12 total, 10 runnable, 1 skipped, 1 todo

alexander-turner and others added 10 commits June 22, 2026 00:07
…s counts

`--collectTests` now categorizes each collected test exactly as a real run
would: runnable tests as `passed`, `test.skip` / focus-deselected tests as
`pending`, and `test.todo` as `todo`. `test.each`/`describe.each` cases were
already expanded at file-load time; this makes the reported counts
(numPassedTests/numPendingTests/numTodoTests/numTotalTests) match an actual
run, so the feature can be used to count tests without executing them.

Also adds a summary line ("Test suites:" / "Tests:") to the non-JSON output
and a shared `makeCollectedTestResult` helper in `@jest/test-result` used by
both the circus and jasmine2 collection paths.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SxLxB6jEJZjteeSJyphqJZ
Addresses two issues found in self-review:

- `--testNamePattern` no longer drops deselected tests from the collected
  counts. A real run reports pattern-deselected tests as pending, so they are
  now collected as `pending` too — making `numTotalTests` match a real run
  even when a pattern is supplied (previously the totals diverged).
- Selected-but-unexecuted tests are reported in the `passed` bucket (so the
  counts add up) but are now additionally flagged with a new
  `AssertionResult.wouldRun` field, so JSON consumers can distinguish "would
  run" from "actually passed" rather than the status silently implying the
  test ran.

Adds e2e parity coverage under `--testNamePattern` and unit coverage for the
new pending/wouldRun behaviour.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SxLxB6jEJZjteeSJyphqJZ
…rors

Two issues found in self-review of the human (non-JSON) collect output:

- The tree printed every collected test name with no status, so under
  `--testNamePattern` (or with skipped/todo tests) runnable and non-runnable
  tests looked identical. Skipped and todo entries are now annotated
  (`[skipped]`/`[todo]`); runnable tests stay bare.
- A test file that threw while loading was silently omitted: the tree showed
  only the healthy files and the summary gave no hint, despite a non-zero exit
  code. Such files are now printed with their error, and the summary reports
  how many suites failed to load.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SxLxB6jEJZjteeSJyphqJZ
Tighten the change without losing coverage:

- `makeCollectedTestResult` tallies via a small `count` helper instead of a
  switch.
- Consolidate e2e cases (parametrize the real-run parity test over
  unfiltered/`--testNamePattern`, fold redundant tree/JSON checks) and slim the
  circus/jasmine unit suites and the kitchenSink/focused fixtures.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SxLxB6jEJZjteeSJyphqJZ
`--collectTests` on the jasmine2 runner ignored `fit`/`fdescribe` focus, so
focus-deselected specs were reported as runnable instead of pending, making
collected counts diverge from a real run. Mirror jasmine's selection by
exposing the env's focused-runnable ids and applying the same enabled/disabled
precedence as `Spec.status` (focus-out and explicitly disabled specs collect as
pending). Also honor the `disabled` flag and restore sibling-order coverage.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GAFTg2RjfGahzhujmr55k3
`spec.disable()` has a single caller, gated on the same `testNamePattern` the
collection already re-derives via `testNamePatternRE`, so the separate
`disabled` branch could never select a spec the pattern path didn't. Remove the
field, branch, and its test; keep focus handling.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GAFTg2RjfGahzhujmr55k3
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SxLxB6jEJZjteeSJyphqJZ
Move the non-JSON collect rendering (per-file tree, failed-to-load reporting,
summary line) into an exported `printCollectedResults`, and unit-test it so the
output paths are covered without relying on e2e subprocesses.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SxLxB6jEJZjteeSJyphqJZ
Cover the per-status tally directly (it was only exercised through the built
package via the runners), so the collect-tests counting logic is measured.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SxLxB6jEJZjteeSJyphqJZ
The summary line bolds only the total count (`chalk.bold(numTotalTests)`),
so with colors enabled the output is `\x1b[1m3\x1b[22m total` and the
literal `toContain('3 total')` assertion fails. This surfaced as a
Windows-only CI failure where chalk detects color support. Strip ANSI
escapes before the summary assertions so the test is color-agnostic.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FYsdWss8a6bhnzXTS5uWgX
@netlify

netlify Bot commented Jun 22, 2026

Copy link
Copy Markdown

Deploy Preview for jestjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 10edf55
🔍 Latest deploy log https://app.netlify.com/projects/jestjs/deploys/6a420b5c29032d000863e84b
😎 Deploy Preview https://deploy-preview-16259--jestjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions Bot added the require-changelog If a PR does requires a changelog entry label Jun 22, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jun 22, 2026

Copy link
Copy Markdown

Open in StackBlitz

babel-jest

npm i https://pkg.pr.new/babel-jest@16259

babel-plugin-jest-hoist

npm i https://pkg.pr.new/babel-plugin-jest-hoist@16259

babel-preset-jest

npm i https://pkg.pr.new/babel-preset-jest@16259

create-jest

npm i https://pkg.pr.new/create-jest@16259

@jest/diff-sequences

npm i https://pkg.pr.new/@jest/diff-sequences@16259

expect

npm i https://pkg.pr.new/expect@16259

@jest/expect-utils

npm i https://pkg.pr.new/@jest/expect-utils@16259

jest

npm i https://pkg.pr.new/jest@16259

jest-changed-files

npm i https://pkg.pr.new/jest-changed-files@16259

jest-circus

npm i https://pkg.pr.new/jest-circus@16259

jest-cli

npm i https://pkg.pr.new/jest-cli@16259

jest-config

npm i https://pkg.pr.new/jest-config@16259

@jest/console

npm i https://pkg.pr.new/@jest/console@16259

@jest/core

npm i https://pkg.pr.new/@jest/core@16259

@jest/create-cache-key-function

npm i https://pkg.pr.new/@jest/create-cache-key-function@16259

jest-diff

npm i https://pkg.pr.new/jest-diff@16259

jest-docblock

npm i https://pkg.pr.new/jest-docblock@16259

jest-each

npm i https://pkg.pr.new/jest-each@16259

@jest/environment

npm i https://pkg.pr.new/@jest/environment@16259

jest-environment-jsdom

npm i https://pkg.pr.new/jest-environment-jsdom@16259

@jest/environment-jsdom-abstract

npm i https://pkg.pr.new/@jest/environment-jsdom-abstract@16259

jest-environment-node

npm i https://pkg.pr.new/jest-environment-node@16259

@jest/expect

npm i https://pkg.pr.new/@jest/expect@16259

@jest/fake-timers

npm i https://pkg.pr.new/@jest/fake-timers@16259

@jest/get-type

npm i https://pkg.pr.new/@jest/get-type@16259

@jest/globals

npm i https://pkg.pr.new/@jest/globals@16259

jest-haste-map

npm i https://pkg.pr.new/jest-haste-map@16259

jest-jasmine2

npm i https://pkg.pr.new/jest-jasmine2@16259

jest-leak-detector

npm i https://pkg.pr.new/jest-leak-detector@16259

jest-matcher-utils

npm i https://pkg.pr.new/jest-matcher-utils@16259

jest-message-util

npm i https://pkg.pr.new/jest-message-util@16259

jest-mock

npm i https://pkg.pr.new/jest-mock@16259

@jest/pattern

npm i https://pkg.pr.new/@jest/pattern@16259

jest-phabricator

npm i https://pkg.pr.new/jest-phabricator@16259

jest-regex-util

npm i https://pkg.pr.new/jest-regex-util@16259

@jest/reporters

npm i https://pkg.pr.new/@jest/reporters@16259

jest-resolve

npm i https://pkg.pr.new/jest-resolve@16259

jest-resolve-dependencies

npm i https://pkg.pr.new/jest-resolve-dependencies@16259

jest-runner

npm i https://pkg.pr.new/jest-runner@16259

jest-runtime

npm i https://pkg.pr.new/jest-runtime@16259

@jest/schemas

npm i https://pkg.pr.new/@jest/schemas@16259

jest-snapshot

npm i https://pkg.pr.new/jest-snapshot@16259

@jest/snapshot-utils

npm i https://pkg.pr.new/@jest/snapshot-utils@16259

@jest/source-map

npm i https://pkg.pr.new/@jest/source-map@16259

@jest/test-result

npm i https://pkg.pr.new/@jest/test-result@16259

@jest/test-sequencer

npm i https://pkg.pr.new/@jest/test-sequencer@16259

@jest/transform

npm i https://pkg.pr.new/@jest/transform@16259

@jest/types

npm i https://pkg.pr.new/@jest/types@16259

jest-util

npm i https://pkg.pr.new/jest-util@16259

jest-validate

npm i https://pkg.pr.new/jest-validate@16259

jest-watcher

npm i https://pkg.pr.new/jest-watcher@16259

jest-worker

npm i https://pkg.pr.new/jest-worker@16259

pretty-format

npm i https://pkg.pr.new/pretty-format@16259

commit: 10edf55

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

require-changelog If a PR does requires a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant