-
-
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
Mocha does not recognise third party reporters installed from a local directory #3530
Comments
You verified installation? $ PROJECT=${HOME}/web/my-third-party-reporter-tester
$ ls -al ${PROJECT}/node_modules/my-third-party-reporter |
Yep, definitely installed. |
Very odd. All you should have needed to do was add the reporter as a dependency of your project. $ cd ${PROJECT}
$ npm install --save-dev my-third-party-reporter
$ (cd node_modules; node -e "console.log(require('my-third-party-reporter'))") |
As a test, does this work? $ cd ${PROJECT}/node_modules
### Don't do this at home!! ###
$ (cd mocha/lib/reporters/; ln -s ../../../my-third-party-reporter/lib/my-third-party-reporter.js)
$ npm test
### Restore your sanity ###
$ rm mocha/lib/reporters/my-third-party-reporter.js |
Your first test:
Worked and outputs: Your second test, creating a symlink worked as expected. The tests run, the reporter works. For reference, the exact code I'm working with is here |
Technically, your function should be |
Package suggestions:
|
Yeah, mistyped it.
Will give it a go.
Many thanks. Will get on it!
:p |
Were you able to track down why it wasn't loading? |
Not yet. Hope to have some time this evening to look into it. |
Anything to report, or should I close this? |
Sorry for the delay @plroebuck I've created a minimal reproduction repository here. It includes a single test suite with a couple assertions in one package, and a custom reporter in the other package. I am now debugging the mocha package and have so far discovered that the reporter argument is undefined when Mocha.prototype.reporter is called first. It is called a second time, where the 'reporter' is defined but 'reporterOptions' is an empty object. |
Ok - This is slightly embarrassing, but it's possible that others will make the same mistake. I think I simply forgot to The reporter worked when installed as a full package because node obviously looks in the only node_modules directory available and finds mocha. But when the reporter was installed from a local package, requiring the reporter throws an exception. We would expect this to be due to the reporter package not being found, but it's actually just bubbled up from the reporter. Logging the error made it pretty clear:
So, what to do? The simple answer is "install mocha in the reporter you dope" - but in the case that somebody makes the same mistake in the future, it might be prudent to update the warning message to more accurately reflect the problem. I'm working on a pull request. I realise it's a minor issue, but I'm interested in making the updates for my own sake. |
Prerequisites
faq
labelnode node_modules/.bin/mocha --version
(Local) andmocha --version
(Global). We recommend avoiding the use of globally installed Mocha.Description
When developing a third party reporter, mocha does not recognise the reporter package if it is installed using
npm install
with a local package directory.The
npm install
command runs successfully. The package appears under the node_modules directory. However, when the test script is run, mocha throws an error saying "reporter not found".This does NOT happen when the package is published and installed through the normal npm system. The third party reporter installs and runs as expected.
Steps to Reproduce
npm install ../path-to/my-third-party-reporter
Expected behavior: The reporter runs as normal, my tests are run and output is produced.
Actual behavior:
With the following test script in package.json:
mocha throws:
Reproduces how often: 100%
Versions
Mocha version: 5.2.0 (not installed globally)
Node version: v8.11.1
OS: MacOs High Sierra v10.13.6
Shell: iTerm2 build 3.2.4beta2
The text was updated successfully, but these errors were encountered: