Skip to content

Commit

Permalink
feat(json): add projecRoot option
Browse files Browse the repository at this point in the history
to support relative paths

Closes istanbuljs#701
  • Loading branch information
Sebastian Plaza committed Oct 28, 2022
1 parent fb8cb4b commit a9c09b1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/istanbul-reports/lib/json/index.js
Expand Up @@ -4,12 +4,13 @@
*/
'use strict';
const { ReportBase } = require('istanbul-lib-report');

const path = require('path');
class JsonReport extends ReportBase {
constructor(opts) {
super();

this.file = opts.file || 'coverage-final.json';
this.projectRoot = opts.projectRoot || process.cwd();
this.first = true;
}

Expand All @@ -20,7 +21,10 @@ class JsonReport extends ReportBase {

onDetail(node) {
const fc = node.getFileCoverage();
const key = fc.path;

const key = path.relative(this.projectRoot, fc.path);
fc.data.path = path.relative(this.projectRoot, fc.data.path);

const cw = this.contentWriter;

if (this.first) {
Expand Down

0 comments on commit a9c09b1

Please sign in to comment.