# Behavior traces — jestjs/jest

> Canonical page: https://codevetter.com/unpack/jest/behavior-traces

# Behavior traces — jestjs/jest

Scanned commit 61050e9323e742539dc2360236671110e37329e6 (2026-10-02). Generated by codevetter codevetter 1.15.0 on 2026-10-02.

Source inspection; upstream code and tests were not executed.

Three concrete flows were followed through implementation: CLI startup and execution, module loading, and snapshot persistence. The execution trace includes the distinction between suite runners and the in-environment framework. Module loading branches on mocks, registry state, file type, and VM capabilities. Snapshot persistence includes retry rollback and cleanup of unchecked keys.
- Startup: bin/jest.js first attempts importLocal; otherwise it defaults NODE_ENV to test, calls run(), then buildArgv → getProjectListFromCLIArgs → runCLI → readConfigs. — [packages/jest-cli/bin/jest.js#L9-L17](https://github.com/jestjs/jest/blob/61050e9323e742539dc2360236671110e37329e6/packages/jest-cli/bin/jest.js#L9-L17) [packages/jest-cli/src/run.ts#L20-L29](https://github.com/jestjs/jest/blob/61050e9323e742539dc2360236671110e37329e6/packages/jest-cli/src/run.ts#L20-L29) [packages/jest-core/src/cli/index.ts#L53-L56](https://github.com/jestjs/jest/blob/61050e9323e742539dc2360236671110e37329e6/packages/jest-core/src/cli/index.ts#L53-L56)
- One-shot orchestration: runCLI → _run10000 → buildContextsAndHasteMaps; each project creates a cache directory, calls Runtime.createHasteMap().build(), and constructs a context before runWithoutWatch. — [packages/jest-core/src/cli/index.ts#L143-L170](https://github.com/jestjs/jest/blob/61050e9323e742539dc2360236671110e37329e6/packages/jest-core/src/cli/index.ts#L143-L170) [packages/jest-core/src/cli/index.ts#L173-L182](https://github.com/jestjs/jest/blob/61050e9323e742539dc2360236671110e37329e6/packages/jest-core/src/cli/index.ts#L173-L182) [packages/jest-core/src/cli/index.ts#L220-L247](https://github.com/jestjs/jest/blob/61050e9323e742539dc2360236671110e37329e6/packages/jest-core/src/cli/index.ts#L220-L247)
- Primary execution: runJest selects tests, shards before sorting, applies onlyFailures, runs globalSetup, schedules tests, caches results, runs globalTeardown, then processes results; listTests and collectTests return through earlier branches. — [packages/jest-core/src/runJest.ts#L269-L329](https://github.com/jestjs/jest/blob/61050e9323e742539dc2360236671110e37329e6/packages/jest-core/src/runJest.ts#L269-L329) [packages/jest-core/src/runJest.ts#L334-L366](https://github.com/jestjs/jest/blob/61050e9323e742539dc2360236671110e37329e6/packages/jest-core/src/runJest.ts#L334-L366) [packages/jest-core/src/runJest.ts#L397-L451](https://github.com/jestjs/jest/blob/61050e9323e742539dc2360236671110e37329e6/packages/jest-core/src/runJest.ts#L397-L451)
- Per-file execution: runTest → runTestInternal reads source/docblocks, loads environment and framework, constructs Runtime, executes setupFiles, calls environment.setup(), then invokes testFramework; runtime and environment teardown occur on the guarded completion path. — [packages/jest-runner/src/runTest.ts#L90-L127](https://github.com/jestjs/jest/blob/61050e9323e742539dc2360236671110e37329e6/packages/jest-runner/src/runTest.ts#L90-L127) [packages/jest-runner/src/runTest.ts#L192-L238](https://github.com/jestjs/jest/blob/61050e9323e742539dc2360236671110e37329e6/packages/jest-runner/src/runTest.ts#L192-L238) [packages/jest-runner/src/runTest.ts#L280-L296](https://github.com/jestjs/jest/blob/61050e9323e742539dc2360236671110e37329e6/packages/jest-runner/src/runTest.ts#L280-L296) [packages/jest-runner/src/runTest.ts#L360-L385](https://github.com/jestjs/jest/blob/61050e9323e742539dc2360236671110e37329e6/packages/jest-runner/src/runTest.ts#L360-L385)
- Circus execution: jestAdapter loads jestAdapterInit through requireInternalModule, calls initialize, registers reset/mock cleanup in beforeEach, loads setupFilesAfterEnv and the test module, then calls runAndTransformResultsToJestFormat → run. — [packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.ts#L25-L43](https://github.com/jestjs/jest/blob/61050e9323e742539dc2360236671110e37329e6/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.ts#L25-L43) [packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.ts#L54-L120](https://github.com/jestjs/jest/blob/61050e9323e742539dc2360236671110e37329e6/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.ts#L54-L120) [packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts#L256-L267](https://github.com/jestjs/jest/blob/61050e9323e742539dc2360236671110e37329e6/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts#L256-L267)
- CJS loading: Runtime.requireModuleOrMock checks teardown and mock decisions, then dispatches to a mock, framework singleton, or requireModule; CjsLoader resolves paths, returns registry hits, pre-registers fresh modules for cycles, and removes failed loads. — [packages/jest-runtime/src/index.ts#L576-L603](https://github.com/jestjs/jest/blob/61050e9323e742539dc2360236671110e37329e6/packages/jest-runtime/src/index.ts#L576-L603) [packages/jest-runtime/src/internals/CjsLoader.ts#L77-L112](https://github.com/jestjs/jest/blob/61050e9323e742539dc2360236671110e37329e6/packages/jest-runtime/src/internals/CjsLoader.ts#L77-L112) [packages/jest-runtime/src/internals/CjsLoader.ts#L129-L169](https://github.com/jestjs/jest/blob/61050e9323e742539dc2360236671110e37329e6/packages/jest-runtime/src/internals/CjsLoader.ts#L129-L169)
- ESM loading: EsmLoader.loadAndEvaluate resolves an ESM path, calls loadEsmModule, then linkAndEvaluateModule; synchronous loading requires VM and resolver capabilities, while the asynchronous path links imports, validates attributes, and shares evaluation promises. — [packages/jest-runtime/src/internals/EsmLoader.ts#L1825-L1871](https://github.com/jestjs/jest/blob/61050e9323e742539dc2360236671110e37329e6/packages/jest-runtime/src/internals/EsmLoader.ts#L1825-L1871) [packages/jest-runtime/src/internals/EsmLoader.ts#L2114-L2151](https://github.com/jestjs/jest/blob/61050e9323e742539dc2360236671110e37329e6/packages/jest-runtime/src/internals/EsmLoader.ts#L2114-L2151) [packages/jest-runtime/src/internals/EsmLoader.ts#L2170-L2203](https://github.com/jestjs/jest/blob/61050e9323e742539dc2360236671110e37329e6/packages/jest-runtime/src/internals/EsmLoader.ts#L2170-L2203)
- Snapshot persistence: initialize resolves the snapshot path and constructs SnapshotState; _toMatchSnapshot calls match, retry events call clear(test), and jestAdapter's _addSnapshotData protects failed/skipped tests, removes eligible unchecked keys, calls save, and transfers counters into TestResult. — [packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts#L138-L155](https://github.com/jestjs/jest/blob/61050e9323e742539dc2360236671110e37329e6/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts#L138-L155) [packages/jest-snapshot/src/index.ts#L376-L384](https://github.com/jestjs/jest/blob/61050e9323e742539dc2360236671110e37329e6/packages/jest-snapshot/src/index.ts#L376-L384) [packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts#L343-L349](https://github.com/jestjs/jest/blob/61050e9323e742539dc2360236671110e37329e6/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts#L343-L349) [packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.ts#L130-L162](https://github.com/jestjs/jest/blob/61050e9323e742539dc2360236671110e37329e6/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.ts#L130-L162)

Every claim links to its cited files at the pinned commit. Citations identify source evidence; they do not establish runtime correctness. Independent CodeVetter scan — not reviewed by upstream maintainers.

## Public product links

- [CodeVetter](https://codevetter.com/)
- [Download](https://codevetter.com/download)
- [Documentation](https://codevetter.com/docs/)
- [Source](https://github.com/Codevetter/codevetter)
