node-test-helper
Test helper suite using Mocha test framework.
Dependencies
Installation
$ npm install node-test-helper
$ sudo npm install -g node-test-helper
Initialization
Copy test suite template to current directory.
$ node_modules/.bin/node-test-helper init
$ node-test-helper init
The following will be copied to the current working directory:
Makefile
test/
factories/
fixtures/
helpers/
unit/
Writing Tests
require("node-test-helper");
describe(TEST_NAME, function() {
describe("without callback", function() {
it("should be successful", function() {
});
});
describe("with callback", function() {
it("should be successful", function(done) {
done();
});
});
});
Execute sample test
$ make test
sample
without callback
✓ should be successful
with callback
✓ should be successful
2 passing
Test Execution
Tests are executed using make command. The script will look for tests under test/unit/ directory.
$ make test
$ make test controllers
$ make test controllers models
$ make test utils/sample.test
Mocha Options
Mocha options can be passed as parameter to make. By default, mocha is being executed using the ff. options:
$ mocha --recursive -t 30000 -R spec
Use MOCHA_OPTS commandline variable to pass specific mocha options to make.
$ make MOCHA_OPTS='-C -R dot' test
Helpers
Custom Helpers
You can write your own test helpers or node modules and save it under test/helpers/ directory. Use the built-in requireHelper() function to load your custom helper.
require("node-test-helper");
describe(TEST_NAME, function() {
it("should load my custom helper", function() {
var my_helper = requireHelper("my_helper");
expect(my_helper).to.exist;
});
});
If you need to do some initialization prior to all your tests execution, you can put them inside test/helpers/bootstrap.js file. This file will be loaded automatically upon test execution.
before(function(done) {
done();
});