0.3.2 • Published 5 years ago
rigorous v0.3.2
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
- Build the code:
npm run build
- Run it!
npm start
Create and run tests
- Add tests by creating files with the
.tests.ts
suffix - Run the tests:
npm t
- Test coverage can be viewed at
/coverage/lcov-report/index.html