Whiskey

A powerful test runner for NodeJS applications.

View the Project on GitHub cloudkick/whiskey

Whiskey

Whiskey is a powerful test runner for NodeJS applications.

Features

Non NPM-installable Dependencies

Changes

For changes please see CHANGES.md file.

Installation

Install it using npm:

npm install whiskey

Usage

whiskey [options] --tests "<test files>"

Available options

Note: When specifying multiple test a list with the test paths must be quoted, for example: whiskey --tests "tests/a.js tests/b.js tests/c.js"

Test File Examples

A simple example (success):

var called = 0;

exports['test_async_one_equals_one'] = function(test, assert) {
  setTimeout(function() {
    assert.equal(1, 1);
    called++;
    test.finish();
  }, 1000);
}

exports['tearDown'] = function(test, assert) {
  assert.equal(called, 1);
  test.finish();
}

A simple example (skipping a test):

var dbUp = false;
exports['test_query'] = function(test, assert) {
  if (!dbUp) {
    test.skip('Database is not up, skipping...');
    return;
  }

  assert.equal(2, 1);
  test.finish();
}

A simple example (failure):

exports['test_two_equals_one'] = function(test, assert) {
  assert.equal(2, 1);
  test.finish();
}

For more examples please check the example/ folder.

Running Whiskey test suite

To run the Whiskey test suite, run the following command in the repository root directory.

npm test

If all the tests have sucessfully passed, the process should exit with a zero status code and you should see * * * Whiskey test suite PASSED. * * * message.

Contributing

To contribute, fork the repository, create a branch with your changes and open a pull request.

Debugging

If you want to debug your test, you can use the --debug option. This will cause Whiskey to start the test process with the V8 debugger attached to it and put you into the Node debugger prompt.

Whiskey will also by default set a breakpoint at the beginning of your test file.

Note: This option can only be used with a single test file.

Troubleshooting

I use long-stack-straces module in my own code and all of the tests get reported as succeeded

Long stack traces modules intercepts the default Error object and throws a custom one. The problem with this is that Whiskey internally relies on attaching the test name to the Error object so it can figure out to which test the exception belongs. long-stack-traces throws a custom Error object and as a consequence test name attribute gets lost so Whiskey thinks your test didn't throw any exceptions.

The solution for this problem is to disable long-stack-trace module when running the tests. This shouldn't be a big deal, because Whiskey internally already uses long-stack-traces module which means that you will still get long stack traces in the exceptions which were thrown in your tests.

My test gets reported as "timeout" instead of "failure"

If your test gets reported as "timeout" instead of "failure" your test code most likely looks similar to the one below:

exports["test failure"] = function(test, assert){
  setTimeout(function() {
    throw "blaaaaah";
    test.finish();
  },200);
};

The problem with this is that if you run tests in parallel (--concurrency > 1) and you don't use a custom assert object which gets passed to each test function, Whiskey can't figure out to which test the exception belongs. As a consequence, the test is reported as "timed out" and the exception is reported as "uncaught".

The solution for this problem is to run the tests in sequential mode (drop the --concurrency option).

License

Apache 2.0, for more info see LICENSE.