gulp-jsx-coverage
Enable istanbul coverage on .JSX or .coffee files when you do mocha tests.
![License](https://img.shields.io/badge/license-MIT-green.svg)
This is not a gulp plugin, it just a task creator to help you deal with istanbul instrumenter and collect coverage report in gulp
Features
- Help you create a gulp task to handle mocha testing + istanbul coverage
- Transpile .jsx, .coffee, and .js (using ES6) 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!
- Customized everything by options
- Extract sourceMaps to hint original codes in istanbul reports
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
Usage
- 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/util/module files, do this only at application/server.js.
gulp.task('your_task_name', require('gulp-jsx-coverage').createTask({
src: ['test/**/*.js', 'test/components/*.jsx'],
istanbul: {
coverageVariable: '__MY_TEST_COVERAGE__',
exclude: /node_modules|test[0-9]/
},
transpile: {
babel: {
include: /\.jsx?$/,
exclude: /node_modules/
},
coffee: {
include: /\.coffee$/
}
},
coverage: {
reporters: ['text-summary', 'json', 'lcov'],
directory: 'coverage'
},
mocha: {
reporter: 'spec'
},
babel: {
sourceMap: 'inline'
},
coffee: {
sourceMap: true
},
cleanup: function () {
}
}));
Live Example
git clone https://github.com/zordius/gulp-jsx-coverage.git
cd gulp-jsx-coverage
npm install
npm test
Output:
[15:22:34] Using gulpfile ~/gulp-jsx-coverage/gulpfile.js
[15:22:34] Starting 'default'...
target (tested by test1.js)
✓ should multiply correctly
- should not show coverage info for test1.js
target (tested by test2.jsx)
✓ should multiply correctly (50ms)
- should not show coverage info for test2.jsx
target (tested by test3.coffee)
✓ should multiply correctly
- should not show coverage info for test3.coffee
3 passing (58ms)
3 pending
----------------|-----------|-----------|-----------|-----------|
File | % Stmts |% Branches | % Funcs | % Lines |
----------------|-----------|-----------|-----------|-----------|
test/ | 66.67 | 100 | 50 | 66.67 |
target.js | 66.67 | 100 | 50 | 66.67 |
----------------|-----------|-----------|-----------|-----------|
All files | 66.67 | 100 | 50 | 66.67 |
----------------|-----------|-----------|-----------|-----------|
[15:22:35] Finished 'default' after 753 ms