-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Option exclude certain files by pattern when testing recursively #1577
Comments
You may better make two parallel directories, one for tests and the other
|
I could (and have in the past) but I'd rather not have to do that anymore now that I've realized that glob ignore is right there. It should be pretty easy to add a command line argument to set the glob ignore option. I just wanted to get thoughts and discuss a little bit first. Any objections to me creating a PR for this? |
I was just needing this too and was surprised to see mocha did not already have it. I think it would be a great addition. We have a "testApp" inside our test folder that we use specifically for testing. We don't want mocha trying to run tests inside that folder. It would be nice to be able to just add an exclude to our mocha.opts file to exclude that specific path rather than having to explicitly include all the other test sub-folders we have. While we could move the testApp out, it really doesn't fit anywhere else in the repo and its got relative pathing to certain files in the test folder. This I think would be a nice addition. Certainly not critical, but helpful. |
If I needed this, I think I'd probably just $ mocha $(find test/ ! -path '*testApp*') So I'm not really thrilled about the idea. I'm kind of on the fence about the existence of the |
I think @boneskull makes a good point - this is already achievable in a variety of ways. And that's not including the fact that you can structure you directories to avoid this altogether. For example, given this structure:
You just update your package.json so that you can simply run
Or with a structure like the following:
You could run specs in a similar fashion as @boneskull's example (this will only run files containing
Edit: Fixed :) |
@danielstjules I think that will actually hit any dir with |
Yup, you're right! Brainfart. Thanks for pointing that out. Fixed command for the example:
|
I think there is still a valid use case for this feature: I tend to group my files by feature, so each test file is next to the files containing the logic they're testing. Naming test files consistently works with the For anyone looking - gulp-mocha can achieve this, I just hate to include |
I'd like to take a moment and +1 this idea. Unlike typical JavaScript projects I like to follow the way GO does unit testing and I include a spec file next to every single file that gets tested. For example a directory in one of my projects may look like the following:
I find this type of organization makes it far easier to find test versus digging into a single directory of test files; you always expect the test to sit right next to the file that it tests and my build script scripts all .spec.js files out in the deployed version. Due to my non-standard layout what I'd like to be able to do is run all unit tests with all of my folders excluding the node_modules directory. I don't have a Windows box near me at the moment but I'm not sure if that find syntax would work in Windows or not; an exclude option would be far more intuitive anyway in my opinion. Plus almost all unit test frameworks include a way of ignoring files anyway so parity would be nice. |
Hi, all my tests support Creating two separate directories will not work here, and you have to agree that moving tests between to directories would create a lot of noise in VCS. @calebthebrewer Thankfully I'm using gulp in the project ;) thanks for the hint! |
+1 @calebthebrewer |
Angular 2.0 and Polymer have me in component mode so I agree with @KrisSiegel. Keeping all of your code in bundles keeps a clean, modular, easy-to-maintain file hierarchy. |
Is there any foreseeable problem to loading the tests using the
This way you can import your files from wherever and just have one test file in You can resolve the promise within the last test block and wrap each test up like this
It seems to work pretty good, unless there is something I am not considering. |
We should still have an ignore for the glob. Using bash commands is not a cross platform solution. |
+1 I really would like to exclude |
@godspeedelbow Why would that particular directory need explicitly ignored? I don't normally hear about FWIW, I could really use this as well. I've got a couple projects where the tests scale far more than the library itself, and this would enable me to better organize them (fixtures belong in a test directory IMHO). |
Ignoring This issue has been around for almost a full year now so I don't have much hope of it being implemented. It's important, in my opinion, to implement because the workarounds either require platform specific terminal commands or you explicitly specify patterns for each directory you want to test (so additional directories need to be added to the testing script). I would fork it and just do it myself but using the hacky method of specifying each directory and a pattern is just easier than finding the time to implement it into mocha. |
@KrisSiegel You could always do Although I think they're just waiting on someone to just take the time to do it themselves. It doesn't seem like a difficult patch to create (unless that logic is a spaghetti code state machine mess). I'm not as driven to do this personally because I'm actually working on a test framework of my own, intended to be a complete alternative to Mocha, Jasmine, Tape, etc., although simpler and more powerful at its core. It's still too much a work in progress for even toy projects ATM, though. |
I'm using Mocha to effectively bootstrap the framework. I used Chai initially for the assertions until I got those stabilized (they're practically API locked now, since I'm using the framework's assertions to test itself). |
Yeah that's a workaround I just don't see many JavaScript projects structured that way though the same could be said about pairing the spec and source file as well. I essentially use that pattern though when I come into projects that are already pretty large with their own custom build systems it's not always easy to change it up. Exclude is a pretty basic pattern a lot of utilities have. I think mocha needs it :). Though I guess my impression, since this issue was closed based around platform specific workarounds, that it was not desired versus awaiting a patch. If this is something the mocha folks would actually want then if it's not done in a few weeks I could certainly crank out a patch. |
@KrisSiegel I'm pretty sure that if someone actually cranked out a patch, it would probably get merged, as long as it doesn't involve some unintuitive, special syntax or extra flag. FWIW, there's yet to be a PR for this, and the reason this issue was closed was pretty weak if you consider the platform-dependent. And I don't see very many Windows users that are willing to install GNU It may be closed, but a similar situation is already happening to Node with Web workers, although Node's implementation will slightly deviate (closed issue, PR in progress). |
+1 for what it's worth. A project I've built doesn't require an Being able to specify files to ignore with a Almost all other build tools allow this, we have |
@isiahmeadows like others mentioned, I'm stuck with a folder structure I can't easily change, therefore I'd love to implement it myself in mocha, if I'd knew where to start :) |
@godspeedelbow @adambuczynski A temporary solution :)
|
Hi @danielstjules thanks! Tried it, but for some reason |
Did you update
|
@danielstjules cheers, but that wouldn't work on windows I believe, and while for this app it's not a problem, I am hesitant to put it in. In the mean time, I've resorted to moving the app code and tests to an |
@danielstjules yeah, all test files are in format of |
In addition, |
...and if it isn't clear, don't use unquoted globs on the command line; see #2355 |
Surprisingly there's still no option like |
+1 |
@isiahmeadows
No, you couldn't - the EDIT: @ScottFreeCode has the answer below |
Are your paths quoted? |
+1 |
As describe in zinserjan/mocha-webpack#124: Inside So we don't want this and only this file to be excluded. |
Voicing my opinion that mocha needs an ignore because even after all this time, maintainers still need convincing. Mocha is canon. why not raise the bar for the cross-platform feature set of the test framework that all other test frameworks aspire to be? We should stop aspiring to leaving everything up to Bash. Its 2017 already. |
I'll also point out that Windows people don't have anything equivalent to Bash's |
There shouldn't be any Bash dependency in Mocha's globbing as-is, since it is processed through the Glob JS module. (Note: quoting the paths may be required to avoid the shell processing globs differently from how Mocha would, e.g. |
@ScottFreeCode Do you use |
It looks like we're just passing the path to glob. I am pretty sure that I got negation working through a glob pattern at some point, but that may have been an older version of the module? In any case, we do have tests for the double-star behavior, so if anyone wants to submit tests to confirm that some negation patterns work too (or if anyone finds any flaws in the globbing tests we already have), that would be great. However, there's a definite advantage to having an explicit
I merely wanted to clarify that the status quo isn't meant to be relying on any particular shell. ;^) |
True, and I had almost forgotten about that 😄 |
Anyone coming to this issue: The workaround is now to use globs, as this should be supported. If someone wants this particular behavior, please send a PR. |
* Add --exclude as option. * Add tests for --exclude option. * Implement --exclude. * Update --exclude description. * Remove old exclude fixture. * Add new exclude fixture. * Fix tests for --exclude option. * Add name to package.contributors. * Filter new files before they're added. * Allow multiple --exclude flags rather than using a comma-delimited list. * Use .fixture extension for exclude fixtures. * Use runMochaJSON (run) instead of of directInvoke.
Does |
Yea, i've been using old version of mocha. Upgraded and Thanks @outsideris |
* Add --exclude as option. * Add tests for --exclude option. * Implement --exclude. * Update --exclude description. * Remove old exclude fixture. * Add new exclude fixture. * Fix tests for --exclude option. * Add name to package.contributors. * Filter new files before they're added. * Allow multiple --exclude flags rather than using a comma-delimited list. * Use .fixture extension for exclude fixtures. * Use runMochaJSON (run) instead of of directInvoke.
This ought to be available in MochaOptions type as well, then. There is no Is this a types issue (that "ignore" option exists as it's found in https://github.com/mochajs/mocha/blob/master/example/config/.mocharc.js but not added to type) or does the "non-cli library" not support ignore? I'll submit PR to DefinitelyTyped if you can assure it should work. |
Just for people who may come later to read this, Mocha supports
|
I would like the ability to provide an exclusion pattern so that I can only test files that match my test file pattern. This would allow data files to coexist with test files so long as they follow a reasonable pattern.
I think this would be simply providing an option that sets
ignore
option inglob
.Thoughts? I can make a PR for it real quick if you'd like.
The text was updated successfully, but these errors were encountered: