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

coverage.json #518

Closed
yangli-io opened this issue Feb 8, 2017 · 12 comments
Closed

coverage.json #518

yangli-io opened this issue Feb 8, 2017 · 12 comments

Comments

@yangli-io
Copy link

yangli-io commented Feb 8, 2017

Expected Behavior

Expect a coverage.json file in the coverage folder

Observed Behavior

No coverage.json

Bonus Points! Code (or Repository) that Reproduces Issue

./node_modules/.bin/nyc ./node_modules/.bin/_mocha --compilers js:babel-core/register \"app/**/*.js\"
{
  "lines": 90,
  "statements": 90,
  "functions": 90,
  "branches": 90,
  "include": [
    "app/**/*.js"
  ],
  "exclude": [
    "**/*.spec.js",
    "app/routes/test/**/*.js",
    "**/*.asset.js"
  ],
  "reporter": [
    "json-summary",
    "lcov",
    "text-summary"
  ],
  "sourceMap": true,
  "cache": true,
  "instrument": true,
  "check-coverage": true,
  "report-dir": "./coverage"
}
@JaKXz
Copy link
Member

JaKXz commented Feb 11, 2017

Is json-summary a valid reporter? I thought it was just json.

@yangli-io
Copy link
Author

@JaKXz yes json-summary is valid. Json and json-summary were producing some json files, however neither matched the format of coverage.json. On the other hand, I just realised that the random hashed json in the generated .nyc_output is the coverage.json that I'm looking for. Is there a way to configure this to fall in the "report-dir" folder?

@JaKXz
Copy link
Member

JaKXz commented Feb 20, 2017

One thing I've noticed is that you're using the _mocha executable in your test command, but you can simplify (assuming this is inside your package.json scripts) to:

nyc mocha --compilers js:babel-register app/**/*.js

because nyc collects the coverage information instead of using _mocha to do it. You'll also have to npm install -D babel-register, but that's just an optional suggestion.

Not sure if that'll get you what you want in report-dir but it might be worth a shot. I also recommend looking at mocha.opts

@bcoe
Copy link
Member

bcoe commented Feb 20, 2017

@yangli1990 to change the location of the output folder, you should be able to set the command line flag --temp-directory.

The files output in .nyc_output are the raw JSON value of the __coverage__ variable populated during coverage collection -- I believe json-summary is a styled copy of this information (it doesn't reflect the format stored in __coverage__.

What is your goal? perhaps there's a report we're missing., or perhaps an additional command line option that prints the combined output of .nyc_output to a coverage.json would be usesful? I'd love to know your use-case.

@yangli-io
Copy link
Author

@bcoe thanks for responding.
I want to be able to read & measure the coverage on my jenkins, however right now .nyc_output outputs some random file with a hash and sometimes it outputs two (I believe it does this when i use the config all = true) I have no way to extracting this information in a nice way. For now, I've written a hack which transforms the output file into a coverage.json file.

@seanpoulter
Copy link

Adding some notes since they haven't come up yet:

  • The .nyc_outputs directory contains the temporary files to create reports later using nyc report. Since you have files in this directory, you can try running creating the JSON summary report:

    nyc report json-summary
    
  • That json-summary report will create a a file called coverage-summary.json not coverage.json. I found this issue while looking for information why the json reporter saves as coverage-final.json instead of coverage.json.

@bcoe
Copy link
Member

bcoe commented May 14, 2017

@yangli1990 it seems like it might be a nice enhancement to add a command to nyc that lets you combine coverage output into a single file; would definitely consider adding this in the future.

Great first contribution if someone wants to give it a shot 👍

@bcoe
Copy link
Member

bcoe commented May 14, 2017

closing this issue as a duplicate, @yangli1990 will flag you in the new issue.

@yangli-io
Copy link
Author

thank you @bcoe

@shellscape
Copy link

@bcoe link to new issue number?

@seanpoulter
Copy link

seanpoulter commented Jan 23, 2018

Lucky for us @shellscape, there's only one other issue that matches a search for is:issue involves:yangli1990. @bcoe mentioned him in this comment of #515.

@shellscape
Copy link

@seanpoulter solid search-fu, I was not aware of the involves parameter.

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

No branches or pull requests

5 participants