Permalink
Browse files

Example of having Travis download the runner

  • Loading branch information...
1 parent 7470f16 commit 0479c9ea09383bb9f4559458d22024417b2d58f2 @mark-rushakoff committed Apr 9, 2012
Showing with 46 additions and 6 deletions.
  1. +16 −5 README.md
  2. +23 −0 travis.yml.example-download
  3. +7 −1 travis.yml.example → travis.yml.example-include
View
@@ -6,7 +6,10 @@ The scripts in PhantomJS's `examples` directory have no explicit license attache
I wrote these scripts as an explicitly MIT-licensed alternative that queries the backing test runner rather than being dependent on the result of the runner's DOM manipulations.
Hopefully, this means you can drop my scripts into your project and immediately start running your browser-based tests from the console -- as a bonus, if you have any concerns about license virality, these scripts should be far-removed enough from Phantom and Webkit to make you feel safe to include OpenPhantomScripts in your project.
-## Usage
+## Local usage
+
+If you plan on running your tests in phantomjs locally, you can copy `phantom-${runner}.js` into your repository or wherever is convenient for you.
+If you don't intend on running the tests in phantomjs locally, you can just have Travis CI automatically download the stable version of the correct test runner -- read ahead for directions.
These scripts can run against local files:
@@ -18,17 +21,25 @@ Or they can run against a real server:
phantomjs phantom-${runner}.js http://${server}:${port}/path/to/test.html
-I'm currently trying to keep it so that you can just grab `phantom-qunit.js` or `phantom-jasmine.js` and drop that in your project along with a .travis.yml to get a really easy CI up and running.
+## Super-easy Travis integration
Want to run your Javascript-based tests under PhantomJs on [Travis CI](http://travis-ci.org/)?
-After you go through [Getting Started with Travis](http://about.travis-ci.org/docs/user/getting-started/), just follow these few easy steps:
+First, go through [Getting Started with Travis](http://about.travis-ci.org/docs/user/getting-started/).
+
+### If you want to check phantom-xxx.js in to your repo
-* copy `travis.yml.example` to your repository root as `.travis.yml`
+* copy `travis.yml.example-include` to your repository root as `.travis.yml`
* copy `phantom-${runner}.js` to your repo root as `.phantom-${runner}.js` (substituting `${runner}` with `qunit`, `jasmine`, or `mocha`)
* modify your `.travis.yml` to use the right runner and point towards your `test.html` or equivalent
* push!
-### Known bugs
+### If you want Travis CI to automatically use the stable version of phantom-xxx.js
+
+* copy `travis.yml.example-download` to your repository root as `.travis.yml`
+* modify your `.travis.yml` to use the right runner and point towards your `test.html` or equivalent
+* push!
+
+## Known issues
The scripts hook into Phantom's resourceReceived event, which is triggered after every resource load (e.g. script tag, image tags); in that hook, we check for the presence of the test object (`window.QUnit`, `window.jasmine`, or `window.mocha`).
If `qunit.js` or `jasmine.js` or `mocha.js` is too close to one of the last resources in the page, the script will not have been evaluated by the time that the `resourceReceived` event is triggered, resulting in Phantom never attaching the watcher defined in the script (see [Issue #1](https://github.com/mark-rushakoff/OpenPhantomScripts/issues/1)).
@@ -0,0 +1,23 @@
+# This version of .travis.yml always downloads the stable version of
+# phantom-qunit.js before running the tests, so you don't have to check
+# phantom-xxx.js into your repository. Make sure to change qunit to jasmine or
+# mocha if necessary. If you aren't sure which version of .travis.yml to use,
+# pick this one.
+
+# We aren't actually using any particular language here, so let's use Ruby
+# since that's probably the most likely Travis worker to be available
+language: ruby
+rvm:
+ - 1.9.3
+notifications:
+ email: false
+before_script:
+ # Travis needs this stuff to start Phantom1.4...
+ # When they get Phantom1.5 this section can go away
+ - "export DISPLAY=:99.0"
+ - "sh -e /etc/init.d/xvfb start"
+script:
+ # Change these to jasmine or mocha if necessary
+ - "wget https://raw.github.com/mark-rushakoff/OpenPhantomScripts/master/phantom-qunit.js"
+ # Make sure to change test/test.html to the path to your test page
+ - "phantomjs phantom-qunit.js test/test.html"
@@ -1,3 +1,8 @@
+# Use this version of .travis.yml if you want to include phantom-xxx.js in your
+# repo. If you don't ever plan on running phantom-xxx.js locally, you probably
+# just want to use travis.yml.example-download instead. Make sure to change
+# qunit to jasmine or mocha if necessary.
+
# We aren't actually using any particular language here, so let's use Ruby
# since that's probably the most likely Travis worker to be available
language: ruby
@@ -11,5 +16,6 @@ before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
script:
- # You can put the script in your repo as .phantom-qunit so it's hidden
+ # You can copy phantom-xxx.js as .phantom-xxx.js to keep it semi-hidden
+ # Make sure to change test/test.html to the path to your test page
- "phantomjs .phantom-qunit.js test/test.html"

0 comments on commit 0479c9e

Please sign in to comment.