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

Add a --file <filename> option for json-cov, json and html-cov reporters #469

Closed
wants to merge 1 commit into from

Conversation

hostalerye
Copy link

This option allows the user to write the report in a file

@tj
Copy link
Contributor

tj commented Jun 20, 2012

why not just redirect stdio?

@hostalerye
Copy link
Author

Actually I work with nherment, so that's for the same reasons he mentioned on this topic: #304 (comment)

@VitalyDov
Copy link

Hi,

We working on big project uses Express and Mocha as testing framework.
For our integration in Jenkins, we need doc and xunit reporters output to files (just mocha output!)
Do you have any plan to provide such functionality?
Thanks a lot!

@anacronw
Copy link

anacronw commented Jul 2, 2012

You can cat the head and tail bits. Mocha's documentation is supposedly generated with this (from the "doc" documentation: http://visionmedia.github.com/mocha ):

test-docs:
make test REPORTER=doc
| cat docs/head.html - docs/tail.html
> docs/test.html

@VitalyDov
Copy link

Hi badunk,
Thank for your quick answer!
Do you have some solution for xunit? (we really need it for Jenkins)
Thanks!

@anacronw
Copy link

anacronw commented Jul 2, 2012

I just did a search and this came up: #83

@VitalyDov
Copy link

Hi badunk,
Yes, I saw this solution, but it not solve the problem :(
The problem, that redirected output file (tap, xml ... ) contains both mocha output and also output from other modules in shuffle manner.We don't want to parse this file for extract only Mocha's messages in order that Jenkins can take it.
Thanks again.

@VitalyDov
Copy link

Hi badunk,
Any news regarding this issue?
Thanks.

@anacronw
Copy link

I have not tried any of those solutions myself, all I did was read documentation :) I don't know if commenting back and forth on this pull request is the best place to get your answer.

If this is a blocker for you, I suppose you can try hostalerye's pull request.

@VitalyDov
Copy link

Ok, thanks

@blmarket
Copy link

+1 for supporting file options to html-cov, because I'm writing some testcases which makes HTTP request to my developing services, and these services can't give me coverage results. I wrote my own coverage-write function, but mocha's reporter doesn't support arbitrary filenames...

@tj tj closed this Jul 25, 2012
@evadnoob
Copy link

https://npmjs.org/package/xunit-file Seems to work well, generates a file called xunit.xml seems good enough for now. The need for this is real, since tests may produce useful logging, and expecting the only output from tests to be xml is overly simplistic.

@beaugunderson
Copy link

I think it would still be useful to provide the file name parameter that's in this pull request because some node modules also emit their own messages to stdout (and don't provide a method to disable them). This is the hack I settled on to get my coverage JSON:

mocha -R json-cov $FILE | perl -0777 -pe "s/(?s).*?{\n/{\n/" > $FILE-coverage.json

@mkotsbak
Copy link

Why are you not merging this? It is very annoying for using Jenkins with output like this:

Express server "undefined" listening on port 8000 in development mode

Then Jenkins complains: Content is not allowed in prolog. Nested exception: Content is not allowed in prolog.
at org.dom4j.io.SAXReader.read(SAXReader.java:482)

@guillaume86
Copy link

+1 I have some modules output before the html when piping stdio ...

@balnagy
Copy link

balnagy commented Mar 23, 2013

This feature would be useful in Grunt environment. Now I have to do in this way with exec plugin, but with this feature I could use the proper mochaTest with file option.

exec: {
 coverage: {
  command: 'mocha -R html-cov ./test/**/*.js > /tmp/coverage.html && open /tmp/coverage.html',
  stout: true
 }
},

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

Successfully merging this pull request may close these issues.

10 participants