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] Is there a way to filter out entries with invalid or missing source maps? #105

Open
Jak-Ch-ll opened this issue Feb 24, 2025 · 1 comment

Comments

@Jak-Ch-ll
Copy link

Jak-Ch-ll commented Feb 24, 2025

Hello,

is there a good solution to filter out files that have have no or no valid source maps?

The scenario

I have the sourceFilter set in the following way:

sourceFilter: {
    '**/src/**': true,
}

My original expectation was that the resulting report should only include files in the src directory, but instead it also has files under the domain:

Image

I understand now that sourceFilter and sourcePath only trigger on actual source maps. In our case the additional 'files' are script and style blocks in HTML files, CSS files (because Vite does not support CSS source maps), and files that have invalid source maps (because they are created from non JS-files). The first two aren't really an issue, because I can clearly identify those in the entryFilter or onEntry hooks.

The problem is the third kind of file. The source maps for these files look something like this:

{"version":3,"file":"_6Ozukyh.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}

I was trying to identify those files in the entryFilter but sadly the entries don't give me a clear differentiator compared to files with valid source maps.

The above example is against the build of our app. When running against dev (with Nuxt), there are also a lot of Hot Module files under the domain.

Potential solution

When I originally started to play around with MCR, I generated a V8 report for everything and then checked what the filters are doing. I figured out that the sourceFilter is way to filter out, what appear in the final report, but I was surprised that not all files would trigger the sourceFilter hook.

Would it make sense to include all files in sourceFilter and sourcePath, even if they have no or no valid source maps? If not, would it be feasable to include a outputFilter which could be used to filter all files that would end up in the report?

This would also be useful when using CoverageReport with raw reports, because in this case onEntry and filterEntries does not trigger

@cenfun
Copy link
Owner

cenfun commented Feb 27, 2025

  • entryFilter is used to filter the files that provide coverage data, maybe sourcemap too
  • sourceFilter is used to filter the files that extracted from the sourcemap

so we should use entryFilter to check whether the sourcemap is valid

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

see cenfun/monocart-reporter#161 (comment)
but i don't think there is a good way to check the sourcemap content. it requires to read sourcemap file content but entryFilter is does not support asynchronous operations.

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