-
-
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 #1240
Conversation
Fixed: - Pending test dots not being counted (leading to longer rows of dots when containing pending tests) - Off-by-one error on first dot row (first row always lacks a dot)
I had also made some comments on #1022. |
This depends on a PR made on the mocha project: mochajs/mocha#1240
@@ -62,6 +64,7 @@ function image(name) { | |||
*/ | |||
|
|||
function Mocha(options) { | |||
module.paths.push(cwd, join(cwd, 'node_modules')); |
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.
@giggio would this work outside of the Mocha
constructor? It seems like it has impact outside the scope of the constructor.
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.
It would impact the whole module defined by the mocha.js
file, but not any of its required modules. So, any require call made inside this file would use the extra paths. Therefore, calls to reporters and UIs would consider the added path, the cwd and node_modules.
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.
Given that, I wonder if this belongs outside of the constructor. It would seem more intuitive to me if this were defined outside the constructor somewhere within the file.
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 don't believe that the correct place would be outside the constructor, as the places where calls to require
that need the cwd are only within prototype functions, therefore only after you have an instance. Placing it outside the construct could affect calls to required modules that don't need to be in the cwd, normal mocha dependencies.
Right now this would affect only UIs and reporters, and they are in function prototypes.
Can we get some love in this pull request from the maintainers? It is a simple change. Some feedback, please? |
…put bugs" * shaine/patch-1: Fix dot reporter output bugs
Show also failed test for doc reporter
Fix #1191 - Tests succeed on rejected falsey promises
xunit reporter: don't include attrs in failure tag
I don't quite understand. For instance, the teamcity reporter simply works through |
Add ES6 arrow function support to utils.clean
as mentioned in #332
@jbnicolai |
@giggio many thanks for figuring out why reporters work and UIs do not. I do feel that a consistent approach to loading in third party UIs and reporters would be best, so I'm closing this PR and am looking forward to one doing just that. Your work on this is greatly appreciated! :) |
@jbnicolai
I incorrectly assumed on my earlier comment that the require call on Now I see 2 options:
Let me know what you prefer. |
@giggio again, your work is appreciated - thanks! I have not tried the I will look into the issues you're having, try |
Okay.. so after some intense debugging I think the following happened:
So even though this pr is marked as |
Right, this PR is broken now. I thought github would be smarter and keep the files in place. |
@giggio unless my understanding is wrong I think you did something along the lines of Feel free to recreate the PR and reference this one for context - I'm still more than open to accepting it if I can understand the issue and reproduce it locally. |
Ok, this is all pretty weird now. I am not able to use locally installed reporters, I always get that error, "invalid reporter". |
That is because you are running from |
That is the problem I am trying to solve. If you run from the globally installed mocha, mocha will not be able to find your reporter/ui, because they are installed locally. If you run from the locally installed it will. We have two different behaviors, depending where you run it from. I will open another PR now. I created another branch so this mess doesn't happen anymore. (Mental note, never do a PR from master). :) |
Right, now I understand the issue. I do think the current behaviour makes some sense though: if you're running mocha globally, use globally installed reporters; if running locally, use the local ones. On the other hand, I see your point. When developing, you simply type |
\o/ |
(Superseded by #1267)
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.
Update (Jul 11): Reporters already work, see discussion bellow.
Update (Jul 12): Actually reporters don't work, discussion bellow. This PR was not merged. I messed the code up with a push --force and started again with #1267.