cenfun / monocart-coverage-reports

A code coverage tool to generate native V8 reports or Istanbul reports.
MIT License
69 stars 6 forks source link

[Bug] Functions declared after an uncovered return (hoisted) are both uncovered and covered #38

Closed jakebailey closed 4 months ago

jakebailey commented 4 months ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce

Expected behavior A clear and concise description of what you expected to happen.

Code for hoisted but called functions should be marked as covered.

Errors or Screenshots Any captured error messages, or add screenshots to help explain your problem.

image

This code is marked as uncovered in red, but at the same time has the little green boxes showing that it really did execute.

Probably, this has something to do with how these functions are declared after the return but the return is never reached.

Make a minimal reproduction

Sorry, I don't know if I can make a small reproducer; I tried writing similar code like:

function doSomething() {
    return foo();

    function foo() {
        return 'Hello';
    }
}

doSomething();

But it didn't exhibit the same problem.

Additional context Add any other context about the problem here.

jakebailey commented 4 months ago

Yeah, it seems to be related to that unreached return. Another example:

image

jakebailey commented 4 months ago

Actually for an easier repro, just clone https://github.com/microsoft/TypeScript/pull/58850 and do npm test -- --no-lint --coverage.

Hopefully this isn't inherent to v8 profiling in general :((

cenfun commented 4 months ago

It seems like this problem occurs when there is a function defined after a return statement. It doesn't seem very reasonable, but there's no syntax error. I will figure out how to fix it. thanks for the case.

jakebailey commented 4 months ago

This is super common code in our codebase as we don't use classes, but instead return plain objects of closures for performance.

jakebailey commented 4 months ago

Built with your most recent change; it does fix some of it, but not all.

This bit works:

image

However, just a bit lower, there are still lines that are mis-marked:

image

image

cenfun commented 4 months ago

I haven't checked all the lines, but it seems like it has been fixed. 38

cenfun commented 4 months ago

@jakebailey Could you please try monocart-coverage-reports@2.8.4

jakebailey commented 4 months ago

Seems like it's working! Thank you!