Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jakebailey opened this issue Jun 13, 2024 · 8 comments

Comments

@jakebailey
Copy link

jakebailey commented Jun 13, 2024

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

To Reproduce

  • Version: 2.8.3
  • Node Version: 20.12.0
  • Have you tried the latest version (including node), and does the issue still exist? Yes
  • Steps to reproduce the actual behavior:
  1. Clone http://github.com/microsoft/TypeScript
  2. npx c8 --experimental-monocart --reporter=v8 npm test -- --no-lint
  3. npx serve coverage

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
Copy link
Author

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

image

@jakebailey
Copy link
Author

jakebailey commented Jun 13, 2024

Actually for an easier repro, just clone microsoft/TypeScript#58850 and do npm test -- --no-lint --coverage.

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

@cenfun
Copy link
Owner

cenfun commented Jun 13, 2024

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
Copy link
Author

jakebailey commented Jun 13, 2024

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

@jakebailey
Copy link
Author

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 added a commit that referenced this issue Jun 15, 2024
@cenfun
Copy link
Owner

cenfun commented Jun 15, 2024

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

@cenfun
Copy link
Owner

cenfun commented Jun 15, 2024

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

@jakebailey
Copy link
Author

Seems like it's working! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants