Running tests with SlimerJS

If you’ve gone through the Getting started and Loading your code tutorials, this article will show you how to run your tests using SlimerJS.

If you have an existing web page that runs your jstest suite, then running it with SlimerJS is straight-forward. Create this script next to the other example project files:

// slimer.js

var JS       = require('./build/jstest'),
    options  = {format: 'dot'},
    reporter = new JS.Test.Reporters.Headless(options)

reporter.open('http://localhost:4180/example/browser.html')

Start a local server so that Slimer can load your files:

$ python -m SimpleHTTPServer 4180

If you run this script you should see the results in your terminal.

You can use the options object to specify the output format for the script. Alternatively, you can omit the format option and use the FORMAT environment variable instead.

One caveat: SlimerJS at time of writing has no way of setting the process exit status, so your tests might fail but the process will still exit with status 0. You need to rely on machine-readable output formats to detect failures, for example using the xml output format or using tap-j and piping it into tapout.

$ FORMAT=tap-j slimerjs slimer.js | tapout 
Started
..F

1. FAIL adds a list item when the text is clicked

    <"added"> expected but was
    <"">

Finished in 0.026s (115.385 test/s, 0.008667s avg.)

3 tests: 2 pass, 1 fail, 0 exit, 0 todo, 0 omit

$ echo $?
255