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

[Question] #98

Closed
springJia opened this issue Dec 18, 2024 · 7 comments
Closed

[Question] #98

springJia opened this issue Dec 18, 2024 · 7 comments

Comments

@springJia
Copy link

springJia commented Dec 18, 2024

想问下,在sourceMap 映射源文件之后,可以通过配置使覆盖率报告中剔除编译后(运行时)的文件吗

@springJia
Copy link
Author

在无法确定真实执行文件的目录情况下

@cenfun
Copy link
Owner

cenfun commented Dec 18, 2024

编译过的文件,如果有sourcemap会自动剔除 ,除非设置了logging=debug就会保留
你这个看起来应该是这些编译后的文件,并没有sourcemap
可以通过entryFilter过滤掉如果不想要的话

@cenfun
Copy link
Owner

cenfun commented Dec 18, 2024

最好是有些特征用来过滤,比如特定的文件夹或文件名
否则应该没有更好的办法

@cenfun
Copy link
Owner

cenfun commented Dec 18, 2024

或许可以通过文件内容过滤,比如

 entryFilter: (entry) => {
    // skip files without sourcemap 
    if (entry.source?.includes("sourceMappingURL") === false) {
      return false;
    }
    ...
 }

@springJia
Copy link
Author

我看了一下,nodejs v8 注入环境变量NODE_V8_COVERAGE 生成的覆盖率文件中包含source-map-cache,
运行时通过 inspector Profiler.takePreciseCoverage() 生成的文件中不包含source-map-cache,

Profiler.takePreciseCoverage() 生成的覆盖率文件经过monocart-coverage-reports 分析之后展示的是相对路径,
NODE_V8_COVERAGE 生成的覆盖率文件经过monocart-coverage-reports 分析之后展示的是绝对路径

所以上面看到有/opt/nodeapp/src 和src 两个目录

@cenfun
Copy link
Owner

cenfun commented Dec 19, 2024

Nodejs确实会提供source-map-cache,这样可以从source-map-cache里读取对应文件的sourcemap
https://nodejs.org/docs/latest/api/cli.html#source-map-cache
但非常可惜的是并没有提供编译后的source,只提供一个lineLengths,行信息,能还原一个假的source,目前并没有好的办法解决这个问题
(也有想过一些方法去解决,比如hooks,但只能用mcr的cli才能够支持,https://github.com/cenfun/monocart-coverage-reports/issues/24)

所以提供的路径可能就不一致,如果要统一路径,可以试试参数sourcePath

const coverageOptions = {
    sourcePath: (filePath) => {
        // Remove the virtual prefix
        const list = ['my-dist-file1/', 'my-dist-file2/'];
        for (const str of list) {
            if (filePath.startsWith(str)) {
                return filePath.slice(str.length);
            }
        }
        return filePath;
    }
};

我其实并没有看懂你具体是个啥问题,但只能尽可能的解释或者帮你找下你提到的一些信息

@springJia
Copy link
Author

又帮到了我,谢谢

@cenfun cenfun closed this as completed Dec 19, 2024
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