jstest 1.0: the cross-platform JavaScript test framework finally released as a standalone package

After hacking away on it for months, I’m happy to announce the 1.0 release of jstest as a standalone package. jstest has long been part of the jsclass library but over time it’s become the module I use the most: I test all my other JavaScript projects with it, not just those based on jsclass.

Using it as heavily as I do, I’ve noticed how its user interface can be troublesome. To being with, you need to install a bunch of apparently unrelated stuff from jsclass in order to use it, and you have to learn how the jsclass module system works, and plenty more besides. I wanted to make it so that it’s easy to get cross-platform JavaScript testing in a simple, single-file package that you could easily drop into any project, and have it just work no matter what platform you’re running on. That’s what the new jstest package achieves.

It bundles up everything you need to run JavaScript tests into a single file that you can download from the website or from npm. The website contains full documentation for how to use and extend it, presenting it as a library in its own right rather than some obscure part of jsclass. I hope the new packaging and improved docs make it much easier to get started and use this library.

But, this is not simply a marketing or refactoring exercise. jstest has always been about running on as many JS platforms as possible, and this release is no different. But until now it’s been hard to integrate into other workflows: there was no way of changing the output format, or integrating with different test runners, and the platforms it did support – TestSwarm, and PhantomJS via a clunky JSON interface – were hard-coded. That all changes in 1.0 thanks to the addition of reporter plugins: an API for adding new output formats to the framework. It already includes a ton of useful output formats that work on all supported platforms, and adapters for many new test runners including Buster.JS, Karma, Teabag, Testem, Testling CI and TestSwarm.

The text output formats are built in such a way that they run on any platform, including in the browser, meaning you can now do things like use any of the output formats for PhantomJS browser tests or send test output over a socket and reformat it somewhere else. The reporters include several standard formats like TAP, TAP-Y/J and JUnit XML for integration with other reporting systems. There’s even an API you can use to make sure your own reporters work everywhere seamlessly.

This release also involves a new release of jsclass. Version 4.0 is really a maintenance release that supports this work, but notably turns all the library modules into CommonJS-compatible modules, so we’re finally free of our pre-Node legacy of managing dependencies via global variables. As before, they still work out of the box on all supported platforms, but if you’re using CommonJS they’ll be better behaved on your platform.

Finally, getting this release done finally frees me up to work on my testing book. While I emphatically don’t want the book to be about any particular tool, having a framework that just works out of the box is crucial for me to keep the book ‘usable’. Getting other frameworks to work cross-platform typically involves fiddling with a bunch of hacky plugins or googling to find out how other people managed it, and it’s important to me that the tools that ship with the book just work, without the reader having to figure out how some random plugin has changed since the book was published. I want to write about how to approach testing and architecture problems in general, rather than about any particular framework, so having tools that get out of the way is a big part of making the book useful and not wasting its readers’ time messing with project config.

So, as usual: download it, and let me know what you think.

And sign up for the book!

If you’ve enjoyed this article, you might enjoy my recently published book JavaScript Testing Recipes. It’s full of simple techniques for writing modular, maintainable JavaScript apps in the browser and on the server.