0.1.0 • Published 6 months ago

relative-paths-istanbul-json-report v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

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-report

Usage 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: [
        // @ts-expect-error types assume only builtin istanbul reporters will be used, see https://github.com/vitest-dev/vitest/issues/4150
        ['relative-paths-istanbul-json-report', { projectRoot: monorepoRoot }],
      ],
    },
  },
});

Building

Run nx build relative-paths-istanbul-json-report to build the library.

Running unit tests

Run nx test relative-paths-istanbul-json-report to execute the unit tests.

License

MIT © Aliaksandr Haurusiou.