# Data flow — mochajs/mocha

> Canonical page: https://codevetter.com/unpack/mocha/data-flow

# Data flow — mochajs/mocha

Scanned commit 79db2ee53b863813b97bf2a74cafa1599115c074 (2026-10-01). Generated by codevetter codevetter 1.15.0 on 2026-10-02.

Source inspection; upstream code and tests were not executed.

Inputs enter through CLI arguments, environment options, config files, required modules, or browser scripts. Node file loading converts executable declarations into a Suite/Test graph before the runner executes it. Runner events feed statistics and reporters, while parallel mode transports serialized events across process boundaries. Persistent results are optional report artifacts whose paths come from reporter options.
- loadOptions merges CLI, MOCHA_OPTIONS, rc configuration, package.json's mocha property, and defaults in that precedence order, then combines spec and positional arguments and deduplicates them. — [lib/cli/options.cjs#L120-L129](https://github.com/mochajs/mocha/blob/79db2ee53b863813b97bf2a74cafa1599115c074/lib/cli/options.cjs#L120-L129) [lib/cli/options.cjs#L148-L177](https://github.com/mochajs/mocha/blob/79db2ee53b863813b97bf2a74cafa1599115c074/lib/cli/options.cjs#L148-L177)
- prepareRunOptions loads --require modules through requireOrImport, discovers their plugin exports, finalizes plugin options, and merges them into argv after validating reporter and interface selection. — [lib/cli/run-helpers.cjs#L97-L121](https://github.com/mochajs/mocha/blob/79db2ee53b863813b97bf2a74cafa1599115c074/lib/cli/run-helpers.cjs#L97-L121) [lib/cli/run.cjs#L125-L130](https://github.com/mochajs/mocha/blob/79db2ee53b863813b97bf2a74cafa1599115c074/lib/cli/run.cjs#L125-L130) [lib/plugin-loader.js#L228-L274](https://github.com/mochajs/mocha/blob/79db2ee53b863813b97bf2a74cafa1599115c074/lib/plugin-loader.js#L228-L274)
- collectFiles expands each spec through lookupFiles, filters ignored paths with minimatch, resolves absolute paths, sorts only spec files when requested, and prepends --file paths. — [lib/cli/collect-files.cjs#L40-L59](https://github.com/mochajs/mocha/blob/79db2ee53b863813b97bf2a74cafa1599115c074/lib/cli/collect-files.cjs#L40-L59) [lib/cli/collect-files.cjs#L82-L91](https://github.com/mochajs/mocha/blob/79db2ee53b863813b97bf2a74cafa1599115c074/lib/cli/collect-files.cjs#L82-L91)
- loadFilesAsync processes files sequentially, surrounding requireOrImport with suite pre-require, require, and post-require events; BDD listeners turn declarations into Test objects attached to the active suite. — [lib/mocha.cjs#L438-L452](https://github.com/mochajs/mocha/blob/79db2ee53b863813b97bf2a74cafa1599115c074/lib/mocha.cjs#L438-L452) [lib/nodejs/esm-utils.cjs#L174-L187](https://github.com/mochajs/mocha/blob/79db2ee53b863813b97bf2a74cafa1599115c074/lib/nodejs/esm-utils.cjs#L174-L187) [lib/interfaces/bdd.js#L27-L34](https://github.com/mochajs/mocha/blob/79db2ee53b863813b97bf2a74cafa1599115c074/lib/interfaces/bdd.js#L27-L34) [lib/interfaces/bdd.js#L82-L90](https://github.com/mochajs/mocha/blob/79db2ee53b863813b97bf2a74cafa1599115c074/lib/interfaces/bdd.js#L82-L90)
- Suite.create establishes parent/context inheritance, while addSuite propagates timeout, retries, slow threshold, and bail settings into child suites. — [lib/suite.js#L109-L113](https://github.com/mochajs/mocha/blob/79db2ee53b863813b97bf2a74cafa1599115c074/lib/suite.js#L109-L113) [lib/suite.js#L126-L140](https://github.com/mochajs/mocha/blob/79db2ee53b863813b97bf2a74cafa1599115c074/lib/suite.js#L126-L140) [lib/suite.js#L417-L425](https://github.com/mochajs/mocha/blob/79db2ee53b863813b97bf2a74cafa1599115c074/lib/suite.js#L417-L425)
- Runner emits test outcomes and lifecycle events; createStatsCollector mutates runner.stats with counts and timestamps, and JSONReporter converts tests and errors into a results object. — [lib/runner.js#L958-L987](https://github.com/mochajs/mocha/blob/79db2ee53b863813b97bf2a74cafa1599115c074/lib/runner.js#L958-L987) [lib/stats-collector.js#L46-L69](https://github.com/mochajs/mocha/blob/79db2ee53b863813b97bf2a74cafa1599115c074/lib/stats-collector.js#L46-L69) [lib/reporters/json.js#L71-L82](https://github.com/mochajs/mocha/blob/79db2ee53b863813b97bf2a74cafa1599115c074/lib/reporters/json.js#L71-L82) [lib/reporters/json.js#L108-L121](https://github.com/mochajs/mocha/blob/79db2ee53b863813b97bf2a74cafa1599115c074/lib/reporters/json.js#L108-L121)
- The worker pool serializes options, invokes worker run over IPC, and deserializes the returned result; worker run serializes buffered results, which the parent re-emits as reporter events. — [lib/nodejs/buffered-worker-pool.cjs#L134-L136](https://github.com/mochajs/mocha/blob/79db2ee53b863813b97bf2a74cafa1599115c074/lib/nodejs/buffered-worker-pool.cjs#L134-L136) [lib/nodejs/worker.cjs#L128-L139](https://github.com/mochajs/mocha/blob/79db2ee53b863813b97bf2a74cafa1599115c074/lib/nodejs/worker.cjs#L128-L139) [lib/nodejs/parallel-buffered-runner.cjs#L173-L204](https://github.com/mochajs/mocha/blob/79db2ee53b863813b97bf2a74cafa1599115c074/lib/nodejs/parallel-buffered-runner.cjs#L173-L204)
- JSON output uses recursive directory creation and synchronous writes with stdout fallback; browser tests instead expose failures and counts through window.__mochaResults for Playwright to read. — [lib/reporters/json.js#L83-L95](https://github.com/mochajs/mocha/blob/79db2ee53b863813b97bf2a74cafa1599115c074/lib/reporters/json.js#L83-L95) [test/browser/server.js#L35-L52](https://github.com/mochajs/mocha/blob/79db2ee53b863813b97bf2a74cafa1599115c074/test/browser/server.js#L35-L52) [test/browser/run.spec.js#L6-L22](https://github.com/mochajs/mocha/blob/79db2ee53b863813b97bf2a74cafa1599115c074/test/browser/run.spec.js#L6-L22)

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)
