//
// A PhantomJS script used to check that the hosted examples load
// without errors. This script is executed by the Makefile's
// check-examples target.
//
var args = require('system').args;
if (args.length != 2) {
  phantom.exit(1);
}
var examplePath = args[1];
var page = require('webpage').create();
var exitCode = 0;
page.onError = function(msg, trace) {
  var msgStack = ['JavaScript ERROR: ' + msg];
  if (trace) {
    msgStack.push('TRACE:');
    trace.forEach(function(t) {
      msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function + '")' : ''));
    });
  }
  console.error(msgStack.join('\n'));
  exitCode = 2;
};
page.onConsoleMessage = function(msg) {
  console.log('console:', msg);
  exitCode = 2;
};
page.open(examplePath, function(s) {
  if (s != 'success') {
    console.error('PAGE LOAD ERROR');
    phantom.exit(2);
  }

  setTimeout(function() {
    console.log("EXIT", exitCode)
    phantom.exit(exitCode);
  }, 3000)
});

//
// A PhantomJS script used to check that the hosted examples load
// without errors. This script is executed by the Makefile's
// check-examples target.
//
var args = require('system').args;
if (args.length != 2) {
  phantom.exit(2);
}
var examplePath = args[1];
var page = require('webpage').create();
page.onError = function(msg, trace) {
  var msgStack = ['JavaScript ERROR: ' + msg];
  if (trace) {
    msgStack.push('TRACE:');
    trace.forEach(function(t) {
      msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function + '")' : ''));
    });
  }
  console.error(msgStack.join('\n'));
  phantom.exit(1);
};
page.open(examplePath, function(s) {
  var exitCode = 0;
  if (s != 'success') {
    exitCode = 1;
    console.error('PAGE LOAD ERROR');
  }
  phantom.exit(exitCode);
});
page.onConsoleMessage = function(msg) {
  console.log('console:', msg);
  phantom.exit(msg.match(/error/i) ? 1 : 0);
};

--- 
+++ 
@@ -5,10 +5,11 @@
 //
 var args = require('system').args;
 if (args.length != 2) {
-  phantom.exit(2);
+  phantom.exit(1);
 }
 var examplePath = args[1];
 var page = require('webpage').create();
+var exitCode = 0;
 page.onError = function(msg, trace) {
   var msgStack = ['JavaScript ERROR: ' + msg];
   if (trace) {
@@ -18,17 +19,20 @@
     });
   }
   console.error(msgStack.join('\n'));
-  phantom.exit(1);
+  exitCode = 2;
+};
+page.onConsoleMessage = function(msg) {
+  console.log('console:', msg);
+  exitCode = 2;
 };
 page.open(examplePath, function(s) {
-  var exitCode = 0;
   if (s != 'success') {
-    exitCode = 1;
     console.error('PAGE LOAD ERROR');
+    phantom.exit(2);
   }
-  phantom.exit(exitCode);
+
+  setTimeout(function() {
+    console.log("EXIT", exitCode)
+    phantom.exit(exitCode);
+  }, 3000)
 });
-page.onConsoleMessage = function(msg) {
-  console.log('console:', msg);
-  phantom.exit(msg.match(/error/i) ? 1 : 0);
-};
Make the application check working

Not so good because I don't find any way to know how to know the
application is loaded (the event $viewContentLoaded is never emmited ...)
