diff --git a/lib/runner.js b/lib/runner.js index 5512a2508..c757c399e 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -84,6 +84,12 @@ var addConfig = function(additionalConfig) { var cleanUp = function(runner) { var passed = runner.results().failedCount == 0; var exitCode = passed ? 0 : 1; + var exit = function(exitCode) { + if (typeof config.onCleanUp === 'function') { + config.onCleanUp(exitCode); + } + process.exit(exitCode); + }; if (sauceAccount) { sauceAccount.updateJob(sessionId, {'passed': passed}, function(err) { if (err) { @@ -91,15 +97,15 @@ var cleanUp = function(runner) { "Error updating Sauce pass/fail status: " + util.inspect(err) ); } - process.exit(exitCode); + exit(exitCode); }); } else if (server) { util.puts('Shutting down selenium standalone server.'); server.stop().then(function() { - process.exit(exitCode); + exit(exitCode); }); } else { - process.exit(exitCode); + exit(exitCode); } }; diff --git a/referenceConf.js b/referenceConf.js index 046d9931e..2b5edbeb7 100644 --- a/referenceConf.js +++ b/referenceConf.js @@ -120,7 +120,7 @@ exports.config = { includeStackTrace: true, // Default time to wait in ms before a test fails. defaultTimeoutInterval: 30000 - } + }, // ----- Options to be passed to mocha ----- // @@ -128,5 +128,12 @@ exports.config = { mochaOpts: { ui: 'bdd', reporter: 'list' - } + }, + + // ----- The cleanup step ----- + // + // A callback function called once the tests have finished running and + // the webdriver instance has been shut down. It is passed the exit code + // (0 if the tests passed or 1 if not). + onCleanUp: function() {} };