Skip to content

Commit

Permalink
Merge pull request #114 from rwjblue/use-command-return-value-for-exi…
Browse files Browse the repository at this point in the history
…t-code

Leverage command return value instead of process.exit.
  • Loading branch information
rwjblue authored Feb 21, 2017
2 parents 70a9279 + 9d663eb commit e676104
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 110 deletions.
37 changes: 18 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,27 @@ 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);
return 1; // Signifies exit code
});
},

_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 +67,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 +130,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 +152,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 e676104

Please sign in to comment.