Skip to content
This repository was archived by the owner on Feb 13, 2024. It is now read-only.

Codecov report generation using ava-nyc #148

Closed
wants to merge 18 commits into from

Conversation

suphalb
Copy link

@suphalb suphalb commented Jan 13, 2018

This PR will help to generate Codecov Report & Upload it on codecov.io

@f2prateek
Copy link
Contributor

hey @suphalb, thanks! can you set this for CI as well? This way the coverage is uploaded to codecov.io (e.g.https://github.com/segmentio/analytics-android/blob/master/.circleci/config.yml#L23)

@codecov-io
Copy link

codecov-io commented Jan 16, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@e1fc2b0). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             master   #148   +/-   ##
=======================================
  Coverage          ?   100%           
=======================================
  Files             ?      1           
  Lines             ?     96           
  Branches          ?      0           
=======================================
  Hits              ?     96           
  Misses            ?      0           
  Partials          ?      0

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e1fc2b0...c3da3a3. Read the comment docs.

Copy link

@vadimdemedes vadimdemedes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation could've been way simpler: https://github.com/sindresorhus/got/blob/master/package.json#L28-L29. There's also no need for coverage-related text to be in the readme.

circle.yml Outdated
@@ -18,3 +18,6 @@ test:
- nvm use 4; npm rebuild &> /dev/null; npm run testci
- nvm use 6; npm rebuild &> /dev/null; npm run testci
- nvm use 8; npm rebuild &> /dev/null; npm run testci
post:
- npm test
- ./node_modules/.bin/nyc report --reporter=lcov > coverage.lcov && bash <(curl -s https://codecov.io/bash)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@f2prateek . IN fact yes. On my local it's working almost in similar way. But over CircleCI it was not working so had to directlt run that cmd via yml to test if the report is actually generating and uploading. So far it's fulfilling the purpose . But Yes i will make it standard and will find out why it's not running as standard way.

package.json Outdated
@@ -23,10 +23,11 @@
],
"scripts": {
"size": "size-limit",
"test": "standard && ava",
"test": "nyc ava tap test.js",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should still be running standard.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok i am little confused here . So far i followed #148 (review) and made it minified / simplified. So will you let me know what should i follow here? I meant should i minify it as per @vadimdemedes request OR it will be same like my previous commit?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mean is we should still be running the standard command as part of the test.

I believe @vadimdemedes pointed to https://github.com/sindresorhus/got/blob/master/package.json#L28-L29. From there xo = standard (both are code formatting tools).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok got it clearly @f2prateek . I am taking care of it quickly and coming back with correct commit.

readme.md Outdated
@@ -28,7 +28,18 @@ client.track({

Documentation is available at [https://segment.com/libraries/node](https://segment.com/libraries/node).

## Generate Codecoverage Report
Copy link
Contributor

@f2prateek f2prateek Jan 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to add this information to the README.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, Already removed and while i will push my next commit it would be rectified.

circle.yml Outdated
@@ -18,3 +18,6 @@ test:
- nvm use 4; npm rebuild &> /dev/null; npm run testci
- nvm use 6; npm rebuild &> /dev/null; npm run testci
- nvm use 8; npm rebuild &> /dev/null; npm run testci
post:
- npm test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to run npm test here? Lines 18-20 are already running a test command as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes in fact. But again the same problem i experienced . It works on my local but it seems over circle ci it doesn't generate any report. Ideally any JS inside of package.json should be executed via npm test automatically by circleCi. So to test it out i had to run that cmd individually just to ensure if reports are generating. Now i will make it standard .

circle.yml Outdated
@@ -8,7 +8,7 @@ dependencies:
- nvm install 4
- nvm install 6
- nvm install 8
- rm -rf node_modules
- rm -rf 'node_modules coverage .nyc_output coverage.lcov'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is wrapped in quotes, the rm program will try to delete a file called "node_modules coverage .nyc_output coverage.lcov". I suspect this is not what you had intended.

package.json Outdated
"testci": "standard && ava && npm run size",
"prepublish": "npm run check-deps",
"check-deps": "nsp check"
"test": "standard && nyc ava tap test.js",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the word "tap" doing here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for TAP format report output as console feedback from cmd?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

however it's not mandatory but just used for report formation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to specify it differently if you want AVA to output TAP: https://github.com/avajs/ava#tap-reporter

readme.md Outdated
@@ -22,13 +22,10 @@ client.track({
userId: 'user id'
});
```

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We ought to keep a newline between these sections of the README.

circle.yml Outdated
@@ -8,7 +8,8 @@ dependencies:
- nvm install 4
- nvm install 6
- nvm install 8
- rm -rf 'node_modules coverage .nyc_output coverage.lcov'
- rm -rf node_modules ; rm -rf coverage ; rm -rf .nyc_output ; rm -f coverage.lcov
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to separate these with semicolons. The single command will work fine.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stephenmathieson So removed those semicolons and surprisingly this time CircleCI accepted these traditional unix like cmd. Just bit clueless why it didn't get execute with same thing on my previous build before i added those semicolons and inverted commas .

As your suggestion reverted back the readme with it's original state removing all codecov related text etc.

regarding ava tap i followed the reference from here actually - https://github.com/istanbuljs/nyc.
In fact they referred to use it in same way like i did and i have been directed there by codecov nyc example . So as reference they say -

update the scripts in your package.json to include these bins:
{
   "scripts": {
     "test": "nyc tap ./test/*.js",
     "coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov"
   }
}
Many testing frameworks (Mocha, Tape, Tap, etc.) can produce TAP output. tap-nyc is a TAP formatter designed to look nice with nyc.

I ran without tap param too however it generates the same output but without a nice serial output formation.

If you think we don't need it here certainly i can omit as it's not mandatory. Please suggest

@suphalb
Copy link
Author

suphalb commented Jan 16, 2018 via email

@suphalb
Copy link
Author

suphalb commented Jan 16, 2018 via email

@f2prateek
Copy link
Contributor

f2prateek commented Jan 16, 2018

@suphalb I believe the issue you are seeing is that locally you are running npm test. On CI, we run npm run testci (https://github.com/segmentio/analytics-node/blob/master/circle.yml#L18).

In your PR you only updated the command for npm test to generate coverage reports. But on CI, it runs npm run testci which doesn't generate any coverage reports, and fails the CI with no such file or directory, scandir '/home/ubuntu/analytics-node/.nyc_output' because the coverage report was not generated on the CI.

If you change the testci command to generate coverage reports by changing it to standard && nyc ava tap test.js && npm run size; it should work on CI. (note: i'm not sure if ava tap is correct as per https://github.com/avajs/ava#tap-reporter; but I'm just using this as the example because that's how the test command is currently setup in the PR).

package.json Outdated
@@ -22,11 +22,11 @@
}
],
"scripts": {
"size": "size-limit",
"test": "standard && ava",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@suphalb this was accidentally removed, can you put this back?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@f2prateek - can you please consider this latest commit ? b0b7874

Seems this time the CI build was successful with the small tweaks you suggested.

package.json Outdated
"testci": "standard && ava && npm run size",
"prepublish": "npm run check-deps",
"check-deps": "nsp check"
"size": "size-limit",
Copy link
Contributor

@f2prateek f2prateek Jan 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation is off by 1 here, which makes the diff harder to read. Can you leave it at the old indentation level?

@vadimdemedes
Copy link

@suphalb when you were using an example config I linked to, what was the error on Circle? If it works in other projects, it should as well just work here.

@suphalb
Copy link
Author

suphalb commented Jan 17, 2018

@vadimdemedes - So here it is . Please refer Build test 185 to 188 as following - https://circleci.com/gh/segmentio/analytics-node/185.

It seems if we consider only codecov and report uploading in fact you are correct that it should work and it was working on my Docker. But it seems for CircleCI there have been additional scripts + test run and those were failing if i remove those additional lines and simplify it only for codecov as your exacmple config. So far all other lines were there from earlier and i didn't refactor it completely. All i just added codecov integration with those previous definition. So going through @f2prateek's tweak suggestion i corrected and minified a bit and put everything inside of testCI run.

Please let me know if i am missing anything here?

readme.md Outdated
@@ -32,3 +32,4 @@ Documentation is available at [https://segment.com/libraries/node](https://segme
## License

Copyright &copy; 2017 Segment Inc. \<friends@segment.com\>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra diff.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will remove it.

package.json Outdated
"prepublish": "npm run check-deps",
"check-deps": "nsp check"
"check-deps": "nsp check",
"report-coverage": "nyc report --reporter=lcov > coverage.lcov && codecov"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=> nyc report --reporter=text-lcov | coveralls

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok here i am bit confused. I have been informed that we should be using codecov. So am just trying to know will it be codecov integration or coveralls?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake, ignore this comment.

package.json Outdated
@@ -23,10 +23,10 @@
],
"scripts": {
"size": "size-limit",
"test": "standard && ava",
"testci": "standard && ava && npm run size",
"testci": "standard && nyc ava tap test.js && npm run size",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove tap and test.js.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok as i followed codecov i did it based on their reference here what i replied to @stephenmathieson . #148 (comment)

So now i am bit confused about what we are implementing here. Codecov OR Coveralls?

Just let me get back to @f2prateek here about it?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake, we're talking about codecov. However, it's still unrelated to this comment.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well then i will give it a shot again in same way you suggested. Fact is i tried it for couple of times on my Docker stack but it didn't work so i had to get those back on my local. Once it started to work i replicated same over Cir-CI.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just ava tap test.js is not a valid command, so I'm not sure how it could work for you.

circle.yml Outdated
@@ -8,7 +8,8 @@ dependencies:
- nvm install 4
- nvm install 6
- nvm install 8
- rm -rf node_modules
- rm -rf node_modules coverage .nyc_output coverage.lcov

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to remove these new files.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmm am just wondering in anycase if those folder contain some older reports from different commits/codes etc and then we should not remove those before new testbed "PRE" build step so it can fetch/upload only new & updated reports for the new expected commits/changes/codes etc?

In anycase report-coverage": "nyc report --reporter=lcov > coverage.lcov && codecov this will always create and rebuild those dir/files before producing reports & upload them over codecov.

So i am trying to understand here , those dir/files with old reports & meta data should be still there even with the fresh build for new changes?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, these files will be overwritten in each build anyway, that's why it makes no sense to remove them beforehand.

coverage
.nyc_output
coverage.lcov

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to ignore coverage.lcov, if you're piping output from nyc to coveralls, like I mentioned in the comment below.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok so you mean i should push all of those dir/files with all my local reports & meta data i used for my local test bed? Should not they be ignored like npm rebuild as they will be created always while codecov report generation and uploading via nyc process will be running? Please suggest.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was talking only about coverage.lcov. But since I was thinking about coveralls and piping output before, it can stay there.

@@ -23,10 +23,10 @@
],
"scripts": {
"size": "size-limit",
"test": "standard && ava",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't remove the test command (this is still used locally).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rectified.

Copy link
Contributor

@stephenmathieson stephenmathieson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

circle.yml Outdated
@@ -9,6 +9,7 @@ dependencies:
- nvm install 6
- nvm install 8
- rm -rf node_modules

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this line added for a reason? Seems unnecessary and inconsistent with the style.

Copy link
Contributor

@f2prateek f2prateek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! One extra line was added in circle.yml.

@f2prateek
Copy link
Contributor

@vadimdemedes all looks good from me and stephen, wanna give your approval too if this looks ok to you?

"test": "standard && ava",
"testci": "standard && ava && npm run size",
"test": "standard && nyc ava --tap",
"testci": "standard && nyc ava --tap && npm run size",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's --tap for? It doesn't affect coverage or reporting.

@vadimdemedes
Copy link

LGTM from me after #148 (comment) is resolved.

@f2prateek f2prateek mentioned this pull request Jan 17, 2018
@f2prateek f2prateek closed this Jan 17, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants