SBoudrias / gulp-istanbul

Istanbul unit test coverage plugin for gulp.
MIT License
186 stars 87 forks source link

how to cover es6 code #109

Closed modood closed 7 years ago

modood commented 7 years ago

My gulpfile.js:

'use strict'

const gulp = require('gulp')
const mocha = require('gulp-mocha')
const eslint = require('gulp-eslint')
const istanbul = require('gulp-istanbul')

const rootPath = ['**/*.js', '!node_modules/**', '!coverage/**']
const testPath = ['test/**/*.js']
const sourcePath = ['app/**/*.js']

gulp.task('eslint', () => gulp
  .src(rootPath)
  // attaches the lint output to the "eslint" property of the file object
  .pipe(eslint())
  // outputs the lint results to the console
  .pipe(eslint.format()))

gulp.task('istanbul', () => gulp
  .src(sourcePath)
  // Covering files
  .pipe(istanbul())
  // Force `require` to return covered files
  .pipe(istanbul.hookRequire()))

gulp.task('mocha', ['istanbul'], () => gulp
  .src(testPath, { read: false })
  .pipe(mocha({ reporter: 'spec' }))
  // Creating the reports after tests ran
  .pipe(istanbul.writeReports())
  // Enforce a coverage of at least 90%
  .pipe(istanbul.enforceThresholds({ thresholds: { global: 90 } })))

gulp.task('watch', () => gulp.watch(rootPath, ['eslint']))

gulp.task('test', ['eslint', 'mocha'])

gulp.task('default', ['test'])

Running the following command:

./node_modules/.bin/gulp --harmony mocha

mocha is fine everything works, but Istanbul does not recognize ES6 arrow function

SBoudrias commented 7 years ago

You need to provide an es6 compatible instrumenter https://github.com/SBoudrias/gulp-istanbul#instrumenter