Coder Social home page Coder Social logo

example-node's Introduction

NodeJS / Javascript Example

https://codecov.io @codecov [email protected] IRC #codecov
install:
  - npm install -g codecov
script:
  - istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec
  - codecov

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 via codecov --token=:token or export CODECOV_TOKEN=":token"

Produce Coverage Reports

Mocha + Blanket.js

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

Mocha + JSCoverage

Instrumenting your app for coverage is probably harder than it needs to be (read here), 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/mocha test -R mocha-lcov-reporter

Istanbul

With Mocha:

istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && codecov

With Jasmine:

istanbul cover jasmine-node --captureExceptions spec/

With Karma:

The lcov.info can be used as in other configurations. Some projects experienced better results using json output but it is no longer enabled by default. In karma.config.js both can be enabled:

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

In package.json supply either lcov.info or coverage-final.json to codecov:

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

Nodeunit + JSCoverage

Depend on nodeunit and jscoverage:

npm install nodeunit jscoverage codecov --save-dev

Add a codecov script to "scripts" in your package.json:

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

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

Run your tests with a command like this:

npm run codecov

Poncho

Client-side JS code coverage using PhantomJS, Mocha and Blanket:

  • Configure Mocha for browser
  • Mark target script(s) with data-cover html-attribute
  • Run your tests with a command like this:
./node_modules/.bin/poncho -R lcov test/test.html && codecov

Lab

lab -r lcov && codecov

JSX

There have been reports of gotwarlost/istanbul not working properly with JSX files, which provide innaccuray coverage results. Please try using ambitioninc/babel-istanbul.

example-node's People

Contributors

saschwarz avatar stevepeak avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.