Fix to make interrupt work more than once. Closes GH-155.

pull/197/merge
Brian Lai 11 years ago committed by Kyle Robinson Young
parent 78e699e30e
commit dfa6953aaf

@ -58,9 +58,11 @@ module.exports = function(grunt) {
// Run grunt this process uses, append the task to be run and any cli options
args: self.tasks.concat(self.options.cliArgs || []),
}, function(err, res, code) {
// Spawn is done
self.spawned = null;
done();
if (self.options.interrupt !== true || code !== 130) {
// Spawn is done
self.spawned = null;
done();
}
});
}
};

@ -5,7 +5,7 @@ module.exports = function(grunt) {
one: { message: 'one has changed' },
two: { message: 'two has changed' },
wait: { message: 'I waited 2s', wait: 2000 },
interrupt: { message: 'I want to be interrupted', wait: 5000 },
interrupt: { message: 'I want to be interrupted', wait: 3000 },
fail: { fail: 1, message: 'This task should fail', wait: 1000 },
cwd: { message: 'cwd works' },
},

@ -1 +1 @@
var interrupt = true;
var interrupt = 3;

@ -124,17 +124,23 @@ exports.watch = {
});
},
interrupt: function(test) {
test.expect(1);
test.expect(2);
var cwd = path.resolve(fixtures, 'multiTargets');
var assertWatch = helper.assertTask('watch', {cwd:cwd});
assertWatch(function() {
grunt.file.write(path.join(cwd, 'lib', 'interrupt.js'), 'var interrupt = false;');
grunt.file.write(path.join(cwd, 'lib', 'interrupt.js'), 'var interrupt = 1;');
setTimeout(function() {
grunt.file.write(path.join(cwd, 'lib', 'interrupt.js'), 'var interrupt = true;');
grunt.file.write(path.join(cwd, 'lib', 'interrupt.js'), 'var interrupt = 2;');
}, 1000);
setTimeout(function() {
grunt.file.write(path.join(cwd, 'lib', 'interrupt.js'), 'var interrupt = 3;');
}, 2000);
}, function(result) {
helper.verboseLog(result);
test.ok(result.indexOf('have been interrupted') !== -1, 'Task should have been interrupted.');
var interruptMatches = result.match(/have been interrupted/g);
test.ok(interruptMatches && interruptMatches.length === 2, 'Task should have been interrupted 2 times.');
var unInterruptMatches = result.match(/I want to be interrupted/g);
test.ok(unInterruptMatches && unInterruptMatches.length === 1, 'Only the last time should be working (without interruption)');
test.done();
});
},

Loading…
Cancel
Save