How cenfun/monocart-coverage-reports works
• Coverage Data Collection Layer: Represent the different methods for collecting coverage
– Node.js V8 Coverage (using NODE_V8_COVERAGE, v8.takeCoverage, Inspector, etc.)
– Browser-based coverage (using Playwright, Puppeteer, and CDPClient API)
– Instrumented source coverage via Istanbul
• Data Conversion & Processing Engine: This is implemented in the “lib” folder and is composed of several submodules:
– Converter Modules (lib/converter/): These include the AST parser/visitor, sourcemap handling, flattening source maps, and converting V8 data into Istanbul-compatible formats.
– Core Modules (lib/cli.js, lib/generate.js, lib/index.js): These handle the script invocation, configuration, report generation and merging of data.
– Registration and Hooks (lib/register/): To allow customization and plug-in behavior.
• Report Generation and Customization Layer:
– Built-In Reporters (lib/reports/): Modules for generating v8, console-details, console-summary, markdown, html, lcov, json, codacy, codecov, etc.
• Utility Services and Helpers:
– Utility modules (lib/utils/…)
– V8 modules (lib/v8/) for additional support in reporting native V8 coverage.
• Configuration and Options: Modules for setting and loading default options (lib/default/options.js) and type definitions (lib/index.d.ts).
CLI/Integration Layer
• Command Line Interface: Represent the CLI entry point (invoked as “mcr”) which wraps test invocations (using child processes) and collects coverage data.
• Config File Resolution: How the tool loads configuration from various files (mcr.config.js, .json, .mjs, etc.) and the use of environment variables.
• Multiprocessing Support: Show how multiple processes (or test stages) add coverage data (via mcr.add) and ultimately the main process calls mcr.generate() to merge and produce reports.
– From external test frameworks (e.g., Jest, Mocha, Playwright, Puppeteer) → Coverage data collection (via Node coverage, CDPClient, etc.)
– Aggregation and conversion of raw coverage data to an internal unified representation (through converter modules, AST visitors, and sourcemap handlers).
– The unified data flows into the reporting engine which then generates various outputs (HTML, JSON, lcov, markdown files, etc.)
– Optionally, flow data into custom integrations (Codacy, Codecov, Coveralls, SonarCloud) with directions showing “upload” or “external integration.”
Distinguish the Frontend/Demo Application
• In “packages/app” you see a Vue-based application that likely demonstrates or previews coverage reports. Represent this as a separate “Frontend UI” component that interacts with (or displays output from) the reporting engine.
Architectural Patterns and Technologies
• Modular Architecture: Clearly note that the project is broken into small, loosely-coupled modules (each in its own folder under lib/) that perform specific tasks such as conversion, reporting, or configuration handling.
• Plugin and Extension Support: Highlight how the architecture supports custom reporters by specifying either local file paths or npm based plugins.
• Multiprocessing & Asynchronous Data Aggregation: Emphasize the design that allows asynchronous addition of coverage data from multiple processes before final report generation.
• Use of Node.js APIs and external integrations (child_process, inspector, CDP APIs).