CodeVetter · Repo Unpack · Extension points
mochajs/mocha
The strongest extension contracts are interfaces, reporters, and required-module plugins. CLI option metadata centralizes names, types, aliases, and help text. Runner events are the shared observation API across serial and parallel modes. Some worker and loader customization hooks are internal and should be treated with that narrower stability expectation.
- Mocha.ui accepts an interface function, a built-in registry name, or a resolvable module, unwraps a default export, and invokes the binding function with the root suite.
- Interfaces attach to Suite's pre-require event; createCommon supplies suite factories and hook registration, allowing a new DSL to reuse shared only/skip behavior.
- Mocha.reporter accepts a constructor, built-in name, package ID, or cwd-relative module, unwraps default exports, and supplies reporterOption/reporterOptions aliases.
- Reporter constructors receive runner and options; Mocha invokes an optional reporter.done(failures, callback), while createStatsCollector makes runner.stats available before reporter construction.
- Required modules can export mochaHooks, mochaGlobalSetup, and mochaGlobalTeardown; hook factories may be asynchronous, and finalization merges four hook lists into rootHooks.
- Internal PluginLoader.create accepts pluginDefs and ignore lists; register enforces unique export names, and each definition can provide validate and async finalize functions.
- run-option-metadata.cjs centralizes option types, aliases, and descriptions; getRunOptionDefinitions feeds CLI help, and flag/type lookup functions derive from the same tables.
- loadFilesAsync accepts an esmDecorator; parallel reporters can request partial-object linking, and ParallelBufferedRunner exposes workerReporter for selecting an alternate worker reporter.