Permalink
Browse files

Work around for phantom.exit not always exiting correctly on Windows.…

… Upgrade to phantomjs 1.9.0.
  • Loading branch information...
1 parent 26122c1 commit 6f7d5ba70231d9ae4cc99e3eb09a275f6c68998d Robert Coulson committed May 17, 2013
@@ -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);
@@ -18,7 +18,7 @@ page.onError = function (msg, trace) {
console.log(' ', item.file, ':', item.line);
});
- phantom.exit(1);
+ exit(1);
};
page.onInitialized = function() {
@@ -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);
}
@@ -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 not shown.

0 comments on commit 6f7d5ba

Please sign in to comment.