@samitouri / QOS-React / commits / f3dbc40261

Split jest task into two

This ensures that we don't make jest do the additional tracking it needs to make coverage work.

Paul O’Shannessy committed Dec 22, 2015 at 10:25 UTC f3dbc40261cf56f2fdeacf1ad9c82be6d6c251cf
2 files changed +40 -19
Gruntfile.js
+5 -3
@@ -111,10 +111,12 @@ module.exports = function(grunt) {
111 ]);
112 grunt.registerTask('build:react-dom', require('./grunt/tasks/react-dom'));
113
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);
117
117 - grunt.registerTask('jest', require('./grunt/tasks/jest'));
118 + grunt.registerTask('test', ['jest:normal']);
119 + grunt.registerTask('npm:test', ['build', 'npm:pack']);
120
121 // Optimized build task that does all of our builds. The subtasks will be run
122 // in order so we can take advantage of that and only run build-modules once.
grunt/tasks/jest.js
+35 -16
@@ -64,29 +64,48 @@ function writeTempConfig(callback) {
64 });
65 }
66
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() {
91 var done = this.async();
92 + run(done);
93 +}
94
70 - grunt.log.writeln('running jest (this may take a while)');
95 +function runJestWithCoverage() {
96 + var done = this.async();
97
98 writeTempConfig(function(writeErr) {
99 if (writeErr) {
100 onError(writeErr);
101 return;
102 }
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);
105 });
106 +}
107 +
108 +module.exports = {
109 + normal: runJestNormally,
110 + coverage: runJestWithCoverage,
111 };