Version: Sonar Scanner 4.6 and hosted sonarcloud.io
Reproduction steps
// a.ts
export const foo = () => {
return 1;
}
/* istanbul ignore next */
export const bar = () => {
return 2;
}
// b.ts
/* istanbul ignore file */
export const baz = () => {
return 3;
}
// a.test.ts
import { foo } from './a.ts.';
it('foo', () => {
expect(foo()).toEqual(1);
});
- create a simple TypeScript project that uses jest, with two source files and 1 test, as illustrated above:
- the test partially covers
a.ts, and none ofb.ts b.tscontains/* istanbul ignore file */comment at the top of the file- alternatively, it can contain
/* istanbul ignore next */before the function block
- the test partially covers
- generate an LCOV coverage report using
jestand thelcovreporter - upload the report with Sonar Scanner using
sonar.javascript.lcov.reportPaths
Expected
a.tsshould report 100% coverage because thefoofunction is covered by tests, while thebarfunction is ignored through anistanbulcommentb.tsshould not be included in the coverage report because it is ignored through anistanbulcomment, or it should report 100%
Actual
Coverage for a.ts is reported as expected, but b.ts shows 0%, not respecting the istanbul comments. Both file and next comments do not have any effect.
Notes
istanbul is the tool used to generate coverage reports for JS/TS. It supports ignoring parts of the code using special comments: istanbul/ignoring-code-for-coverage.md at master · gotwarlost/istanbul · GitHub