Gulp如何将Mocha grep参数传递给我的任务?

时间:2014-05-13 07:53:30

标签: mocha gulp

我有我的gulpfile.coffee

gulp  = require 'gulp'

coffeelint = require 'gulp-coffeelint'
mocha      = require 'gulp-mocha'
plumber    = require 'gulp-plumber'
gutil      = require 'gulp-util'
watch      = require 'gulp-watch'

handleError = (err) ->
  console.error err.message
  process.exit 1

gulp.task 'test', ->
  gulp.src('test/*-test.*')
    .pipe(mocha(reporter: 'spec'))
    .on 'error', handleError

我需要运行gulp test --grep group1,我找到options.grep但我不知道如何从CLI继续参数。

1 个答案:

答案 0 :(得分:4)

已解决:使用yargs npm package

gulp  = require 'gulp'

coffeelint = require 'gulp-coffeelint'
mocha      = require 'gulp-mocha'
plumber    = require 'gulp-plumber'
gutil      = require 'gulp-util'
watch      = require 'gulp-watch'
yargs      = require 'yargs'

handleError = (err) ->
  console.error err.message
  process.exit 1

gulp.task 'test', ->
  gulp.src('test/*-test.*')
    .pipe(mocha(reporter: 'spec', grep: yargs.argv.grep))
    .on 'error', handleError