Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Example repo for uploading reports to Codecov

License

NotificationsYou must be signed in to change notification settings

codecov/example-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

80 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Codecov NodeJS / Javascript Example

FOSSA Status

Guide

You can install Codecov by adding

npm install -g codecov

Travis Setup

Add the following to your.travis.yml:

language:node_jsbefore_install:  -npm install -g codecovscript:  -istanbul cover ./node_modules/mocha/bin/_mocha --reporter lcovonly -- -R spec  -codecov

The first script line will change depending on your coverage collecting tool, see below.

Produce Coverage Reports

  • Installblanket.js
  • Configure blanket according todocs.
  • Run your tests with a command like this:
NODE_ENV=test YOURPACKAGE_COVERAGE=1 ./node_modules/.bin/mocha \  --require blanket \  --reporter mocha-lcov-reportercodecov

Instrumenting your app for coverage is probably harder than it needs to be (readhere), but that's also a necessary step.

In mocha, if you've got your code instrumented for coverage, the command for a travis build would look something like this:

YOURPACKAGE_COVERAGE=1 ./node_modules/.bin/mochatest -R mocha-lcov-reporter

With Mocha:

nyc --reporter=lcov mocha&& codecov

With Jasmine:

istanbul cover ./node_modules/jasmine/bin/jasmine.js

With Karma:

Thelcov.info can be used as in other configurations. Some projects experienced better results usingjson output but it is no longer enabled by default. Inkarma.config.js both can be enabled:

module.exports=functionkarmaConfig(config){config.set({        ...reporters:[            ...// Reference: https://github.com/karma-runner/karma-coverage// Output code coverage files'coverage'],// Configure code coverage reportercoverageReporter:{reporters:[// generates ./coverage/lcov.info{type:'lcovonly',subdir:'.'},// generates ./coverage/coverage-final.json{type:'json',subdir:'.'},]},        ...});};

Inpackage.json supply eitherlcov.info orcoverage-final.json tocodecov:

{"scripts":{"report-coverage":"codecov",    ...}  ...}

Depend on nodeunit and jscoverage:

npm install nodeunit jscoverage codecov --save-dev

Add a codecov script to "scripts" in yourpackage.json:

"scripts":{"test":"nodeunit test","codecov":"jscoverage lib && YOURPACKAGE_COVERAGE=1 nodeunit --reporter=lcov test && codecov"}

Ensure your app requires instrumented code whenprocess.env.YOURPACKAGE_COVERAGE variable is defined.

Run your tests with a command like this:

npm run codecov
-name:Codecovuses:codecov/codecov-action@v2with:token:${{ secrets.CODECOV_TOKEN }}flags:unittests

Client-side JS code coverage usingPhantomJS,Mocha andBlanket:

  • Configure Mocha for browser
  • Mark target script(s) withdata-cover html-attribute
  • Run your tests with a command like this:
./node_modules/.bin/poncho -R lcov test/test.html&& codecov
istanbul cover ./node_modules/lab/bin/lab --report lcovonly  -- -l&& codecov
{"scripts":{"report-coverage":"nyc report --reporter=text-lcov > coverage.lcov && codecov",    ...}  ...}

Run

jest --ci --coverage&& codecov

or you can add it in your package.json:

"jest":{"coverageDirectory":"./coverage/","collectCoverage":true}

Jest will now generate coverage files intocoverage/ and you can run your tests with a command like this:

jest&& codecov

JSX

There have been reports ofgotwarlost/istanbul not working properly with JSX files, which provide inaccurate coverage results. Please try usingambitioninc/babel-istanbul.

istanbul cover node_modules/.bin/tape ./test/*.js

Or simply run:

istanbul cover ./test/*.js

Or add in package.json:

"test": "istanbul cover test/*.js",

After test:

codecov --token=:token

Caveats

Private Repo

Repository tokens are required for (a) all private repos, (b) public repos not using Travis-CI, CircleCI or AppVeyor. Find your repository token at Codecov and provide viacodecov --token=:token orexport CODECOV_TOKEN=":token"

Common Pitfalls

When usingmock-fs make sure to runmock.restore() when your tests are done running, or else the reports wont get generated on the CI.

Support

FAQ

  1. More documentation athttps://docs.codecov.io
  2. Configure codecov through thecodecov.ymlhttps://docs.codecov.io/docs/codecov-yaml

We are happy to help if you have any questions. Please contact email our Support atsupport@codecov.io

License

FOSSA Status

About

Example repo for uploading reports to Codecov

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp