2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ES2015(ES6) + mocha + gulpで test coverage出す

Posted at

いろいろ迷ったのでメモ。結局 gulp-istanbulispartaを使った

istanbulもispartaもコードカバレッジツールだが、
ispartaがes2015対応なので、instrumenterにispartaのものを使っている

インストール

npm install --save-dev gulp-istanbul 
npm insatll --save-dev isparta       

Version

$node -v
  v0.12.0 
$npm list
  ...
  ..mocha@2.3.4
  ..gulp@3.9.0
  ..gulp-istanbul@0.10.3
  ..istanbul@0.4.2
  ..isparta@4.0.0

gulpfileを編集

gulpfile.js
import gulp     from 'gulp'
import mocha    from 'gulp-mocha'
import istanbul from 'gulp-istanbul'

const SOURCES    = 'src/**/*.js'
const TEST_FILES = 'test/**/*.js'

gulp.task('pre-test-coverage', () => {
  return gulp.src(SOURCES)
             .pipe(istanbul( { instrumenter: require('isparta').Instrumenter }))
             .pipe(istanbul.hookRequire());
})

gulp.task('test:coverage', ['pre-test-coverage'], () => {
  return gulp.src(TEST_FILES)
             .pipe(mocha())
             .pipe(istanbul.writeReports())
             .pipe(istanbul.enforceThresholds({ thresholds: { global: 90 } }));
})

実行

gulp test:coverage

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?