-
-
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
Allow local modules to work as UIs and Reporters #1267
Conversation
So this is what confused me originally. There is no need to install mocha globally, but if running mocha globally then it will only find globally installed UIs and reporters as well. However, when running locally, locally installed reporters and UIs work just find. What this PR adds is that a globally running mocha will source locally installed or linked reporters and UIs. @giggio does that about sum it up? ;-) |
@jbnicolai Yes! |
Am I correct in understanding that this fixes UIs, but not reporters? I'm just checking against the earlier installed |
It fixes both. I just tested:
|
When you run |
Allow local modules to work as UIs and Reporters when running mocha globally
Nice! Thanks for the support. I will be able to run regular mocha again. :D |
Nope, already happy you merged in the CDN option on chromedriver a while back ;-) fixed some issues I was having being my proxy at work. |
(This was PR #1240, we are starting over)
The current way dependencies are handled forces us to have a ui interface (or reporter) installed globally.
I am trying to write another ui interface and unless I use an absolute path or install the module globally I can't load the ui interface. The ideal scenario is to do this per application, so when someone clones the repo the tests just work. The current way will force the developer to globally install mocha and also globally install the module I am writing with the custom ui interface.
This happens because when you
require
a name, the lookup starts from the executable file location,mocha
(globalnode_modules
dir). It doesn't do the lookup from thenode_modules
folder where themocha
command is ran (pwd
).https://github.com/visionmedia/mocha/blob/755f05410d8bdb1218073b74755089998b98a0ca/lib/mocha.js#L153
Currently mocha adds the cwd to modules.path on _mocha like so:
https://github.com/visionmedia/mocha/blob/755f05410d8bdb1218073b74755089998b98a0ca/bin/_mocha#L152
But not on mocha.js.
This will only work for immediate requires, only when they are
require
d directly from_mocha
. Whenmocha.js
tries to load the new ui interface later it can't find it, because itsmodule.paths
is different from_mocha
'smodule.paths
.To be able to load from a local
node_modules
folder it would be needed to setmodule.paths
from where therequire
for the ui is set, atmocha.js
.This PR does just that.