Skip to content

Commit f3dbc40

Browse files
committed
Split jest task into two
This ensures that we don't make jest do the additional tracking it needs to make coverage work.
1 parent bbef295 commit f3dbc40

File tree

2 files changed

+40
-19
lines changed

2 files changed

+40
-19
lines changed

Gruntfile.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,12 @@ module.exports = function(grunt) {
111111
]);
112112
grunt.registerTask('build:react-dom', require('./grunt/tasks/react-dom'));
113113

114-
grunt.registerTask('test', ['jest']);
115-
grunt.registerTask('npm:test', ['build', 'npm:pack']);
114+
var jestTasks = require('./grunt/tasks/jest');
115+
grunt.registerTask('jest:normal', jestTasks.normal);
116+
grunt.registerTask('jest:coverage', jestTasks.coverage);
116117

117-
grunt.registerTask('jest', require('./grunt/tasks/jest'));
118+
grunt.registerTask('test', ['jest:normal']);
119+
grunt.registerTask('npm:test', ['build', 'npm:pack']);
118120

119121
// Optimized build task that does all of our builds. The subtasks will be run
120122
// in order so we can take advantage of that and only run build-modules once.

grunt/tasks/jest.js

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,29 +64,48 @@ function writeTempConfig(callback) {
6464
});
6565
}
6666

67-
module.exports = function() {
67+
function run(done, configPath) {
68+
grunt.log.writeln('running jest (this may take a while)');
69+
70+
var args = ['--harmony', path.join('node_modules', 'jest-cli', 'bin', 'jest')];
71+
if (configPath) {
72+
args.push('--config', configPath);
73+
}
74+
grunt.util.spawn({
75+
cmd: 'node',
76+
args: args,
77+
opts: { stdio: 'inherit', env: { NODE_ENV: 'test' } },
78+
}, function(spawnErr, result, code) {
79+
if (spawnErr) {
80+
onError(spawnErr);
81+
} else {
82+
grunt.log.ok('jest passed');
83+
}
84+
grunt.log.writeln(result.stdout);
85+
86+
done(code === 0);
87+
});
88+
}
89+
90+
function runJestNormally() {
6891
var done = this.async();
92+
run(done);
93+
}
6994

70-
grunt.log.writeln('running jest (this may take a while)');
95+
function runJestWithCoverage() {
96+
var done = this.async();
7197

7298
writeTempConfig(function(writeErr) {
7399
if (writeErr) {
74100
onError(writeErr);
75101
return;
76102
}
77-
grunt.util.spawn({
78-
cmd: 'node',
79-
args: ['--harmony', path.join('node_modules', 'jest-cli', 'bin', 'jest'), '--config', tempConfigPath],
80-
opts: { stdio: 'inherit', env: { NODE_ENV: 'test' } },
81-
}, function(spawnErr, result, code) {
82-
if (spawnErr) {
83-
onError(spawnErr);
84-
} else {
85-
grunt.log.ok('jest passed');
86-
}
87-
grunt.log.writeln(result.stdout);
88-
89-
done(code === 0);
90-
});
103+
104+
run(done, tempConfigPath);
91105
});
106+
}
107+
108+
module.exports = {
109+
normal: runJestNormally,
110+
coverage: runJestWithCoverage,
92111
};

0 commit comments

Comments
 (0)