Created
August 13, 2015 09:55
-
-
Save fdubost/856fcef37e8f1c49609e to your computer and use it in GitHub Desktop.
Tip to add `--name` option to jest with gulp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var gulp = require('gulp'); | |
var _ = require('lodash'); | |
var jest = require('jest-cli'); | |
var minimist = require('minimist'); | |
var gulpCliOptions = minimist(process.argv.slice(2)); | |
var config = require('./jest.config'); | |
gulp.task('jest', 'Run Jest tests.', function (done) { | |
// underscore (i.e. the no name argument) is the name of the gulp task | |
var toAssign = _.omit(gulpCliOptions, '_'); | |
// name is not a jest CLI option, it corresponds to the _ arg of jest CLI (replaced by a regexp here) | |
if (gulpCliOptions.name) { | |
toAssign.testPathPattern = new RegExp(gulpCliOptions.name); | |
} | |
var cliOptions = _.assign({config: config}, toAssign); | |
jest.runCLI(cliOptions, config.rootDir, function (success) { | |
if (success) { | |
done(); | |
} else { | |
done(new Error('Tests failed')); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment