$ npm install whiskey
Whiskey is a powerful test runner for Node.js applications and a process orchestration framework which makes running integration tests with a lot of service / process dependencies easier.
--concurrency
option)--independent-tests
option)setUp
/ tearDown
function supportinitialize
/ finalize
function support--coverage
option is used)For changes please see CHANGES.md file.
Install it using npm:
npm install whiskey
whiskey [options] --tests "<test files>"
whiskey [options] --independent-tests "<test files>"
whiskey [options] --tests "<test files>" --independent-tests "<test files>"
init
function and it is called in a child process *before running the tests in
each test file--dependencies
option
is used.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"
Presently, two kinds of setup and teardown procedures exist with Whiskey. setUp and tearDown work on a per-suite basis; that is, Whiskey invokes setUp prior to running all tests in a given Javascript file, called a suite, and invokes tearDown after all tests in that file have been exhausted. If you run multiple suites in parallel (e.g., via the -T/--independent-tests option), you'll get concurrent execution of setups and teardowns as well.
Sometimes, though, you need longer-lived environmental configurations, or you need safe resource sharing between entire batches of independently running tests. For these, you'll want to use globalSetUp and globalTearDown.
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();
};
A simple example using the optional BDD module:
var bdd = require('whiskey').bdd.init(exports);
var describe = bdd.describe;
describe('the bdd module', function(it) {
it('supports it(), expect(), and toEqual()', function(expect) {
expect(true).toEqual(true);
});
});
A simple example demonstrating how to use global setup and teardown functionality:
exports['globalSetUp'] = function(test, assert) {
// Set up database schema here...
// Push known data set to database here...
test.finish();
}
exports['globalTearDown'] = function(test, assert) {
// Drop database here...
test.finish();
}
For more examples please check the example/
folder, and the test/run.sh
script.
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.
To contribute, fork the repository, create a branch with your changes and open a pull request.
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 functionality.
You then need to manually connect to the debugger to control it (i.e. using
node repl or node-inspector).
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. Further, you
cannot use the --debug
and --independent-tests
options together. The
semantics just don't make any sense. To debug a test, make sure you invoke it
with --tests
instead.
long-stack-straces
module in my own code and all of the tests get reported as succeededLong 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.
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).
Apache 2.0, for more info see LICENSE.
© 2010 - cnpmjs.org x YWFE | Home | YWFE