Skip to content
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

Project-local custom reporters #2434

Closed
cletusw opened this issue Aug 12, 2016 · 7 comments · Fixed by #2659
Closed

Project-local custom reporters #2434

cletusw opened this issue Aug 12, 2016 · 7 comments · Fixed by #2659
Labels
status: accepting prs Mocha can use your help with this one!

Comments

@cletusw
Copy link

cletusw commented Aug 12, 2016

According to the wiki, you can

define custom third-party reporters within your own test suite, or by using npm modules

The second part ("reporters that are npm modules") works fine, but when I try to use a project-local custom reporter, I'm forced to specify the path relative to node_modules/mocha/lib/.

That is, supposing I have a custom-reporter.js in the root of my project, running

node_modules/.bin/mocha --reporter=./custom-reporter.js

fails, but

node_modules/.bin/mocha --reporter=../../../custom-reporter.js

works.

It would instead be nice if the --reporter option were relative to the current directory for non-npm reporters.

Here's the relevant line that needs fixing. It would need to fall back to something like path.resolve(process.cwd(), reporter). I can try to put together a PR, but I want to make sure I'm not missing something.

@boneskull
Copy link
Member

@cletusw Sounds about right. Just nest another try/catch with path.join(process.cwd(), reporter) or something. path.resolve() should work as well.

@boneskull boneskull added the status: accepting prs Mocha can use your help with this one! label Aug 23, 2016
@cletusw
Copy link
Author

cletusw commented Aug 23, 2016

Will do.

@cletusw
Copy link
Author

cletusw commented Aug 23, 2016

@boneskull On a related note, what's the difference between that code in lib/mocha.js and

mocha/bin/_mocha

Lines 209 to 220 in 2a51080

// load reporter
var Reporter = null;
try {
Reporter = require('../lib/reporters/' + program.reporter);
} catch (err) {
try {
Reporter = require(program.reporter);
} catch (err) {
throw new Error('reporter "' + program.reporter + '" does not exist');
}
}
?

@cletusw
Copy link
Author

cletusw commented Aug 23, 2016

That code is causing errors after my fix, but it looks like Reporter is not actually used anywhere. Does that sound right?

cletusw added a commit to cletusw/mocha that referenced this issue Aug 23, 2016
Closes mochajs#2434

Previously, mocha --reporter=./path/to/custom-reporter.js would fail.

Also removes code from _mocha that has been unnecessary since 191b88c
cletusw added a commit to cletusw/mocha that referenced this issue Aug 24, 2016
Closes mochajs#2434

Previously, mocha --reporter=./path/to/custom-reporter.js would fail.

Also removes code from _mocha that has been unnecessary since 191b88c
cletusw added a commit to cletusw/mocha that referenced this issue Sep 6, 2016
Closes mochajs#2434

Previously, mocha --reporter=./path/to/custom-reporter.js would fail.

Also removes code from _mocha that has been unnecessary since 191b88c
@dasilvacontin
Copy link
Contributor

This feature has been released in v3.3.0! 🎉

@AndersDJohnson
Copy link

I can't get this to work with v4.0.1.

@ScottFreeCode
Copy link
Contributor

Try removing any leading ./; see #2659 (comment) for details (it's been a while but I think my recommendations # 1 and # 2 would cover getting this fix to actually work, while # 3 and # 4 expand the idea to other similar issues).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepting prs Mocha can use your help with this one!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants