rigorous
TypeScript icon, indicating that this package has built-in type declarations

0.3.2 • Public • Published

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

/rigorous/

    Package Sidebar

    Install

    npm i rigorous

    Weekly Downloads

    0

    Version

    0.3.2

    License

    MIT

    Unpacked Size

    141 kB

    Total Files

    81

    Last publish

    Collaborators

    • skonves