diff --git a/tasks/watch.js b/tasks/watch.js index a768269..3a9946d 100644 --- a/tasks/watch.js +++ b/tasks/watch.js @@ -93,7 +93,10 @@ module.exports = function(grunt) { }); // Display stdout/stderr immediately spawned[i].stdout.on('data', function(buf) { grunt.log.write(String(buf)); }); - spawned[i].stderr.on('data', function(buf) { grunt.log.error(String(buf)); }); + spawned[i].stderr.on('data', function(buf) { + buf = grunt.log.uncolor(String(buf)); + if (!grunt.util._.isBlank(buf)) { grunt.log.error(buf); } + }); } }, 250); diff --git a/test/fixtures/multiTargets/Gruntfile.js b/test/fixtures/multiTargets/Gruntfile.js index 95ac63d..623f014 100644 --- a/test/fixtures/multiTargets/Gruntfile.js +++ b/test/fixtures/multiTargets/Gruntfile.js @@ -6,6 +6,7 @@ module.exports = function(grunt) { two: { message: 'two has changed' }, wait: { message: 'I waited 2s', wait: 2000 }, interrupt: { message: 'I want to be interrupted', wait: 5000 }, + fail: { fail: 1, message: 'This task should fail' } }, watch: { one: { @@ -24,6 +25,10 @@ module.exports = function(grunt) { files: ['lib/interrupt.js'], tasks: ['echo:interrupt'], options: { interrupt: true } + }, + fail: { + files: ['lib/fail.js'], + tasks: ['echo:fail'] } } }); diff --git a/test/fixtures/multiTargets/lib/fail.js b/test/fixtures/multiTargets/lib/fail.js new file mode 100644 index 0000000..743a693 --- /dev/null +++ b/test/fixtures/multiTargets/lib/fail.js @@ -0,0 +1 @@ +var fail = false; \ No newline at end of file diff --git a/test/fixtures/tasks/echo.js b/test/fixtures/tasks/echo.js index 321be55..dde2c76 100644 --- a/test/fixtures/tasks/echo.js +++ b/test/fixtures/tasks/echo.js @@ -11,12 +11,17 @@ module.exports = function(grunt) { grunt.registerMultiTask('echo', 'A task that echos a message.', function() { var msg = this.data.message || 'I do absolutely nothing.'; var wait = this.data.wait || 0; + var fail = this.data.fail || false; var done = this.async(); - // After a given time print a message + // After a given time print a message or fail setTimeout(function() { - grunt.log.writeln(msg); - done(); + if (fail) { + grunt.fail.fatal(msg, fail); + } else { + grunt.log.writeln(msg); + done(); + } }, wait); // Keep the process alive diff --git a/test/tasks/watch_test.js b/test/tasks/watch_test.js index 7fd3648..461b48f 100644 --- a/test/tasks/watch_test.js +++ b/test/tasks/watch_test.js @@ -169,5 +169,18 @@ exports.watchConfig = { test.ok(result.indexOf('has been interrupted') !== -1, 'Task should have been interrupted.'); test.done(); }); + }, + failingTask: function(test) { + test.expect(2); + var cwd = path.resolve(fixtures, 'multiTargets'); + var assertWatch = assertTask('watch', {cwd:cwd}); + assertWatch(function() { + grunt.file.write(path.join(cwd, 'lib', 'fail.js'), 'var fail = false;'); + }, function(result) { + verboseLog(result); + test.ok(result.indexOf('') !== -1, 'Task should have been fatal.'); + test.equal(grunt.util._(result).count('Waiting...'), 2, 'Should have displayed "Wating..." twice'); + test.done(); + }); } };