Giter VIP home page Giter VIP logo

dgreif / gulp-jsx-coverage Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zordius/gulp-jsx-coverage

0.0 2.0 0.0 782 KB

Enable istanbul coverage on ES6/babel or coffee-script files when you do mocha/jasmine tests, also deal with sourceMap for coverage report and stack trace.

Home Page: https://www.npmjs.com/package/gulp-jsx-coverage

License: Other

JavaScript 90.04% CoffeeScript 4.68% Shell 5.28%

gulp-jsx-coverage's Introduction

gulp-jsx-coverage

Enable istanbul coverage on ES6/babel or coffee-script files when you do mocha/jasmine tests, also deal with sourceMap for coverage report and stack trace.

npm version npm download Dependency Status Build Status License

Features

  • Help you create a gulp task to handle mocha testing + istanbul coverage
  • Transpile .jsx, .coffee, and ES6 .js files on the fly
  • Use babel (6to5) to transpile .js and .jsx files so you can use ES6 features inside your .js and .jsx files!
  • Customize everything by options
  • Extract sourceMaps to hint original codes in istanbul reports
  • sourceMaps on stack traces when mocha test failed
  • coverage threshold

Install

npm install gulp-jsx-coverage mocha --save-dev
  • You will need to install coffee-script when you require('foobar.coffee') or write tests as foobar.coffee
  • The golden rule: Use .jsx as ext name , require('file.jsx')
  • The golden rule: Use .coffee as ext name , require('file.coffee')
  • Regular JavaScript files with .js extension may use ES6 features, including mocha tests
  • No need to use transform tools to register .jsx or .coffee for require() at library or util or module files, do this only at application or server.js.

Usage: General Mocha Test Creator

gulp.task('your_task_name', require('gulp-jsx-coverage').createTask({
    src: ['test/**/*.js', 'test/components/*.jsx'],  // will pass to gulp.src as mocha tests
    istanbul: {                                      // will pass to istanbul
        coverageVariable: '__MY_TEST_COVERAGE__',
        exclude: /node_modules|test[0-9]/            // do not instrument these files
    },

    threshold: 80,                                   // fail the task when coverage lower than this
                                                     // default is no threshold
    thresholdType: 'functions',                      // one of 'lines', 'statements', 'functions', 'banches'
                                                     // default is 'lines'

    transpile: {                                     // this is default whitelist/blacklist for transpilers
        babel: {
            include: /\.jsx?$/,
            exclude: /node_modules/
        },
        coffee: {
            include: /\.coffee$/
        }
    },
    coverage: {
        reporters: ['text-summary', 'json', 'lcov'], // list of istanbul reporters
        directory: 'coverage'                        // will pass to istanbul reporters
    },
    mocha: {                                         // will pass to mocha
        reporter: 'spec'
    },
    babel: {                                         // will pass to babel
        sourceMap: 'both'                            // get hints in covarage reports or error stack
    },
    coffee: {                                        // will pass to coffee.compile
        sourceMap: true                              // true to get hints in HTML coverage reports
    },

    //optional
    cleanup: function () {
        // do extra tasks after test done
        // EX: clean global.window when test with jsdom
    }
}));

Usage: Other Testing Frameworks

var GJC = require('gulp-jsx-coverage');
var jasmine = require('gulp-jasmine');

gulp.task('my_jasmine_tests', function () {
    GJC.initIstanbulHook(GJCoptions); // Refer to previous gulp-jsx-coverage options

    return gulp.src('test/*.js')
    .pipe(jasmine(jasmineOptions))
    .on('end', GJC.colloectIstanbulCoverage(GJCoptions));
});

Live Example: mocha

git clone https://github.com/zordius/gulp-jsx-coverage.git
cd gulp-jsx-coverage
npm install
npm run mocha_test

Output:

[13:00:52] Using gulpfile ~/gulp-jsx-coverage/gulpfile.js
[13:00:52] Starting 'default'...


  target (tested by test1.js)
    ✓ should multiply correctly
    - should not show coverage info for test1.js
    ✓ should handle es6 template string correctly

  target (tested by test2.jsx)
    ✓ should multiply correctly
    - should not show coverage info for test2.jsx

  target (tested by test3.coffee)
    ✓ should multiply correctly
    - should not show coverage info for test3.coffee


  4 passing (42ms)
  3 pending

----------------|-----------|-----------|-----------|-----------|
File            |   % Stmts |% Branches |   % Funcs |   % Lines |
----------------|-----------|-----------|-----------|-----------|
   test/        |        80 |       100 |     66.67 |        80 |
      target.js |        80 |       100 |     66.67 |        80 |
----------------|-----------|-----------|-----------|-----------|
All files       |        80 |       100 |     66.67 |        80 |
----------------|-----------|-----------|-----------|-----------|

[13:00:53] Finished 'default' after 642 ms

Upgrade Notice

0.2.0

  • the sourceMap stack trace feature requires:
    • mocha >= 2.2.2
    • the options.babel.sourceMap should be changed from 'inline' to 'both'

gulp-jsx-coverage's People

Contributors

andrewzey avatar dgreif avatar sstenerdal 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.