Skip to content

Commit

Permalink
Work around for phantom.exit not always exiting correctly on Windows.…
Browse files Browse the repository at this point in the history
… Upgrade to phantomjs 1.9.0.
  • Loading branch information
Robert Coulson committed May 17, 2013
1 parent 26122c1 commit 6f7d5ba
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/main/java/com/philmander/jstest/PhantomTestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,14 @@ public JsTestResults runTests(String[] testFiles) throws IOException {

StringBuilder message = new StringBuilder();
String line = null;
while ((line = input.readLine()) != null) {

boolean keepProcessing = true;
while (keepProcessing) {
line = input.readLine();
if (line != null && line.equalsIgnoreCase("EOF")) {
keepProcessing = false;
} else {
keepProcessing = true;
}
//TODO: totally need to refactor reporting parsing
if(logger != null) {
logger.log(line);
Expand Down
21 changes: 18 additions & 3 deletions src/main/resources/qunit-phantom-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ page.onError = function (msg, trace) {
console.log(' ', item.file, ':', item.line);
});

phantom.exit(1);
exit(1);
};

page.onInitialized = function() {
Expand Down Expand Up @@ -89,14 +89,14 @@ page.open(url, function(status){

if (status !== "success") {
console.log("Unable to access network: " + status);
phantom.exit(1);
exit(1);
} else {
var interval = setInterval(function() {


if (finished()) {
clearInterval(interval);
phantom.exit();
exit(0);
}
}, 100);
}
Expand All @@ -106,4 +106,19 @@ function finished() {
return page.evaluate(function(){
return window.qunitDone;
});
};

// Hack for phantom.exit not always working.
//
// PhantomTestRunner (see line 144) is looking for "EOF" while reading the process output stream
// and will break the processing loop (and eventually destroy the phantomjs.exe process) if EOF is detected.
//
// See
// https://groups.google.com/forum/?fromgroups#!topic/phantomjs/kaEzJ45VS0c
//
// for a lively discussion on phantomjs not always exiting properly in windows.
function exit(errorCode) {
console.log("Exiting with return code: " + errorCode);
console.log("EOF");
phantom.exit(errorCode);
};
Binary file modified src/test/resources/phantomjs.exe
Binary file not shown.

0 comments on commit 6f7d5ba

Please sign in to comment.