diff --git a/tests/javascript_tests/runner.js b/tests/javascript_tests/runner.js index 403d560d..2b49c019 100644 --- a/tests/javascript_tests/runner.js +++ b/tests/javascript_tests/runner.js @@ -51,7 +51,7 @@ result = message.data; failed = !result || result.failed; - phantom.exit(failed ? 1 : 0); + exit(failed ? 1 : 0); } } }; @@ -59,7 +59,7 @@ page.open(url, function(status) { if (status !== 'success') { console.error('Unable to access network: ' + status); - phantom.exit(1); + exit(1); } else { // Cannot do this verification with the 'DOMContentLoaded' handler because it // will be too late to attach it if a page does not have any script tags. @@ -136,4 +136,21 @@ }); }, false); } + + /* + This function was taken from: + https://github.com/jonkemp/qunit-phantomjs-runner + + It helps prevent some problems with the output produced by this script. + */ + function exit(code) { + if (page) { + page.close(); + } + setTimeout(function () { + phantom.exit(code); + }, 0); + } + + })();