c8 icon indicating copy to clipboard operation
c8 copied to clipboard

Incorrect code coverage report when all lines are covered

Open motss opened this issue 4 years ago • 2 comments

Description

Code coverage report generated by c8 is showing incorrect result despite all branches are covered.

I even tested it with compiled JavaScript files by swc and the result remains unchanged when there is no additional code generated found at the said line.

Actual behavior

additional line reported

There is 1 additional branch has been reported not being covered.

Expected behavior

all lines are covered

All lines are covered and c8 should be able to pick up the result correctly.

Reproduction steps

  1. reduced test case

Reqeuired info

motss avatar Jul 25 '21 13:07 motss

@motss thank you for providing the test case 👍

bcoe avatar Dec 30 '21 04:12 bcoe

@motss I dug into your example repo, when I run your test suite, v8 reports a missing block in the getWeekdays method:

        {
          "functionName": "getWeekdays",
          "ranges": [
            {
              "startOffset": 264,
              "endOffset": 1134,
              "count": 9
            },
            {
              "startOffset": 413,
              "endOffset": 423,
              "count": 0
            },
            {
              "startOffset": 499,
              "endOffset": 502,
              "count": 1
            },
            {
              "startOffset": 503,
              "endOffset": 506,
              "count": 8
            },
            {
              "startOffset": 547,
              "endOffset": 554,
              "count": 7
            },
            {
              "startOffset": 605,
              "endOffset": 746,
              "count": 4
            },
            {
              "startOffset": 666,
              "endOffset": 674,
              "count": 2
            },
            {
              "startOffset": 675,
              "endOffset": 687,
              "count": 2
            },
            {
              "startOffset": 747,
              "endOffset": 751,
              "count": 5
            }
          ],
          "isBlockCoverage": true
        },

See the:

            {
              "startOffset": 413,
              "endOffset": 423,
              "count": 0
            },

This missing coverage is happening before c8 does anything.

Is it possible to see the JavaScript generated by @swc/register from the TypeScript code? My guess is that 413 - 423 will be a block of code that is not executed in the transpiled code. The other bug is that I don't believe inline source maps are being created by @swc/register, which leads to the random block of code being highlighted in the file.

bcoe avatar Dec 30 '21 05:12 bcoe