Split jest task into two

This ensures that we don't make jest do the additional tracking it needs to make coverage work.
This commit is contained in:
Paul O’Shannessy
2015-12-22 10:25:34 -08:00
parent bbef2958b2
commit f3dbc40261
2 changed files with 40 additions and 19 deletions

View File

@@ -111,10 +111,12 @@ module.exports = function(grunt) {
]);
grunt.registerTask('build:react-dom', require('./grunt/tasks/react-dom'));
grunt.registerTask('test', ['jest']);
grunt.registerTask('npm:test', ['build', 'npm:pack']);
var jestTasks = require('./grunt/tasks/jest');
grunt.registerTask('jest:normal', jestTasks.normal);
grunt.registerTask('jest:coverage', jestTasks.coverage);
grunt.registerTask('jest', require('./grunt/tasks/jest'));
grunt.registerTask('test', ['jest:normal']);
grunt.registerTask('npm:test', ['build', 'npm:pack']);
// Optimized build task that does all of our builds. The subtasks will be run
// in order so we can take advantage of that and only run build-modules once.

View File

@@ -64,29 +64,48 @@ function writeTempConfig(callback) {
});
}
module.exports = function() {
var done = this.async();
function run(done, configPath) {
grunt.log.writeln('running jest (this may take a while)');
var args = ['--harmony', path.join('node_modules', 'jest-cli', 'bin', 'jest')];
if (configPath) {
args.push('--config', configPath);
}
grunt.util.spawn({
cmd: 'node',
args: args,
opts: { stdio: 'inherit', env: { NODE_ENV: 'test' } },
}, function(spawnErr, result, code) {
if (spawnErr) {
onError(spawnErr);
} else {
grunt.log.ok('jest passed');
}
grunt.log.writeln(result.stdout);
done(code === 0);
});
}
function runJestNormally() {
var done = this.async();
run(done);
}
function runJestWithCoverage() {
var done = this.async();
writeTempConfig(function(writeErr) {
if (writeErr) {
onError(writeErr);
return;
}
grunt.util.spawn({
cmd: 'node',
args: ['--harmony', path.join('node_modules', 'jest-cli', 'bin', 'jest'), '--config', tempConfigPath],
opts: { stdio: 'inherit', env: { NODE_ENV: 'test' } },
}, function(spawnErr, result, code) {
if (spawnErr) {
onError(spawnErr);
} else {
grunt.log.ok('jest passed');
}
grunt.log.writeln(result.stdout);
done(code === 0);
});
run(done, tempConfigPath);
});
}
module.exports = {
normal: runJestNormally,
coverage: runJestWithCoverage,
};