Fast tests with PhantomJS
To run these in CI, I wrote a script using capybara. It visits the URL for each of the spec files and scrapes the pages to determine success/failure. However, it was slow - the suite for our app took over 100 seconds.
So I sat down and hacked together a faster script. Rather than completely replacing my CI script, I just got it running a single test file. This individual specs running about 5 times faster.
Then I realised that without the overhead of loading a firefox instance, there was no reason not to run all the specs in parallel. Some quick shell scripting and I was there:
find public/spec/integration -iname *.js | grep -v _spec_helper.js | sed s/^public.spec.//g | xargs -L1 -P30 ./lib/tasks/phantom_runner.coffee
Hey presto! the entire suite ran in under 7 seconds, even on my ancient, groaning hardware.
Now I’m wondering if I could fork from within PhantomJS to speed things up further - but that’s a post for another day.