Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

[Design required?] Source code that is not included in source map causes incorrect coverage results #149

Closed
clemyan opened this issue May 7, 2021 · 0 comments

Comments

@clemyan
Copy link
Contributor

clemyan commented May 7, 2021

For background: I have been trying to make a PoC for more robust source map support. I discovered this issue which make me think such a feature is intractable.

Note to maintainers: This is not really actionable at this point and I would have used GitHub Discussions if it is enabled here. Feel free to move to Discussions or close this issue.


Consider this simple transpiled script and source map (generated with rollup)

source-map-visualization

main.js

export const one = 1

main.out.js

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const one = 1;

exports.one = one;

main.out.js.map

{"version":3,"file":"main.out.js","sources":["main.js"],"sourcesContent":["export const one = 1\n"],"names":[],"mappings":";;;;AAAY,MAAC,GAAG,GAAG;;;;"}

The export const in main.js is not included in the source map. Given only the V8 coverage data, the source map and the file contents, there is no way to distinguish if such ranges are syntactic constructs that are not executable (e.g. export const here) or executable code that is not included in the generated file (e.g. treeshaken functions). As far as I can see, this can only be resolved with the AST of the original source, but that does not scale to TypeScript or other compile-to-JS languages.

Simply assuming one or the other is problematic. If we assume unincluded ranges are executable and thus is uncovered code, then the case above would report a non-full coverage when in fact coverage is 100%.

On the other hand, if we assume unincluded ranges are non-executable and treat them as covered code (which is, effectively, the current behavior), then treeshaken functions are treated as covered code when in fact they are uncovered code.

@bcoe bcoe closed this as completed Jun 3, 2021
@istanbuljs istanbuljs locked and limited conversation to collaborators Jun 3, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants