Skip to content

Latest commit

 

History

History
69 lines (45 loc) · 1.81 KB

README.md

File metadata and controls

69 lines (45 loc) · 1.81 KB

REST API testing starter kit

SuperTest REST API testing with Mocha. This is a starter kit which you can copy to your own projects.

Installation

  • Requires NodeJS v0.10 or newer

Install Nodemon and Mocha globally:

npm install -g nodemon mocha

Install local depedencies:

npm install

Running the server and testing it

Run the example server:

npm start

Test locally:

npm test

Test on continuous integration

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.

Writing tests

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.