Skip to content

Commit

Permalink
feat: allow FileCoverage to be initialized with logical tracking (#644)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Oct 17, 2021
1 parent 94455eb commit 4cb5af1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/istanbul-lib-coverage/lib/file-coverage.js
Expand Up @@ -9,8 +9,8 @@ const dataProperties = require('./data-properties');
const { CoverageSummary } = require('./coverage-summary');

// returns a data object that represents empty coverage
function emptyCoverage(filePath) {
return {
function emptyCoverage(filePath, reportLogic) {
const cov = {
path: filePath,
statementMap: {},
fnMap: {},
Expand All @@ -19,6 +19,8 @@ function emptyCoverage(filePath) {
f: {},
b: {}
};
if (reportLogic) cov.bT = {};
return cov;
}

// asserts that a data object "looks like" a coverage object
Expand Down Expand Up @@ -99,14 +101,14 @@ class FileCoverage {
* and empty coverage object with the specified file path or a data object that
* has all the required properties for a file coverage object.
*/
constructor(pathOrObj) {
constructor(pathOrObj, reportLogic = false) {
if (!pathOrObj) {
throw new Error(
'Coverage must be initialized with a path or an object'
);
}
if (typeof pathOrObj === 'string') {
this.data = emptyCoverage(pathOrObj);
this.data = emptyCoverage(pathOrObj, reportLogic);
} else if (pathOrObj instanceof FileCoverage) {
this.data = pathOrObj.data;
} else if (typeof pathOrObj === 'object') {
Expand Down
7 changes: 7 additions & 0 deletions packages/istanbul-lib-coverage/test/file.test.js
Expand Up @@ -760,4 +760,11 @@ describe('base coverage', () => {
bcby
);
});

it('allows file coverage to be initialized with tracking for logical truthiness', () => {
let fcov = new FileCoverage('foo.json');
assert.notOk(fcov.data.bT);
fcov = new FileCoverage('foo.json', true);
assert.ok(fcov.data.bT);
});
});

0 comments on commit 4cb5af1

Please sign in to comment.