Multiple processes
Use this workflow for processes that can share one outputDir/.cache. For CI shards, containers, or machines without a shared cache, export and merge raw reports instead. Successful generation removes the cache unless debug logging is enabled; exporting a raw report moves the cache to the raw output location.
Workflow
The subprocesses run in parallel and write to the same cache. Report generation starts only after all subprocesses have finished writing.
Loading diagram…
Step 1: Initialize the main process
import { MCR } from 'monocart-coverage-reports';
import coverageOptions from 'path-to/same-options.js';
const mcr = MCR(coverageOptions);
// clean previous cache before the start of testing
// unless the running environment is new and no cache
mcr.cleanCache();Step 2: Collect coverage in parallel
Subprocesses can run concurrently. Use the same outputDir (an absolute path if working directories differ) and leave cleanCache: false. Do not clear the cache or generate reports while collection is running.
Subprocess 1
import { MCR } from 'monocart-coverage-reports';
import coverageOptions from 'path-to/same-options.js';
const mcr = MCR(coverageOptions);
await mcr.add(coverageData1);Subprocess 2
import { MCR } from 'monocart-coverage-reports';
import coverageOptions from 'path-to/same-options.js';
const mcr = MCR(coverageOptions);
await mcr.add(coverageData2);Step 3: Generate the report in the main process
Wait for all subprocesses to finish writing coverage data before calling generate() once in the main process.
// generate coverage reports after the completion of testing
import { MCR } from 'monocart-coverage-reports';
import coverageOptions from 'path-to/same-options.js';
const mcr = MCR(coverageOptions);
await mcr.generate();