Dont display empty stderr. Add test for failing task
This commit is contained in:
parent
c01ba9f2fe
commit
3682c6e654
@ -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);
|
||||
|
||||
|
5
test/fixtures/multiTargets/Gruntfile.js
vendored
5
test/fixtures/multiTargets/Gruntfile.js
vendored
@ -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']
|
||||
}
|
||||
}
|
||||
});
|
||||
|
1
test/fixtures/multiTargets/lib/fail.js
vendored
Normal file
1
test/fixtures/multiTargets/lib/fail.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
var fail = false;
|
11
test/fixtures/tasks/echo.js
vendored
11
test/fixtures/tasks/echo.js
vendored
@ -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
|
||||
|
@ -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();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user