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

Cannot exclude test files from rollup bundle #1042

Closed
nrabinowitz opened this issue Mar 25, 2019 · 3 comments
Closed

Cannot exclude test files from rollup bundle #1042

nrabinowitz opened this issue Mar 25, 2019 · 3 comments

Comments

@nrabinowitz
Copy link

I'm using rollup to bundle a library I'm working on, using ES2015 import/export. My current test approach is to bundle my tests along with the code under test:

rollup test/index.js --file dist/test.js --sourcemap --format=cjs

This allows me to run the tests under Node, and use nyc like so:

nyc --clean -x 'test/**' node dist/test.js

The test coverage shows that the sourcemaps are recognized and used - the coverage is broken out properly by source file. However, the -x/--exclude param is not properly excluding tests or other files I want to exclude, and these show up in the coverage report. I have tried every glob combination of test/**/test/**, ./test/**, etc with no effect. I have also tried putting include/exclude in the "nyc" stanza of package.json.

If I specify --include='lib/**', I get no coverage at all, but --include='dist/test**' works, and shows me the mapped files, so include at least is being processed relative to the filesystem. Using -x 'dist/test**' --include='dist/test**' gives me no coverage at all. So it's pretty certain that --exclude is being processed relative to the filesystem as well, regardless of how I set --exclude-after-remap.

  • Is my test-bundling approach incorrect?
  • Is there a CLI option I've overlooked here?

Apologies if this is user error rather than a bug, but it seems that --exclude is not working as expected in this case.

@coreyfarrell
Copy link
Member

I believe this issue is fixed by #1010 but is not yet released (will become nyc@14.0.0). Could you test by reinstalling nyc from the master branch? You can do this by running npm i -D git://github.com/istanbuljs/nyc#master on your project (it'll still claim to be 13.3.0 but it's a newer version).

Tests are excluded from coverage by default but the currently releases of nyc do not exclude coverage based on source-maps, so it just sees the bundle as a whole and reports on everything in it. That is what #1010 fixes.

@nrabinowitz
Copy link
Author

@coreyfarrell Yes! That fixes the issue - thanks, I've been banging my head against this.

@coreyfarrell
Copy link
Member

nyc@14.0.0-alpha.0 has been released to npm to allow easier testing. Please note that additional breaking changes will occur before 14.0.0 final is released. I'm closing this issue, you can monitor release progress at #1051.

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