J5’s Blog

March 23, 2010

Introducing Jester – The JavaScript unit tester based around the Gjs engine

Filed under: Gnome, JavaScript, webapps — J5 @ 12:42 pm

Introducing Jester. Jester is a JavaScript unit tester based around GNOME’s Gjs JavaScript engine. I wrote it because I needed a stand alone tester for testing non-DOM JavaScript code in my AMQP Bindings (kamaloka-js). I also wanted to learn the ins and outs of Gjs and GLib Introspection while making it relevant to my friends in the GNOME Community. By utilizing a separate run time for non-DOM code I hope to encourage the separation of browser and generic JavaScript code for the sake of reuse across browser and desktop platforms.

Jester has a couple of components and can be used indirectly or directly by Gjs applications. The first component is the jester standalone application which can load and run a JavaScript file from the command line. Use this to integrate with test workflows such as make check or to simply test out some quick JavaScript. The second component is the jester.js module which can be loaded directly in a Gjs application. This module contains the Test class which is used to write unit tests.

Here is a simple example of how to use Jester:

test.js

const Jester = imports.jester;

let test = {
    testExample: function() {
        this.assertEquals(1, 1, "This test should always pass");
        this.assertEquals(1, 2, "This test should fail");
    }
}

this.info("Jester Example");
let test_suite = new Jester.Test({"Simple Test": test});
test_suite.run();

To run this code you would enter this on the command line:

jester test.js

Home Page: http://live.gnome.org/Jester
0.1 Tarball: http://live.gnome.org/Jester?action=AttachFile&do=view&target=jester-0.1.tar.bz2
Git:

  • anonymous – git://git.gnome.org/jester
  • commit access – ssh://USERNAME@git.gnome.org/git/jester

Since kamaloka-js is built on top of js.io, I have create a patch for js.io which makes the importer work when used with Jester.

[read this post in: ar de es fr it ja ko pt ru zh-CN ]

6 Comments

  1. Why not use JSUnit?

    Comment by Dom Lachowicz — March 23, 2010 @ 1:27 pm

  2. JSUnit is more complicated than I needed and is based around HTML pages. The API for Jester is somewhat based around JSUnit. I tried to see if I could use JSUnit inside of Jester but quickly ran away.

    I also wanted to learn Gjs as well as make it dead simple for Gjs developers to incorporate it inside their apps. It is pretty much one .js file if you want to have unit testing functionality in a Gjs app. It took me a couple of days to write.

    The other reason is to see if I can’t get Seed and Gjs to play nicely and export similar APIs. But that is a down the road pet project.

    Oh and also, it makes for an excellent example of how to write a Gjs app.

    Comment by J5 — March 23, 2010 @ 1:52 pm

  3. Jester’s already the name of a javascript project (JS rest client library from thoughtbot: http://github.com/thoughtbot/jester). Just thought you should know.

    Comment by Josh Adams — March 23, 2010 @ 2:39 pm

  4. Hmm, I might need to rename then. J5Tester? It was jstester at first but I kept pronouncing is Jester so that stuck but it could cause confusion.

    Comment by J5 — March 23, 2010 @ 3:24 pm

  5. FWIW gjs uses JSUnit for its own unit tests and there’s gjs-unit that runs test scripts from a directory. gjs-unit just has somewhat inconvenient setup and for that reason isn’t installed for other projects to use.

    Comment by Tommi Komulainen — March 23, 2010 @ 5:32 pm

  6. Tommi,

    I’ll look at your unit tests. Perhaps I can make the API fairly compatible so they are both drop in replacements. One pain is that JSUnit has the optional comment parameter as the first parameter and then goes on to use a bunch of magic to determine if there is a comment or not. Not a big deal but it does make the internals look ugly and complicated.

    This is a pet project of mine. If people use it great. If JSUnit is better to use, no harm done.

    Comment by J5 — March 23, 2010 @ 5:51 pm

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress