Permalink
Browse files

Fix things for the newest PhantomJS. Fixes #57.

  • Loading branch information...
1 parent ac37c42 commit 302c23881f36106d4dd5d17d24f1d17c63322a65 @emezeske committed Mar 20, 2012
@@ -20,6 +20,18 @@ Set up and start the server like this:
Now, point your web browser at `http://localhost:3000`, and see the web app in action!
+## PhantomJS
+
+[PhantomJS] (http://www.phantomjs.org) is a headless Webkit browser, which can be automated
+via Javascript. It provides a Javascript execution environment with access to all browser
+features (the DOM, etc), without opening a browser GUI.
+
+The tests and the "phantom-*" REPLs require PhantomJS 1.3 or newer to be installed.
+The process for accomplishing This is OS dependent. See [PhantomJS] (http://www.phantomjs.org)
+for information on installing it on your OS.
+
+If you do not plan to run the tests and only want to use the rhino or firefox REPLs, you can skip this step.
+
## Running the Tests
To run the unit tests:
@@ -36,8 +48,8 @@ be compiled, so they have their own entry in the `:builds` configuration. Note
all of the `:source-path` entries from the `:builds` are added to the classpath, so
the tests can `:require` ClojureScript namespaces from, e.g., the `src-cljs` directory.
-The example configuration uses [PhantomJS] (http://www.phantomjs.org) to run the tests.
-See the `phantom/unit-test.js` file for details on how this works.
+See the `phantom/unit-test.js` file for more details on how PhantomJS is configured to
+make this work.
## Connecting Firefox to a REPL
@@ -64,10 +76,6 @@ need to have your app running in the background:
## Connecting PhantomJS to a REPL
-[PhantomJS] (http://www.phantomjs.org) is a headless Webkit browser, which can be automated
-via Javascript. It provides a Javascript execution environment with access to all browser
-features (the DOM, etc), without opening a browser GUI.
-
To try out a PhantomJS-based REPL, first start the Ring server in one terminal:
$ lein ring server-headless 3000
@@ -3,8 +3,9 @@ if (phantom.args.length != 1) {
phantom.exit(1);
}
-var page = new WebPage();
+var page = require('webpage').create();
var url = phantom.args[0];
+var page_opened = false;
page.onConsoleMessage = function (message) {
console.log("App console: " + message);
@@ -13,6 +14,15 @@ page.onConsoleMessage = function (message) {
console.log("Loading URL: " + url);
page.open(url, function (status) {
+ // FIXME: This is a horrible, ridiculous hack. For some reason, PhantomJS calls
+ // page.open() twice, and if doesn't return immediately the second time,
+ // things break. Reference:
+ // http://code.google.com/p/phantomjs/issues/detail?id=353&q=wait&sort=-type
+ if (page_opened) {
+ return;
+ }
+ page_opened = true;
+
if (status != "success") {
console.log('Failed to open ' + url);
phantom.exit(1);
@@ -3,7 +3,7 @@ if (phantom.args.length != 1) {
phantom.exit(1);
}
-var page = new WebPage();
+var page = require('webpage').create();
var url = phantom.args[0];
page.onConsoleMessage = function (message) {

0 comments on commit 302c238

Please sign in to comment.