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 5039f6c
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -6,9 +6,9 @@
"scripts": {
"test": "cross-env NODE_ENV=test nyc mocha --timeout 30000 packages/*/test{,/*}.js",
"posttest": "eslint .",
"fix": "eslint . --fix",
"postinstall": "bash scripts/install.sh"
"fix": "eslint . --fix"
},
"workspaces": ["packages/*"],
"repository": {
"type": "git",
"url": "git@github.com:istanbuljs/istanbuljs.git"
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

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 5039f6c

Please sign in to comment.