Configuration files
Minimal config
Create mcr.config.js in your project root. This example uses ESM exports; for CommonJS configuration, see Module format:
export default {
name: 'My Coverage Report',
outputDir: './coverage-reports',
reports: ['v8', 'console-summary']
};Then run from the project root (replace demo.js with your script, or use the quick-start example):
npx mcr node demo.jsThe CLI discovers config files automatically. See Configuration options for all fields and Reports for output formats.
Module format
MCR supports both ESM and CommonJS configuration. Use export default for ESM (for example, .js files with "type": "module" in package.json), or module.exports for CommonJS (for example, .cjs files, or .js files with "type": "commonjs").
MCR being ESM-only does not change the module format of your project's .js files. CommonJS scripts can load MCR with asynchronous import() without converting the whole project to ESM; see the migration guide.
Load config with the API
With the API, load config explicitly before adding data:
import { CoverageReport } from 'monocart-coverage-reports';
const mcr = new CoverageReport();
await mcr.loadConfig();Then add data and generate reports as shown in the report API example. MCR({...}) is a shorthand factory for new CoverageReport({...}).
Loading behavior
In MCR 3.x, loadConfig() throws if an explicitly requested config does not exist or a discovered config fails to load (including JSON parsing, module syntax and startup errors). All CLI commands exit with a non-zero status for these errors. No strict option is needed. If no custom config is requested and no default config is found, execution continues with existing options.
Configuration types
Configuration types: CoverageReportOptions for the API, or McrCliOptions for CLI and test runner options.
Loading priority
Use --config ./mcr.config.mjs or await mcr.loadConfig('./mcr.config.mjs') to select a file explicitly. Otherwise, MCR searches upward from the current working directory and stops at the nearest directory with a config file. Within that directory, it uses the first existing file in this order:
mcr.config.jsmcr.config.cjsmcr.config.mjsmcr.config.jsonmcr.config.ts(native loading for erasable syntax)
For configuration syntax Node.js cannot run natively, preload a loader such as tsx with the CLI:
npx mcr --import tsx -c mcr.config.ts -- node ./test.js