You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Invalid coverage with --experimental-monocart when using ts-node #561
I guess this is because runtime JS files are transformed on the fly, and Monocart does not have access to those? c8 would require a loader or require hook in order to capture all files that user executed? cc. @cenfun
I have found that the issue is related to the generated source code.
when using c8 + ts-node, we can not get the generated source code, but there is only a fake code with lineLengths of source-map-cache, see https://nodejs.org/docs/latest/api/cli.html#source-map-cache and nodejs/node#48460
It said, the sourcemap contains the original code, but it does not have the generated code, instead, it has lineLengths only.
So Monocart cannot get the precise location by parsing the AST of the generated code.
Activity
AriPerkkio commentedon May 21, 2025
I guess this is because runtime JS files are transformed on the fly, and Monocart does not have access to those?
c8would require a loader or require hook in order to capture all files that user executed? cc. @cenfuncenfun commentedon May 21, 2025
I thought it should be the issue with the sourcemap.
I used your example and it works with
mcrCLI, see here (branch is example)But I haven't figured out why c8 isn't working. The differences:
1, tsconfig.json: https://github.com/cenfun/mcr-ts-node/blob/example/tsconfig.json
2, cross-env NODE_OPTIONS="--loader ts-node/esm --no-warnings"
3, package.json
{ "type": "module" }4, CLI:
mcrAriPerkkio commentedon May 21, 2025
That example is not using
c8at all?cenfun commentedon May 21, 2025
yes, I haven't figured out why c8 isn't working
cenfun commentedon May 22, 2025
I have found that the issue is related to the generated source code.
when using
c8+ts-node, we can not get the generated source code, but there is only a fake code withlineLengthsofsource-map-cache, see https://nodejs.org/docs/latest/api/cli.html#source-map-cache and nodejs/node#48460It said, the sourcemap contains the original code, but it does not have the generated code, instead, it has
lineLengthsonly.So Monocart cannot get the precise location by parsing the AST of the generated code.
In order to get the generated code,

mcrCLI uses Node.js customization-hooks to save the generated code in some cases. (It doesn't always succeed, for example, it fails when using tsx)see https://github.com/cenfun/monocart-coverage-reports/blob/main/lib/register/hooks.js
AriPerkkio commentedon May 22, 2025
Yep, that's exactly what I meant by #561 (comment).