gulp-babel-istanbul
raw JSON → 1.6.0 verified Sat Apr 25 auth: no javascript maintenance
A gulp plugin that instruments source files with Istanbul code coverage after Babel transpilation, enabling ES2015+ coverage reporting. Version 1.6.0 (latest) uses babel-istanbul under the hood. It integrates with any Node.js test framework via gulp, providing hooks for require and reports. Compared to alternatives like gulp-istanbul, it natively handles Babel-transpiled code. Browser testing is untested. Requires gulp, babel, and Istanbul. Slow release cadence; last update 2016. Consider seamless builds with webpack or karma for browser coverage.
Common errors
error Error: Cannot find module 'babel/register' ↓
cause Plugin expects babel-istanbul but babel-core is not installed or outdated
fix
npm install babel-core@^6 --save-dev
error TypeError: istanbul.hookRequire is not a function ↓
cause hookRequire is not called on the default export directly
fix
Use require('gulp-babel-istanbul').hookRequire or import { hookRequire } from 'gulp-babel-istanbul'
error ENOENT: no such file or directory, open 'coverage/lcov.info' ↓
cause writeReports expects a coverage variable that may not exist
fix
Ensure istanbul() and hookRequire() are applied before running tests
error The coverage report is empty ↓
cause includeUntested option false by default and require hook not applied
fix
Set { includeUntested: true } and ensure hookRequire() is piped
Warnings
gotcha hookRequire must be used in the same stream after istanbul() ↓
fix Call .pipe(istanbul.hookRequire()) before the finish event.
gotcha Browser testing is untested and may not work ↓
fix Use Karma with karma-coverage instead for browser coverage.
deprecated babel-core is replaced by @babel/core ↓
fix Use gulp-babel with @babel/core and @babel/preset-env; this plugin uses babel-istanbul which may not be updated.
gotcha require hook does not work with ESM modules ↓
fix Use CommonJS modules or transpile to CJS before testing.
Install
npm install gulp-babel-istanbul yarn add gulp-babel-istanbul pnpm add gulp-babel-istanbul Imports
- istanbul wrong
const istanbul = require('gulp-babel-istanbul').defaultcorrectimport istanbul from 'gulp-babel-istanbul' - hookRequire wrong
require('gulp-babel-istanbul').hookRequirecorrectimport { hookRequire } from 'gulp-babel-istanbul' - writeReports wrong
istanbul.writeReports()correctimport { writeReports } from 'gulp-babel-istanbul'
Quickstart
const gulp = require('gulp');
const babel = require('gulp-babel');
const istanbul = require('gulp-babel-istanbul');
const mocha = require('gulp-mocha');
gulp.task('coverage', function (cb) {
gulp.src('src/**/*.js')
.pipe(istanbul())
.pipe(istanbul.hookRequire())
.on('finish', function () {
gulp.src('test/**/*.js')
.pipe(babel())
.pipe(mocha())
.pipe(istanbul.writeReports())
.pipe(istanbul.enforceThresholds({ thresholds: { global: 90 } }))
.on('end', cb);
});
});