cenfun / monocart-coverage-reports

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

[Bug] When the command is ts-node, the V8 reports display the fake sources alongside the real ones #24

Closed ericmorand closed 4 months ago

ericmorand commented 4 months ago

Describe the bug

Using this reproduction repository (https://github.com/ericmorand/c8-with-bundle), executing the command:

npx mcr ts-node src/test/index.ts 

Displays the expected console output:

[MCR] My Coverage Report
┌──────────────┬─────────┬────────────┬──────────┬───────────┬─────────┬─────────────────┐
│ Name         │   Bytes │ Statements │ Branches │ Functions │   Lines │ Uncovered Lines │
├──────────────┼─────────┼────────────┼──────────┼───────────┼─────────┼─────────────────┤
│ src/main/lib │         │            │          │           │         │                 │
│ └ foo.ts     │ 74.38 % │    50.00 % │ 100.00 % │   50.00 % │ 57.14 % │ 5-7             │
├──────────────┼─────────┼────────────┼──────────┼───────────┼─────────┼─────────────────┤
│ Summary      │ 74.38 % │    50.00 % │ 100.00 % │   50.00 % │ 57.14 % │                 │
└──────────────┴─────────┴────────────┴──────────┴───────────┴─────────┴─────────────────┘

But display the fake sources in the V8 HTML output:

image

Expected behavior

The V8 report and the console one are consistent.

Additional context

I'd like to fix this but I need some context to understand the underlying issue.

cenfun commented 4 months ago

This is a known issue, but we can't fix it. Nodejs only exports lineLengths of generated codes and doesn't export generated codes self, so we can only get a fake source code. see issue and source-map-cache I'm afraid we need to fix it on Nodejs side. Alternatively, I've thought a solution, such as using Nodejs hooks to export generated code. see ts-node exmaple: https://github.com/cenfun/mcr-ts-node/tree/main and the hooks source codes: https://github.com/cenfun/monocart-coverage-reports/blob/main/lib/register/hooks.js#L46

ericmorand commented 4 months ago

Since they are not in the console output, maybe it is possible to remove them also from the html one ?

cenfun commented 4 months ago

They are in the HTML list because option logging has been set as debug for debugging purposes. Therefore, changing logging to info can remove them. see debug-for-coverage-and-sourcemap

ericmorand commented 4 months ago

Oooooooooooooooooooh. Thank you!