Skip to content

Mocking and testing utilities for developing APIs with Swagger/OpenAPI

License

Notifications You must be signed in to change notification settings

gpsinsight/rigorous

Repository files navigation

build code coverage npm

rigorous

Mocking and testing utilities for developing APIs with Swagger/OpenAPI

Quickstart

Run a mock server

The following example starts a mock server that hosts each of the spec files in the specified folder. The server will restart when any of the spec files are updated. The regex determines which files should be run. But default, any file ending with .oas2.json will be run.

const { watch } = require('rigorous');

watch('/path/to/my/spec/folder', {
  port: 8080,
  regex: /^spec\.json$/,
});

Generate integration tests

The following example will generate Mocha tests for negative cases based on the provided specs. The tests can then be run as you would run any suite of Mocha tests.

const fs = require('fs');

const {
  createTestCases,
  createBadParameters,
  createMethodNotAllowed,
  createMissingParameters,
  createSmokeTests,
  generate,
} = require('rigorous');

const spec = fs.readFileSync('/path/to/spec.oas2.json');

createTestCases(spec, [
  createBadParameters,
  createMethodNotAllowed,
  createMissingParameters,
  createSmokeTests,
]).then(testCases =>
  fs.writeFileSync('/path/to/spec.tests.js', generate(testCases)),
);

How to:

Run this project

  1. Build the code: npm run build
  2. Run it! npm start

Create and run tests

  1. Add tests by creating files with the .tests.ts suffix
  2. Run the tests: npm t
  3. Test coverage can be viewed at /coverage/lcov-report/index.html

About

Mocking and testing utilities for developing APIs with Swagger/OpenAPI

Resources

License

Stars

Watchers

Forks

Packages

No packages published