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!: address off by one error processing branches #127

Merged
merged 4 commits into from Oct 25, 2020
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
4 changes: 2 additions & 2 deletions .nycrc
Expand Up @@ -6,7 +6,7 @@
"html",
"text"
],
"lines": 99.5,
"lines": 99.4,
"branches": "92",
"statements": "99.5"
"statements": "99.4"
}
7 changes: 6 additions & 1 deletion lib/v8-to-istanbul.js
Expand Up @@ -34,6 +34,9 @@ module.exports = class V8ToIstanbul {
this.rawSourceMap = undefined
this.sourceMap = undefined
this.sourceTranspiled = undefined
// Indicate that this report was generated with placeholder data from
// running --all:
this.all = false
}

async load () {
Expand Down Expand Up @@ -104,10 +107,11 @@ module.exports = class V8ToIstanbul {
// lines zeroed out.
if (block.functionName === '(empty-report)') {
line.count = 0
this.all = true
return true
}

return startCol <= line.endCol && endCol >= line.startCol
return startCol < line.endCol && endCol >= line.startCol
})
const startLineInstance = lines[0]
const endLineInstance = lines[lines.length - 1]
Expand Down Expand Up @@ -222,6 +226,7 @@ module.exports = class V8ToIstanbul {
return {
[resolvedPath]: {
path: resolvedPath,
all: this.all,
...this._statementsToIstanbul(source, path),
...this._branchesToIstanbul(source, path),
...this._functionsToIstanbul(source, path)
Expand Down
160 changes: 54 additions & 106 deletions tap-snapshots/test-v8-to-istanbul.js-TAP.test.js
Expand Up @@ -7,6 +7,7 @@
'use strict'
exports['test/v8-to-istanbul.js TAP > must match branches snapshot 1'] = `
Object {
"all": false,
"b": Object {
"0": Array [
1,
Expand Down Expand Up @@ -36,7 +37,7 @@ Object {
1,
],
"9": Array [
0,
1,
],
},
"branchMap": Object {
Expand Down Expand Up @@ -275,15 +276,15 @@ Object {
"type": "branch",
},
"9": Object {
"line": 34,
"line": 35,
"loc": Object {
"end": Object {
"column": 0,
"line": 37,
},
"start": Object {
"column": 14,
"line": 34,
"column": -1,
"line": 35,
},
},
"locations": Array [
Expand All @@ -293,8 +294,8 @@ Object {
"line": 37,
},
"start": Object {
"column": 14,
"line": 34,
"column": -1,
"line": 35,
},
},
],
Expand Down Expand Up @@ -782,6 +783,7 @@ Object {

exports['test/v8-to-istanbul.js TAP > must match functions snapshot 1'] = `
Object {
"all": false,
"b": Object {
"0": Array [
1,
Expand Down Expand Up @@ -1763,6 +1765,7 @@ Object {

exports['test/v8-to-istanbul.js TAP > must match mixed new lines snapshot 1'] = `
Object {
"all": false,
"b": Object {
"0": Array [
1,
Expand Down Expand Up @@ -1869,6 +1872,7 @@ Object {

exports['test/v8-to-istanbul.js TAP > must match shebang snapshot 1'] = `
Object {
"all": false,
"b": Object {
"0": Array [
1,
Expand All @@ -1879,15 +1883,15 @@ Object {
},
"branchMap": Object {
"0": Object {
"line": 1,
"line": 2,
"loc": Object {
"end": Object {
"column": 7,
"line": 8,
},
"start": Object {
"column": 19,
"line": 1,
"column": -1,
"line": 2,
},
},
"locations": Array [
Expand All @@ -1897,8 +1901,8 @@ Object {
"line": 8,
},
"start": Object {
"column": 19,
"line": 1,
"column": -1,
"line": 2,
},
},
],
Expand Down Expand Up @@ -2030,14 +2034,12 @@ Object {

exports['test/v8-to-istanbul.js TAP > must match source-map and minified source snapshot 1'] = `
Object {
"all": false,
"b": Object {
"0": Array [
1,
],
"1": Array [
0,
],
"10": Array [
"1": Array [
0,
],
"2": Array [
Expand All @@ -2047,52 +2049,23 @@ Object {
0,
],
"4": Array [
0,
1,
],
"5": Array [
0,
],
"6": Array [
1,
0,
],
"7": Array [
0,
1,
],
"8": Array [
0,
],
"9": Array [
1,
],
},
"branchMap": Object {
"0": Object {
"line": 31,
"loc": Object {
"end": Object {
"column": 10,
"line": 31,
},
"start": Object {
"column": 10,
"line": 31,
},
},
"locations": Array [
Object {
"end": Object {
"column": 10,
"line": 31,
},
"start": Object {
"column": 10,
"line": 31,
},
},
],
"type": "branch",
},
"1": Object {
"line": 5,
"loc": Object {
"end": Object {
Expand All @@ -2118,33 +2091,7 @@ Object {
],
"type": "branch",
},
"10": Object {
"line": 29,
"loc": Object {
"end": Object {
"column": 10,
"line": 30,
},
"start": Object {
"column": 0,
"line": 29,
},
},
"locations": Array [
Object {
"end": Object {
"column": 10,
"line": 30,
},
"start": Object {
"column": 0,
"line": 29,
},
},
],
"type": "branch",
},
"2": Object {
"1": Object {
"line": 8,
"loc": Object {
"end": Object {
Expand All @@ -2170,7 +2117,7 @@ Object {
],
"type": "branch",
},
"3": Object {
"2": Object {
"line": 11,
"loc": Object {
"end": Object {
Expand All @@ -2196,7 +2143,7 @@ Object {
],
"type": "branch",
},
"4": Object {
"3": Object {
"line": 14,
"loc": Object {
"end": Object {
Expand All @@ -2222,33 +2169,7 @@ Object {
],
"type": "branch",
},
"5": Object {
"line": 31,
"loc": Object {
"end": Object {
"column": 10,
"line": 31,
},
"start": Object {
"column": 10,
"line": 31,
},
},
"locations": Array [
Object {
"end": Object {
"column": 10,
"line": 31,
},
"start": Object {
"column": 10,
"line": 31,
},
},
],
"type": "branch",
},
"6": Object {
"4": Object {
"line": 1,
"loc": Object {
"end": Object {
Expand All @@ -2274,7 +2195,7 @@ Object {
],
"type": "branch",
},
"7": Object {
"5": Object {
"line": 1,
"loc": Object {
"end": Object {
Expand All @@ -2300,7 +2221,7 @@ Object {
],
"type": "branch",
},
"8": Object {
"6": Object {
"line": 2,
"loc": Object {
"end": Object {
Expand All @@ -2326,7 +2247,7 @@ Object {
],
"type": "branch",
},
"9": Object {
"7": Object {
"line": 20,
"loc": Object {
"end": Object {
Expand All @@ -2352,6 +2273,32 @@ Object {
],
"type": "branch",
},
"8": Object {
"line": 29,
"loc": Object {
"end": Object {
"column": 10,
"line": 30,
},
"start": Object {
"column": 0,
"line": 29,
},
},
"locations": Array [
Object {
"end": Object {
"column": 10,
"line": 30,
},
"start": Object {
"column": 0,
"line": 29,
},
},
],
"type": "branch",
},
},
"f": Object {
"0": 1,
Expand Down Expand Up @@ -2732,6 +2679,7 @@ Object {

exports['test/v8-to-istanbul.js TAP > must match source-map with multiple source files snapshot 1'] = `
Object {
"all": false,
"b": Object {},
"branchMap": Object {},
"f": Object {
Expand Down