SuperTest REST API testing with Mocha. This is a starter kit which you can copy to your own projects.
- Requires NodeJS
v0.10
or newer
Install Nodemon and Mocha globally:
npm install -g nodemon mocha
Install local depedencies:
npm install
Run the example server:
npm start
npm test
Set an environment variable export CI=true
(note: e.g. Travis-CI sets this automatically) in your continuous integration environment or just prepend the variable before the test command:
CI=true npm test
This outputs the test results as "standard-ish" XUnit XML.
Test suites must be stored in ./test/suites/
-folder. If you wish, you can also organize your test suites into folders (maximun 2 levels deep).
A test suite must exposed as CommonJS module function which takes the supertest's request object (in this case called API
) as an argument. Suite must have at least one MochaJS describe
-block inside them.
Here's an example structure:
module.exports = function(API) {
describe('Describe your test suite here', function() {
it('should do something', function(done) {
/* some tests */
});
});
}
See the provided examples root endpoint test
and collection test
for more examples.