From dfa6953aaf3d53755e46ab9838f6b921ce057c2a Mon Sep 17 00:00:00 2001 From: Brian Lai Date: Sat, 13 Jul 2013 00:22:44 -0700 Subject: [PATCH] Fix to make interrupt work more than once. Closes GH-155. --- tasks/lib/taskrun.js | 8 +++++--- test/fixtures/multiTargets/Gruntfile.js | 2 +- test/fixtures/multiTargets/lib/interrupt.js | 2 +- test/tasks/watch_test.js | 14 ++++++++++---- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/tasks/lib/taskrun.js b/tasks/lib/taskrun.js index 2311db4..abd42fa 100644 --- a/tasks/lib/taskrun.js +++ b/tasks/lib/taskrun.js @@ -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(); + } }); } }; diff --git a/test/fixtures/multiTargets/Gruntfile.js b/test/fixtures/multiTargets/Gruntfile.js index fe0444e..397b8f4 100644 --- a/test/fixtures/multiTargets/Gruntfile.js +++ b/test/fixtures/multiTargets/Gruntfile.js @@ -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' }, }, diff --git a/test/fixtures/multiTargets/lib/interrupt.js b/test/fixtures/multiTargets/lib/interrupt.js index 5671f07..3d48656 100644 --- a/test/fixtures/multiTargets/lib/interrupt.js +++ b/test/fixtures/multiTargets/lib/interrupt.js @@ -1 +1 @@ -var interrupt = true; \ No newline at end of file +var interrupt = 3; \ No newline at end of file diff --git a/test/tasks/watch_test.js b/test/tasks/watch_test.js index 1ecf764..8133a05 100644 --- a/test/tasks/watch_test.js +++ b/test/tasks/watch_test.js @@ -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(); }); },