hypertest

test a hyper+json API

hypertest

test a hyper+json api interface

$ npm install -g hypertest
$ hypertest path/to/test.spec.yml
 
  ....
 
  4 passing (2s)

hypertest(1) accepts the same flags as mocha

See format for details.

hypertest expects a yaml document describing the tests. A document includes the host name, optional headers and a set of paths with one or more assertions.

The most basic assertion is a simple string. The available methods are described by should.js

host: http://api.example.com
 
.account.name: should exist

With (optional) headers

host: http://api.example.com
headers:
  header1: value1
  header2: value2
  
.account.name: should exist

Additionally, reference to environment variables is possible

host: $HOST
headers:
  authorization: $AUTH_TOKEN

Since should exist is so common it is the default assertion.

host: http://api.example.com
 
.account.name:

Assertions can also be a list of assertion statements.

.account.name:
  - should eql 'Frank'
  - should startWith 'F'
  - should endWith 'nk'
  - should be type 'string'
  - should be a String

If more complex assertions are needed inline javascript functions are available.

.account.name:
  - !!js/function >
    function(value, done) {
      // complex testing here
      done();
    }

The function can also be given a human-readable name.

.account.name:
  -
    name: should do some really complex thing
    fn: !!js/function >
      function(value, done) {
        // complex testing here
        done();
      }

The values for the custom functions get injected in by reading the names of the arguments specified. A list of default values includes:

The value of the body at the end of the path

The response object returned by superagent

The path used in the test

should.js module used for testing

hyperagent context used to make the request

CommonJS require function to require any other needed modules

Function to be called when the assertions are done executing. This is required for any async assertions.