nyc-merge is a lightweight Node.js tool designed to merge multiple Istanbul (nyc) coverage reports into a single, unified JSON report. This makes it easier to aggregate test coverage results from various sources and present a comprehensive overview.
- Multi-Pattern Search: Use one or more glob patterns to locate coverage files.
- Concurrent Processing: Leverages parallel operations for fast file processing, configurable to match your machine's capabilities.
- Robust Merging: Uses Istanbul’s coverage library to combine coverage data accurately.
- Error Reporting: Logs errors encountered during file processing, ensuring that issues are visible and can be addressed.
- CLI Usability: Provides a simple command line interface with clear options for output and concurrency.
Ensure you have Node.js (version 18 or higher) installed, then install nyc-merge globally via npm:
npm install -g nyc-merge
Alternatively, you can add it to your project as a dependency:
npm install nyc-merge --save-dev
After installation, you can run nyc-merge directly from the command line.
nyc-merge --out <output.json> [--concurrency <number>] <glob-pattern> [<glob-pattern> ...]
-
--out, -o
(Required)
Path to the output JSON file where the merged coverage report will be written. -
--concurrency, -c
Number of parallel operations used to process files. Defaults to the number of CPU cores available.
Merge all coverage files matching a single glob pattern:
nyc-merge --out merged-coverage.json "coverage/**/coverage-final.json"
Merge coverage reports from multiple directories:
nyc-merge --out merged-coverage.json "coverage/**/coverage-final.json" "test-coverage/**/coverage-final.json"
Customize concurrency:
nyc-merge --out merged-coverage.json --concurrency 4 "coverage/**/coverage-final.json"
-
File Discovery:
The tool utilizes fast-glob to locate files matching the provided glob patterns. -
File Processing:
Each found file is read asynchronously, and its JSON content is parsed. Any errors during this process are logged. -
Data Merging:
Istanbul’s lib-coverage library is used to merge the JSON coverage reports into a single cohesive report. -
Output Generation:
The resulting merged JSON report is written to the specified output file. Directories are created as needed.
Contributions are welcome! If you encounter issues, have suggestions, or want to contribute new features, please check the issues page and submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.