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.ts
contains/* 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
jest
and thelcov
reporter - upload the report with Sonar Scanner using
sonar.javascript.lcov.reportPaths
Expected
-
a.ts
should report 100% coverage because thefoo
function is covered by tests, while thebar
function is ignored through anistanbul
comment -
b.ts
should not be included in the coverage report because it is ignored through anistanbul
comment, 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