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

include/exclude files from coverage #197

Closed
fullstackzach opened this issue Jan 30, 2023 · 15 comments
Closed

include/exclude files from coverage #197

fullstackzach opened this issue Jan 30, 2023 · 15 comments

Comments

@fullstackzach
Copy link

Hi,

Thanks for providing this plugin, I was wondering if it was possible to include or exclude files for coverage similar to how nyc has the option to here? https://github.com/istanbuljs/nyc#using-include-and-exclude-arrays

I'm trying to get this working with Cypress and Next.js. Currently I have this plugin included but the coverage report includes more files than we would like to report on

in next.config.js

...
  experimental: {
    swcPlugins: [
      ['swc-plugin-coverage-instrument', {}], // used to instrument code for cypress e2e test coverage
    ],
  },
...
@kwonoj
Copy link
Owner

kwonoj commented Jan 31, 2023

This plugin attempts to mimic istanbul's api surface as much (https://github.com/istanbuljs/istanbuljs), not the high level api wraps those such as nyc does. If istanbuljs have such interfaces, it can be added. Otherwise, it should be configured by caller instead.

@fullstackzach
Copy link
Author

Gotcha thanks. I think that the includes / excludes files feature is a part of nyc & babel-plugin-istanbul.

Unfortunately, this is going to prevent us from switching from babel to SWC with Next.js until we can target coverage instrumentation for only certain files.

@ivanwidj

This comment was marked as off-topic.

@kwonoj
Copy link
Owner

kwonoj commented Jun 15, 2023

Please do not leave redundant comment.

@GonsonInter

This comment was marked as off-topic.

@timlindsk
Copy link

In .nycrc-config, have you tried using the exclude option with "excludeAfterRemap": true? fullstackzach

@ArnasDickus
Copy link

In .nycrc-config, have you tried using the exclude option with "excludeAfterRemap": true? fullstackzach

Using excludeAfterRemap fixed issue with node_modules showing. So it's viable for me.

@sebkasanzew
Copy link

This prevents me from using Middleware in a Next.js project, because this plugin instruments all files, including middleware.ts. But Middleware uses the edge runtime, instead of nodejs and prohibits eval.

But the instrumented middleware.js in the build output .next/server/src/ includes strings that are evaluated.

Here is a codesandbox with the reproduced error:
https://codesandbox.io/p/devbox/swc-instrument-with-middleware-9kw6rq?file=/next.config.js:3,18

With exclude I could exclude middleware.ts from being instrumented.

@henrikvolmer

This comment was marked as off-topic.

@Themezv
Copy link

Themezv commented Mar 11, 2024

Hello!

If istanbuljs have such interfaces, it can be added.

If babel-plugin-istanbul have such interface, can it be added to swc-plugin?

https://github.com/istanbuljs/babel-plugin-istanbul?tab=readme-ov-file#ignoring-files

@kwonoj
Copy link
Owner

kwonoj commented Jul 4, 2024

I'm still not fully convinced if plugin should support this or not, however to see if this things works or not added unstable options to the plugin. unstableExclude will accept an array of glob pattern to be excluded to be instrumented.

{
unstableExclude: ["somepath/**/excluded.*"],
},

@kwonoj kwonoj closed this as completed Jul 4, 2024
@lhimstedt
Copy link

lhimstedt commented Jul 17, 2024

Hello @kwonoj, thanks for this update. What should the file look like when it is in the exclude pattern?

I added a middleware file from Next.js to the unstableExclude pattern. But the file looks the same whether I add it to the pattern.

I removed the plugin and compared the compiled version of the middleware with the one with an activated plugin; it looks different.

At first, I thought the pattern was not working. However, after debugging the plugin and compiling a version I tested locally, I can confirm that the pattern matches.

I expect the excluded file matched by the pattern to look like the file when the plugin is inactive. Is that correct?

If so, I will debug more and find a solution.

@kwonoj
Copy link
Owner

kwonoj commented Jul 17, 2024

You may refer the test case to see how things work. If the patter matches it should not trigger transform.

@lhimstedt
Copy link

@kwonoj I saw the test case but I wanted to double check my hypothesis. I take you comment as a confirmation that the code of the excluded file should look like the file without the plugin. Since it's not the case it must be a bug in Next.js SWC implementation or the library. Let's see.

@kwonoj
Copy link
Owner

kwonoj commented Jul 17, 2024

Next-swc's plugin runs same as @swc/core. I do not think there is next.js specific swc bugs.

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

10 participants