Skip to content

Commit

Permalink
Leverage command return value instead of process.exit.
Browse files Browse the repository at this point in the history
Works around an upstream issue in ember-cli 2.13 canary versions,
and is quite a bit easier to test.

Also tweaked SIGINT handling to queue up a cancel and avoid additional
work. This is because in ember-cli 2.9+ we use `capture-exit` so that
`process.exit()` does not immediately schedule an exit any longer (so
the semantics that we intended with the prior SIGINT logic were generally
broken already).
  • Loading branch information
rwjblue committed Feb 19, 2017
1 parent 70a9279 commit 9971720
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 110 deletions.
38 changes: 19 additions & 19 deletions lib/tasks/try-each.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,11 @@ module.exports = CoreObject.extend({
dependencyManagerAdapters: dependencyManagerAdapters
});

var shutdownCount = 0;
task._canceling = false;
task._on('SIGINT', function() {
if (shutdownCount === 0) {
shutdownCount++;
task.ui.writeLine('\nGracefully shutting down from SIGINT (Ctrl-C)');
return task.ScenarioManager.cleanup().then(function() {
task._exit();
});
} else {
task.ui.writeLine('\nOk, but it\'s going to be a mess');
task._exit();
}
task._canceling = true;
task.ui.writeLine('\nGracefully shutting down from SIGINT (Ctrl-C)');
return task.ScenarioManager.cleanup()
});

return task.ScenarioManager.setup().then(function() {
Expand All @@ -40,22 +33,28 @@ module.exports = CoreObject.extend({
return task._optionallyCleanup(options).then(function() {
debug('Output results');
task._printResults(results);
task._exitAsAppropriate(results);
return task._exitAsAppropriate(results);
});
}).catch(function(err) {
task.ui.writeLine(chalk.red('Error!'));
if (err) {
task.ui.writeLine(chalk.red(err));
task.ui.writeLine(chalk.red(err.stack));
}
task._exit(1);
// exitCode 1
return 1;
});
},

_runCommandForThisScenario: function(scenario) {
var task = this;

if (task._canceling) { return; }

return task.ScenarioManager.changeTo(scenario)
.then(function(scenarioDependencyState) {
if (task._canceling) { return; }

process.env.EMBER_TRY_CURRENT_SCENARIO = scenario.name;
task._writeHeader('Scenario: ' + scenario.name);
var command = task._determineCommandFor(scenario);
Expand All @@ -69,6 +68,8 @@ module.exports = CoreObject.extend({
debug('With:\n', runResults);

return task._runCommand({commandArgs: command, commandOptions: task._commandOptions()}).then(function(result) {
if (task._canceling) { return; }

runResults.result = result;
task._writeFooter('Result: ' + result);
return RSVP.resolve(runResults);
Expand Down Expand Up @@ -130,7 +131,8 @@ module.exports = CoreObject.extend({
var outcomes = results.map(function(result) {
return result.result || result.allowedToFail;
});
this._exitBasedOnCondition(outcomes.indexOf(false) > -1);

return this._exitBasedOnCondition(outcomes.indexOf(false) > -1);
},

_optionallyCleanup: function(options) {
Expand All @@ -151,11 +153,9 @@ module.exports = CoreObject.extend({
},

_exitBasedOnCondition: function(condition) {
if (condition) {
this._exit(1);
} else {
this._exit(0);
}
var exitCode = condition ? 1 : 0;
debug('Exit %s', exitCode);
return exitCode;
},

_exit: function(code) {
Expand Down
Loading

0 comments on commit 9971720

Please sign in to comment.