Parallel vs serial javascript async tests

If you’re writing tests for a javascript web application, sooner or later you’ll need to be aware of whether you are using a parallel or serial test runner.

Parallel Serial
How it works Start all async tests at once and wait until they have all completed. Wait for each test to complete before starting the next one.
Implications Callbacks execute in the order they return so race conditions are possible. Tests are isolated, but take much longer to run.
Examples Jasmine, Vows QUnit, Mocha

I discovered this last week while porting all our tests to a different framework. Under QUnit, everything was green, but under Jasmine, most of the end-to-end tests (that exercise our whole app, simulating user actions via the DOM down to a live API and back) were failing with all sorts of weird errors.

The problem? Unlike our regular tests, the end-to-end tests run the whole application at once, using the entire DOM, plus a globally-scoped event aggregator.

In QUnit all the tests ran fine, because they were completely isolated from one another. But in Jasmine they were running concurrently, all racing to update the DOM at the same time, and publishing all sorts of events that were being picked up by other tests. We fixed the problem by switching to Mocha instead… but definitely something to watch out for!

4 thoughts on “Parallel vs serial javascript async tests

  1. @Daniel: QUnit is very solid but a bit simple – I was outgrowing it with too many tests that needed to be put in some bigger hierarchy. Plus I wanted something a bit more BDD-ish. I am now using Jasmine (my preferred) for unit tests, and Mocha for full app integration tests (where I hit this parallel issue).

  2. Jasmine does not actually run your specs in parallel in any way. It is however possible to have specs whose asynchronous portion takes long enough that the built-in time limit elapses which will cause jasmine to start running the next spec, even though there may still be code running from earlier specs.

    Jasmine definitely doesn’t “Start all async tests at once and wait until they have all completed.” as you have listed in your table.

Comments are closed.