Skip to content

Commit

Permalink
Fix gulp test task
Browse files Browse the repository at this point in the history
jest.runCLI() was being called with only 1 argument, there was a mis-bracketing
which lead to this. When trying to fix the bracketing here, I realised the
error handling callback also did not work correctly (done was undefined), and
the 'test' task considered itself succeeded before the tests were even run.

I've refactored the task a little to successfully "fail" when the tests fail,
which means that "gulp test" will now return a non-zero exit code when the
tests fail.
  • Loading branch information
s0 committed Dec 10, 2018
1 parent 06f5521 commit f7e5810
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ gulp.task('webserver', function() {
connectTask();
});

gulp.task('test', function() {
jestTask();
gulp.task('test', function(callback) {
return jestTask(callback);
});

gulp.task('scripts', function() {
Expand Down
13 changes: 8 additions & 5 deletions tasks/jest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var jest = require('jest-cli');
var gutil = require('gulp-util');
var configs = require('./configs');

var jestConfig = {
Expand All @@ -10,8 +9,12 @@ var jestConfig = {
verbose: false
};

module.exports = function() {
jest.runCLI({ config: jestConfig }), configs.paths.source, function() {
done().on('error', gutil.log);
};
module.exports = function(callback) {
jest.runCLI({ config: jestConfig }, configs.paths.source, function(result) {
if (!result || !result.success) {
callback('Jest tests failed')
} else {
callback()
}
});
};

0 comments on commit f7e5810

Please sign in to comment.