-
-
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
Support multipart extensions like ".test.js" #4442
Conversation
e716568
to
41ec48d
Compare
Thanks for the PR. To be clear: is using globs a workaround for this? |
@boneskull sure it's possible to match the files I'm looking for using globs—you could use globs instead of the existing Let me tell you about our project setup: We have many widgets each with their own groups of modules. Tests are nested within the src tree adjacent to their source files. We often want to test one widget at a time or one module or a collection of either. So yes, we could run mocha with the following way right now:
If I run that last example in zsh, I'll run these tests:
But if I run this in bash, I'll only run this one:
Unless I'm running bash >= v4 (and I have It's a huge pain to have to specify this glob pattern all the time when we want to easily scope our test runs by directory path, and I would like to codify this testing pattern in our project README without having to enumerate subtle differences between shells. This led me to try to configure this behavior via the I want to be able to run the following:
Without mocha trying to read all of the Given that you already offer the Thanks! |
Ah... well, you can quote your globs--which will be handled by the mocha "src/foo/**/*.test.js" should work fine either way. likewise you can throw this into your { "spec": "blah/**/*.test.js" } |
(relying on the presence of a certain shell or configuration thereof for glob parsing is--as you have found out--fraught with peril) |
Ah, I hadn't realized that you could have mocha expand the globs from a positional argument—but even so, I would still be required to type I'm not doing this for the "run every test in the project for CI" scenario. Your proposals would work find in that case. I'm concerned with the "run tests in this directory" scenario because I'm iterating on something locally and I'm trying to keep my feedback loop tight. I'm trying to extend the supported configuration functionality so that I can avoid having to type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see; thanks for explaining your use-case further. Given that hasMatchingExtname()
only operates on files as determined by a call to fs.stat()
, this looks OK. Otherwise we could run into trouble if you have, say, a directory name matching the extension (e.g., project/.test.js/foo.test.js
). Why that'd be a thing, I don't know, but it's a case that path.extname()
handles (it still returns .js
); as written, hasMatchingExtname()
would return test.js/foo.test.js
. maybe it'd be good to add a comment noting this limitation? Otherwise, LGTM
I'm having trouble writing a comment, because I don't think I understand the limitation you are perceiving.
I'm not sure I follow you here. If we want to prevent directories from being matched, I think we do exactly as we have done in this module and Would you prefer to rename this to something like |
I think I'm confused too. nevermind 😄 this looks ok. I think I want to change this so it supports a leading |
@jordanstephens merged #4472 which allows extensions to be specified as |
@boneskull wow! I found the lack of the leading dot to be strange as well, but I wasn't ready to take it on. Thanks for taking on that extra bit of work! |
Requirements
Description of the Change
Allow
extensions
configuration option to support multipart extensions, ex:test.js
. extension matching support is currently implemented by matching against node'spath.extname
whichThis prevents support for multipart extensions like
.test.js
.By instead using
String.prototype.endsWith
, we can support the existing behavior while also enabling support for multipart extensions.Alternate Designs
You could have also accomplished this by using a RegExp, I suppose, but
endsWith
is simpler.Why should this be in core?
Even without adding support for multipart extensions, I think this implementation is simpler than the existing one for the currently supported use-case. But because multipart extensions are relatively common, and the
extensions
configuration is the only way I can see to support restricting input to these files without resorting to more intricate globbing, I think opening up support for this is also a benefit.Benefits
Support for multipart extensions, simpler implementation.
Possible Drawbacks
I don't see any from here.
Applicable issues
I looked for relevant issues and was surprised that not to find any. If I have overlooked something, let me know.
Thanks!