Skip to content

Instantly share code, notes, and snippets.

@martintrojer
Created September 15, 2015 18:02
Show Gist options
  • Save martintrojer/9a8e78126063705fabdb to your computer and use it in GitHub Desktop.
Save martintrojer/9a8e78126063705fabdb to your computer and use it in GitHub Desktop.
(function() {
var Ap = Array.prototype;
var slice = Ap.slice;
var Fp = Function.prototype;
if (!Fp.bind) {
// PhantomJS doesn't support Function.prototype.bind natively, so
// polyfill it whenever this module is required.
Fp.bind = function(context) {
var func = this;
var args = slice.call(arguments, 1);
function bound() {
var invokedAsConstructor = func.prototype && (this instanceof func);
return func.apply(
// Ignore the context parameter when invoking the bound function
// as a constructor. Note that this includes not only constructor
// invocations using the new keyword but also calls to base class
// constructors such as BaseClass.call(this, ...) or super(...).
!invokedAsConstructor && context || this,
args.concat(slice.call(arguments))
);
}
// The bound function must share the .prototype of the unbound
// function so that any object created by one constructor will count
// as an instance of both constructors.
bound.prototype = func.prototype;
return bound;
};
}
})();
<html>
<body>
<script> var apiUrl="http://api:8030"; </script>
<script> var sseUrl="http://see:8050"; </script>
<script src="phantomjs-shims.js" type="text/javascript"></script>
<script src="../target/site_tests.js" type="text/javascript"></script>
</body>
</html>
/*global phantom,setTimeout,require,last_test_run_successful */
var system = require('system');
var page = require('webpage').create();
var url = system.args[1];
page.onConsoleMessage = function (message) {
console.log(message);
};
function exit(code) {
setTimeout(function(){ phantom.exit(code); }, 0);
phantom.onError = function(){};
}
console.log("Loading URL: " + url);
page.open(url, function (status) {
if (status != "success") {
console.log('Failed to open ' + url);
phantom.exit(1);
}
var result = page.evaluate(function() {
return azondi.site.core_test.run_all_phantom();
});
var last_test_run_successful = page.evaluate(function () {
return last_test_run_successful;
});
if (last_test_run_successful) {
console.log("Tests succeeded.");
phantom.exit(0);
} else {
console.log("*** Tests failed! ***");
phantom.exit(1);
}
});
@bensu
Copy link

bensu commented Sep 15, 2015

What I think is happening:

  1. You start the tests in L24.
  2. The tests run until they reach the async part, and they are parked.
  3. The control is passed to the script which checks if the test were successful and terminates.

The point being: the script never returns the control to the tests. Chrome, on the other hand, doesn't have an exiting mechanism, so it just returns the control to the tests without exiting.

My current solution is to set a function in ClojureScript that listens if the tests are done (we've implemented the reporting event :end-run-tests specifically for this purpose) which then calls another function called *exit-fn* which can be set from the script, and does the final exit.

There is a lot of indirection going on and I realize my answer might not be clear. Don't hesitate to ask questions.

@martintrojer
Copy link
Author

Thanks! This solved it for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment