relative-paths-istanbul-json-report
v0.5.0
Published
An [Istanbul](https://istanbul.js.org) reporter whose output is like that of the built-in [`json`](https://istanbul.js.org/docs/advanced/alternative-reporters/#json) reporter, with one added feature - **support for `projectRoot`**
Readme
relative-paths-istanbul-json-report
An Istanbul reporter whose output is like that of the built-in json reporter, with one added feature - support for projectRoot
Rationale
In the context of a monorepo, it may be useful to get a merged coverage report.
But, in a CI pipeline, or with distributed task execution, testing tasks may be run on different machines, resulting in reports that cannot be merged, because of different absolute paths to the checked out repository
Thus, the projectRoot should be set to the monorepo root
Installation
npm i -D relative-paths-istanbul-json-reportUsage with Jest
Add the reporter to coverageReporters
// workspace-level jest.config.ts
/** @type {import('jest').Config} */
const config = {
coverageReporters: [
["relative-paths-istanbul-json-report", { projectRoot: monorepoRoot }],
],
};
module.exports = config;Usage with Vitest
Add the reporter to coverage.reporter
// vitest.config.ts
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
coverage: {
reporter: [
["relative-paths-istanbul-json-report", { projectRoot: monorepoRoot }],
],
},
},
});Building
Run pnpm run build to build the library.
Running unit tests
Run pnpm run test to execute the unit tests.
License
MIT © Aliaksandr Haurusiou.
