Skip to content

Instantly share code, notes, and snippets.

@kentcdodds
Last active February 15, 2023 14:19
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kentcdodds/3f57448c47c404e12200815048b1cc01 to your computer and use it in GitHub Desktop.
Save kentcdodds/3f57448c47c404e12200815048b1cc01 to your computer and use it in GitHub Desktop.
coverage information for https://testingjavascript.com

Code Coverage

Code coverage is accomplished with Jest thanks to babel-plugin-istanbul. It transforms your code to "instrument" it for coverage. When your tests are finished, Jest reads the coverage data to generate the coverage report.

Reviewing code that has been instrumented for coverage can help understanding how coverage works and how to interpret coverage reports.

function getFormattedValue(value, language = 'en-US') {
let formattedValue = parseFloat(value).toLocaleString(language, {
useGrouping: true,
maximumFractionDigits: 6,
})
// Add back missing .0 in e.g. 12.0
const match = value.match(/\.\d*?(0*)$/)
if (match) {
formattedValue += /[1-9]/.test(match[0]) ? match[1] : match[0]
}
return formattedValue
}
export {getFormattedValue}
var cov_2k0r47ewe = function () {
var path = "/Users/kentcdodds/Desktop/tmp/utils.js";
var hash = "797a9fb26f3bf326cd604591b0f8e666e1afc48e";
var global = new Function("return this")();
var gcv = "__coverage__";
var coverageData = {
path: "/Users/kentcdodds/Desktop/tmp/utils.js",
statementMap: {
"0": {
start: {
line: 2,
column: 23
},
end: {
line: 5,
column: 4
}
},
"1": {
start: {
line: 7,
column: 16
},
end: {
line: 7,
column: 42
}
},
"2": {
start: {
line: 9,
column: 2
},
end: {
line: 11,
column: 3
}
},
"3": {
start: {
line: 10,
column: 4
},
end: {
line: 10,
column: 66
}
},
"4": {
start: {
line: 12,
column: 2
},
end: {
line: 12,
column: 23
}
}
},
fnMap: {
"0": {
name: "getFormattedValue",
decl: {
start: {
line: 1,
column: 9
},
end: {
line: 1,
column: 26
}
},
loc: {
start: {
line: 1,
column: 54
},
end: {
line: 13,
column: 1
}
},
line: 1
}
},
branchMap: {
"0": {
loc: {
start: {
line: 1,
column: 34
},
end: {
line: 1,
column: 52
}
},
type: "default-arg",
locations: [{
start: {
line: 1,
column: 45
},
end: {
line: 1,
column: 52
}
}],
line: 1
},
"1": {
loc: {
start: {
line: 9,
column: 2
},
end: {
line: 11,
column: 3
}
},
type: "if",
locations: [{
start: {
line: 9,
column: 2
},
end: {
line: 11,
column: 3
}
}, {
start: {
line: 9,
column: 2
},
end: {
line: 11,
column: 3
}
}],
line: 9
},
"2": {
loc: {
start: {
line: 10,
column: 22
},
end: {
line: 10,
column: 66
}
},
type: "cond-expr",
locations: [{
start: {
line: 10,
column: 47
},
end: {
line: 10,
column: 55
}
}, {
start: {
line: 10,
column: 58
},
end: {
line: 10,
column: 66
}
}],
line: 10
}
},
s: {
"0": 0,
"1": 0,
"2": 0,
"3": 0,
"4": 0
},
f: {
"0": 0
},
b: {
"0": [0],
"1": [0, 0],
"2": [0, 0]
},
_coverageSchema: "43e27e138ebf9cfc5966b082cf9a028302ed4184",
hash: "797a9fb26f3bf326cd604591b0f8e666e1afc48e"
};
var coverage = global[gcv] || (global[gcv] = {});
if (coverage[path] && coverage[path].hash === hash) {
return coverage[path];
}
return coverage[path] = coverageData;
}();
function getFormattedValue(value, language = (cov_2k0r47ewe.b[0][0]++, 'en-US')) {
cov_2k0r47ewe.f[0]++;
let formattedValue = (cov_2k0r47ewe.s[0]++, parseFloat(value).toLocaleString(language, {
useGrouping: true,
maximumFractionDigits: 6
}));
const match = (cov_2k0r47ewe.s[1]++, value.match(/\.\d*?(0*)$/));
cov_2k0r47ewe.s[2]++;
if (match) {
cov_2k0r47ewe.b[1][0]++;
cov_2k0r47ewe.s[3]++;
formattedValue += /[1-9]/.test(match[0]) ? (cov_2k0r47ewe.b[2][0]++, match[1]) : (cov_2k0r47ewe.b[2][1]++, match[0]);
} else {
cov_2k0r47ewe.b[1][1]++;
}
cov_2k0r47ewe.s[4]++;
return formattedValue;
}
export { getFormattedValue };
function getFormattedValue(value, language = 'en-US') {
let formattedValue = parseFloat(value).toLocaleString(language, {
useGrouping: true,
maximumFractionDigits: 6,
})
const match = value.match(/\.\d*?(0*)$/)
/* istanbul ignore next */
if (match) {
formattedValue += /[1-9]/.test(match[0]) ? match[1] : match[0]
}
return formattedValue
}
export {getFormattedValue}
var cov_2k0r47ewe = function () {
var path = "/Users/kentcdodds/Desktop/tmp/utils.js";
var hash = "37e923c03715b193e7589207c26a97c97cbe28f7";
var global = new Function("return this")();
var gcv = "__coverage__";
var coverageData = {
path: "/Users/kentcdodds/Desktop/tmp/utils.js",
statementMap: {
"0": {
start: {
line: 2,
column: 23
},
end: {
line: 5,
column: 4
}
},
"1": {
start: {
line: 7,
column: 16
},
end: {
line: 7,
column: 42
}
},
"2": {
start: {
line: 13,
column: 2
},
end: {
line: 13,
column: 23
}
}
},
fnMap: {
"0": {
name: "getFormattedValue",
decl: {
start: {
line: 1,
column: 9
},
end: {
line: 1,
column: 26
}
},
loc: {
start: {
line: 1,
column: 54
},
end: {
line: 14,
column: 1
}
},
line: 1
}
},
branchMap: {
"0": {
loc: {
start: {
line: 1,
column: 34
},
end: {
line: 1,
column: 52
}
},
type: "default-arg",
locations: [{
start: {
line: 1,
column: 45
},
end: {
line: 1,
column: 52
}
}],
line: 1
}
},
s: {
"0": 0,
"1": 0,
"2": 0
},
f: {
"0": 0
},
b: {
"0": [0]
},
_coverageSchema: "43e27e138ebf9cfc5966b082cf9a028302ed4184",
hash: "37e923c03715b193e7589207c26a97c97cbe28f7"
};
var coverage = global[gcv] || (global[gcv] = {});
if (coverage[path] && coverage[path].hash === hash) {
return coverage[path];
}
return coverage[path] = coverageData;
}();
function getFormattedValue(value, language = (cov_2k0r47ewe.b[0][0]++, 'en-US')) {
cov_2k0r47ewe.f[0]++;
let formattedValue = (cov_2k0r47ewe.s[0]++, parseFloat(value).toLocaleString(language, {
useGrouping: true,
maximumFractionDigits: 6
}));
const match = (cov_2k0r47ewe.s[1]++, value.match(/\.\d*?(0*)$/));
/* istanbul ignore next */
if (match) {
formattedValue += /[1-9]/.test(match[0]) ? match[1] : match[0];
}
cov_2k0r47ewe.s[2]++;
return formattedValue;
}
export { getFormattedValue };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment