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

Use file instead of stdout #16

Closed
honzajavorek opened this issue Feb 16, 2017 · 5 comments
Closed

Use file instead of stdout #16

honzajavorek opened this issue Feb 16, 2017 · 5 comments

Comments

@honzajavorek
Copy link

Currently, I first run my tests with regular reporter and then I instrument the codebase and run the test suite again, with mocha-lcov-reporter. That works, but takes twice as much time then running the tests in a regular way.

Also, some CIs (e.g. Travis CI) kill the build if there's no output for certain time, so if I redirect the stdout of mocha-lcov-reporter to a file by > as advised in README, the instrumented run gets killed - it doesn't output anything to stdout for a long time and CI sees it as a stale process.

Thus I'd like to use mocha-lcov-reporter combined together with other Mocha reporters. It's possible by creating file reporter.coffee like this (CoffeeScript, but JS would work as well):

Spec = require('mocha').reporters.Spec
LCov = require('mocha-lcov-reporter')


module.exports = (runner, options) ->
  new Spec(runner, options)
  new LCov(runner, options) if process.env.COLLECT_COVERAGE

...and then running Mocha with --reporter=test/reporter.coffee. But in this case, I need to separate lcov output and regular spec reporter output, both will get combined on stdout. I need to configure mocha-lcov-reporter to internally append the lcov results to a given file, instead of stdout.

I looked into the code of your lcov reporter and there seems to be no easy way not only configure the reporter, but even monkey-patching isn't possible, as all the important functionality happens in externally inaccessible functions.

@StevenLooman What do you think about this feature? How would you approach implementing it? I'm willing to contribute it, if you give me some pointers.

@StevenLooman
Copy link
Owner

Thank you for the issue, @honzajavorek . If I remember correctly, an issue requesting support for running multiple reporters at the same time was opened before, but I can't seem to find it.

As far as I know, mocha doesn't provide any means to use multiple reporters at the same time. However, a quick Google given reporters such as mocha-multi-reporters. A composite reporter is a great idea, either your own or one pre-existing.

As soon as I have the time I'll make the reporter either monkey-patchable, by using a separate function to write output, and/or make it configurable to write to a file or stdout.

@StevenLooman
Copy link
Owner

@honzajavorek Only made it monkey-patchable for now. Can you verify this fits your needs?

@honzajavorek
Copy link
Author

@StevenLooman You are correct Mocha doesn't really support multiple reporters (yet or very well, considering my approach to be rather workaround). mocha-multi-reporters and similar ones are exactly where I've got inspired with my solution.

The changes you made in fe526ff are exactly what I need. It's really great. This way I'll just override the write method and I'm done.

@StevenLooman
Copy link
Owner

@honzajavorek Great. I have just release version 1.3.0 of mocha-lcov-reporter to npmjs.

@honzajavorek
Copy link
Author

Thank you! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants