Add --collectOnly flag to list tests without running them#16006
Open
alexander-turner wants to merge 3 commits intojestjs:mainfrom
Open
Add --collectOnly flag to list tests without running them#16006alexander-turner wants to merge 3 commits intojestjs:mainfrom
--collectOnly flag to list tests without running them#16006alexander-turner wants to merge 3 commits intojestjs:mainfrom
Conversation
✅ Deploy Preview for jestjs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
babel-jest
babel-plugin-jest-hoist
babel-preset-jest
create-jest
@jest/diff-sequences
expect
@jest/expect-utils
jest
jest-changed-files
jest-circus
jest-cli
jest-config
@jest/console
@jest/core
@jest/create-cache-key-function
jest-diff
jest-docblock
jest-each
@jest/environment
jest-environment-jsdom
@jest/environment-jsdom-abstract
jest-environment-node
@jest/expect
@jest/fake-timers
@jest/get-type
@jest/globals
jest-haste-map
jest-jasmine2
jest-leak-detector
jest-matcher-utils
jest-message-util
jest-mock
@jest/pattern
jest-phabricator
jest-regex-util
@jest/reporters
jest-resolve
jest-resolve-dependencies
jest-runner
jest-runtime
@jest/schemas
jest-snapshot
@jest/snapshot-utils
@jest/source-map
@jest/test-result
@jest/test-sequencer
@jest/transform
@jest/types
jest-util
jest-validate
jest-watcher
jest-worker
pretty-format
commit: |
alexander-turner
added a commit
to alexander-turner/jest
that referenced
this pull request
Mar 27, 2026
- Fix bug: stack-based (LIFO) traversal reversed describe block order; switch back to recursive traversal to preserve source order - Fix CHANGELOG link: point to jestjs#16006 not fork PR - Disable coverage collection in collectOnly mode (wasted work) - Add "preserves source order" regression test - Tighten unit tests: simplify helper, remove over-assertions, extract collect() shorthand, reduce from 111 to 96 lines https://claude.ai/code/session_018SbTXFCAujDRRjBFtMTFXU
Add a new CLI flag that loads test files and registers all describe/test/it blocks, then prints a tree showing discovered tests without running them. - Circus adapter returns collected results with pending status when collectOnly is set, using getTestID for testNamePattern filtering - runJest.ts prints test tree via VerboseReporter.groupTestsBySuites and delegates JSON/file output to existing processResults - Supports --testNamePattern filtering and --json output - Exits with code 0 regardless of test count - Disables coverage collection (unnecessary without execution) https://claude.ai/code/session_018SbTXFCAujDRRjBFtMTFXU
fc5fefe to
44b35ce
Compare
Member
|
Thanks for the PR! we have |
Rename from --collectOnly to --collectTests for consistency with the existing --listTests flag. The flag loads test files and registers all describe/test/it blocks, prints a tree of discovered tests, and exits with code 0. - Circus adapter returns collected results with pending status, filtering by testNamePattern via existing getTestID utility - runJest prints test tree via VerboseReporter.groupTestsBySuites and delegates JSON/file output to existing processResults - Coverage collection disabled (unnecessary without execution) https://claude.ai/code/session_018SbTXFCAujDRRjBFtMTFXU
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
--collectOnlyflag discovers and reports all test cases without executing any test callbacks — similar to pytest's--collect-only.Running
jest --collectOnlyloads test files and registers alldescribe/test/itblocks, then prints a tree of discovered tests and exits with code 0:With
--json, it outputs the standardformatTestResultsJSON format with all tests marked aspending. Works with--testNamePatternand--testPathPatternsfor filtering.Implementation
collectOnlyas aGlobalConfigboolean optioncollectTestsWithoutRunning()which walks the describe tree recursively, filters bytestNamePatternusing the existinggetTestIDutility, and returns all matching tests aspendingassertion resultsrunJestschedules tests with reporters suppressed and coverage disabled, prints the tree viaVerboseReporter.groupTestsBySuites, and delegates JSON/file output to the existingprocessResultshelpergetTestNamesPathfor use by the collection functionTesting
e2e/__tests__/collectOnly.test.ts) using the existinge2e/eachfixture verify: tree output, valid JSON structure,--testNamePatternfiltering, empty result handling, and that deliberately failing tests still exit 0 (confirming no execution)collectTestsWithoutRunning.test.ts) verify: flat/nested collection, ancestor titles, source order preservation across describe blocks,testNamePatternfiltering, and empty results