Problem
Is there a way to configure Istanbul/Jest to collect a separate code coverage metric?
The metric should count the visited lines/branches of code but only when the line is executed as a part of a direct call to containing function.
Motivation
I want to see how well are functions tested in isolation (in a true sense of unit-testing).
Example
For the code below, I am interested in seeing the metric that counts every line of foo()
function as visited once (since it is invoked directly from the test); however each bar()
's line to not be counted, because it's not invoked directly by the test, but rather called transitively.
.
// test.js
it(`should count things well`, () => {
expect(foo()).toEqual(3);
});
// code.js
| function foo() {
1 | const a = 1;
1 | const b = bar();
1 | return a + b;
| }
| function bar() {
0 | return 2;
| }
What I tried
The Istanbul-generated coverage-final.json
does not seem to contain any metadata about what a certain line of code is. It only tells whether certain lines/branches of code are visited or not. I wonder if there are some command flags I could use to control what coverage information is being emitted and make an analysis of the extended data.