Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow FileCoverage to be initialized with logical tracking #644

Merged
merged 1 commit into from Oct 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
});
});