We were having an issue with phantomjs not exiting the process cleanly. I have managed to monkey patch this for our purposes, but would like to get input from the JS MVC on the problem and real solution. When we had multiple tests being run through the .then() function in our funcunit.js, then the process would hang and never call 'phantomexit'. In the
/steal/browser/phantomjs/client.js file, I added the following line in the steal.client.trigger() function after steal.client.phantomexit=true:
- if(type == "done"){
- steal.client.phantomexit = true;
- window.cb(); //New line added to force phantom to exit.
- }
Environment: JS MVC 3.2.2, phantomJS 1.7, windows 7
Gory details are below:
Our funcunit.js file looks like this, and was causing phantomjs to hang after executing the funcunit tests successfully:
steal("funcunit")
.then("./test_setup")// simple page test
.then("./authentication_controller_test")
If we only ran the funcunit.js file with only a single test (steal("funcunit").then("./test_setup")), then phantomjs would exit cleanly. Once we added more tests, it started to break again.
What I noticed, after stepping through the code, was that steal.client.phantomexit was being set to true, but the call to exit phantomjs (and in turn close the server and kill the process) was not being called. I located this in the window.cb() function in the steal/browser/phantomjs/client.js file, and thus had to explicitly call it after steal.client.phantomexit was set to true. Only then would phantomjs exit cleanly if we specified multiple tests to be run in our funcunit.js file.
Is this fix valid/correct?