Skip to content

Commit

Permalink
Fix things for the newest PhantomJS. Fixes #57.
Browse files Browse the repository at this point in the history
  • Loading branch information
emezeske committed Mar 20, 2012
1 parent ac37c42 commit 302c238
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
20 changes: 14 additions & 6 deletions example-projects/advanced/README.md
Expand Up @@ -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:
Expand All @@ -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

Expand All @@ -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
Expand Down
12 changes: 11 additions & 1 deletion example-projects/advanced/phantom/repl.js
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion example-projects/advanced/phantom/unit-test.js
Expand Up @@ -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) {
Expand Down

0 comments on commit 302c238

Please sign in to comment.