Hot, hot test reloading from Javascript
JavaScript Go Makefile
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 1 commit ahead of kevinburke:master.
Latest commit aa82857 Jul 21, 2015



This is a tool that will help you reload your Javascript based test suite really fast.



Lucifer exposes one function with the following signature:

var lucifer = function(initTestEnvironment, isTestFile, opts)

initTestEnvironment: function(cb) A function which sets up your test environment. For us this is sails.lift and a few other things. Should take a callback as an argument, and callback with a single error argument if there was one.

isTestFile: function(file) -> bool. A function which takes a filename as input and returns true if the file is a test file. Necessary so we know which files to run, and because you don't want to re-require test files until you are ready to run them.

opts: dictionary. Currently the dictionary supports two keys:

  • directory: When you make requests to the Lucifer server, assume they are relative to this directory.
  • slow: A slow test threshold, in milliseconds

So a simple example would be:

var lucifer = require('./lucifer');
var s = require('sails');

var startTestEnvironment = function(cb) {
  var start =;
  s.lift({}, function(err) {
    if (err) {
      return cb(err);
    console.log('Sails ready.. booted in ' + ( - start) + 'ms');
    return cb();

var isTestFile = function(file) {
  return file.indexOf('.test.') >= 0;

var opts = { directory: __dirname, slow: 2 };
lucifer(startTestEnvironment, isTestFile, opts);


Copy the lucifer-server.js file to a place you can import it from.

Server Dependencies

The server is an instance of the Express web server and runs tests with Mocha.



go get    # Or 'make install'

I should really package these up / distribute them as binaries...


The Lucifer binary makes requests to the Lucifer server.


    lucifer command [arguments]

The commands are:

    invalidate      Invalidate the cache for a given file
    run             Run tests for a given file

Use "lucifer help [command]" for more information about a command.


Node's require is really, really slow. If you need to load a large app with an unfortunately large number of dependencies to run your test suite, you're looking at a 5-10 second penalty to run a single test.

Instead of requiring every file every time you want to run your test suite, load all of them once and listen on a socket for incoming test run requests.

But a long running server won't take into account the changes I make

Yes! Luckily it's not too difficult to invalidate the Node cache for a module. If you call lucifer invalidate [file] the binary will make a request to the server to invalidate the cache for that module; this way you can ensure the server is running tests against the version of the module on your file system.