Simple test runner (works well with jsassert). Left here more as an example. Currently developed as a part of .
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

jsrunner - Simple runner pattern for JavaScript

This works well with jsassert. It actually uses this to test itself so check it out for a concrete demo.

The runner consists of one function: "tests". It is used both to collect tests to run and to actually run the tests.

A simple test set may look like this:

tests('Color', {
    _: { // set up
        c: color()
    initialValue: function() { // actual test
        assert(this.c.r()).equals(0); // do some actual asserts now
        // in this case we're using jsassert. you can use whatever
        // assert method you want
    ... // more tests

In order to get the tests run, define some kind of HTML file as follows:


    <link rel="stylesheet" type="text/css" href="../css/runner.css" />

    <script type="text/javascript" src="assert.js"></script>
    <script type="text/javascript" src="runner.js"></script>
    <script type="text/javascript" src="tests.js"></script>
    <script type="text/javascript">
        window.onload = function() {
            var outputArea = document.getElementById('testOutput');

            document.body.insertBefore(tests.playbackUI(), document.body.childNodes[0]);

                output: tests.HTMLOutput(outputArea), // sink for output
                refresh: 2000 // in ms, default zero
    <div id="testOutput"></div>

As you can see tests().run provides an output hook that you may attach your handler to. This handler receives report (individual test) containing its text and state (started, passed, failed, error, finished). "tests" also contains two predefined sinks, consoleOutput and HTMLOutput, that may you might find handy.

In addition tests contains simple playbackUI you might want to use. It makes it possible to stop the playback and resume it later (FIXME: currently expects that the runner is already running).