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

Fix false-positive coverage of if statements (REDUCES REPORTED COVERAGE!) #878

Merged
merged 3 commits into from Nov 7, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -242,7 +242,7 @@ internals.instrument = function (filename) {
}
else if (node.type === 'LogicalExpression') {
const left = addStatement(line, node.left, true);
const right = addStatement(line, node.right, node.parent.type === 'LogicalExpression');
const right = addStatement(line, node.right, node.parent.type === 'LogicalExpression' || node.parent.type === 'IfStatement');

node.set(`(global.__$$labCov._statement(\'${filename }\',${left},${line},${node.left.source()})${node.operator}global.__$$labCov._statement(\'${filename}\',${right},${line},${node.right.source()}))`);
}
@@ -370,6 +370,20 @@ describe('Coverage', () => {
expect(missedLines).to.be.empty();
});

it('should measure missing coverage on conditional value', async () => {

const Test = require('./coverage/conditional-value2');

expect(Test.method(false, false, false)).to.equal(false);
expect(Test.method(true, false, false)).to.equal(true);
expect(Test.method(false, true, false)).to.equal(true);

const cov = await Lab.coverage.analyze({ coveragePath: Path.join(__dirname, 'coverage/conditional-value2') });
const source = cov.files[0].source;
const missedLines = Object.keys(source).filter((lineNumber) => source[lineNumber].miss);
expect(missedLines).to.equal(['7']);
});

describe('#analyze', () => {

it('sorts file paths in report', async () => {
@@ -0,0 +1,11 @@
'use strict';

// Load modules


exports.method = function (value1, value2, value3) {
if (value1 || value2 || value3) {
return true;
}
return false;
};
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.