-
-
Notifications
You must be signed in to change notification settings - Fork 240
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
NYC doesn't work correctly with local node_modules #278
Comments
Anyone have time to take a look at this and provide some thoughts? |
This is affecting our ability to run unit tests. Any solution, even a hacky workaround, would be appreciated. Or where the fix could be made with a PR. |
This is not a simple issue, we cannot just stop ignoring Sorry I don't have any suggestions for work-arounds, you are doing things in a way I've never thought of. |
@coreyfarrell Thanks for the reply! Let me know if there is anything we can do to help you out with this. |
Thanks @coreyfarrell Question on the glob.sync to return all file names. EDIT: looking a bit closer I see At this point Does this seem like a plausible idea? If so, I can try it out locally and let you know if results are different. |
Unfortunately there are problems with the misunderstanding of how Here in detail how we solved it: |
Yea, it seems there is a big misunderstanding of that fact indeed. Thanks for passing along your solution to NYC's limitation but unfortunately, we have too many applications that are using local node_modules and I'm concerned about the risks when building and deploying out to different environments. Until we can get some additional dialogue with the NYC owners for a proper solution, we might just fork the repo and handle the fix internally that way. I'm happy to contribute to NYC's codebase for a fix but first need more feedback from the owners/contributors. |
I don't agree with this assessment. node_modules does have a specific purpose, to install external modules. It's possible to abuse it as you have, but node_modules is meant for stuff installed by npm - normally stuff that has it's own testing. I'm not against making it possible/easier for you to use NYC but I have to prioritize the normal way of working. I'm open to making a boolean option to prevent test-exclude from forcing exclude of |
@coreyfarrell I'll take a stab at this. From what I understand, looks like I'll need to make edits to three libraries – On a slightly separate note, I also noticed that the |
thanks @hershmire, this is exactly what we need. @coreyfarrell, thoughts on merging these PRs? |
@leslc I have to ask for patience. I'm currently dealing with release related issues which need to be addressed first, I have limited time to work on NYC. |
@coreyfarrell Understandable that you're busy. Any idea when you'll be able to have time to look at the three PRs referenced above? |
This seems to also match our use case at our job as well. So I would also appreciate any attention this matter could receive. |
👋 I've moved this issue to the istanbuljs repo, I think we should address this behavior in |
With the merge of #213, #351, istanbuljs/nyc#912 and istanbuljs/nyc#1053 this is now supported in nyc, documented by istanbuljs/nyc#1039. To get this feature you need to upgrade to [email protected]. istanbuljs/babel-plugin-istanbul#172 still pending, need to resolve a merge conflict. Further progress can be monitored on that PR if you need this functionality in the babel plugin. |
Expected Behavior
NYC to not exclude local node_modules (i.e.
src/node_modules/...
ORsrc/somedirectory/node_modules/**
) BUT to exclude root node_modules. We have a lot of Node applications at the company I work for that use the pattern of creating local node_modules as it helps modularize our code at an application/page-level and provides a nice way to require files instead of doing long relative paths to everything. Below is an example file structure many of our apps could see:Observed Behavior
Since by default, NYC adds the glob
**/node_modules/**
it will exclude all node_modules, which in our case we don't want. To get around this problem, you have a negateExcludes section where we supply!src/**/node_modules/**
but that doesn't quite work right as it will force to include our test files which live next to the files that are being tested since negateExclude is evaluated after the exclude rules.Additionally, even with the
all: true
flag set in package.json, NYC doesn't appear to be picking up all files as I thought it would; especially the ones that I purposely left out of having tests point to – i.e. https://github.com/hershmire/nyc-test/blob/master/src/pages/page-1/components/Name.jsx & https://github.com/hershmire/nyc-test/tree/master/src/pages/page-no-tests-1.It would be nice to not exclude all node_modules by default but just the root ones for starters. OR at least provide a easier way to turn that off. It gets quite complicated when you also have to take into account babel-plugin-istanbul and understand how to set both up properly.
Bonus Points! Code (or Repository) that Reproduces Issue
I created a quick demo app that shows what I'm running into here:
https://github.com/hershmire/nyc-test
After running
yarn install
, runyarn coverage
As you can see from the results, my test files under any
test-node
folders are picked up which they should be excluded.Forensic Information
Operating System: the operating system you observed the issue on.
MacOS 10.13.6
Environment Information: information about your project's environment, see instructions below:
sh -c 'node --version; npm --version; npm ls' > output.txt
https://github.com/hershmire/nyc-test/blob/master/output.txt
The text was updated successfully, but these errors were encountered: