Dont display empty stderr. Add test for failing task

This commit is contained in:
Kyle Robinson Young 2012-10-31 17:12:03 -07:00
parent c01ba9f2fe
commit 3682c6e654
5 changed files with 31 additions and 4 deletions

View File

@ -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);

View File

@ -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']
}
}
});

View File

@ -0,0 +1 @@
var fail = false;

View File

@ -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

View File

@ -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('<FATAL>') !== -1, 'Task should have been fatal.');
test.equal(grunt.util._(result).count('Waiting...'), 2, 'Should have displayed "Wating..." twice');
test.done();
});
}
};