Jest-compatible alternative to Dredd.
API Blueprint is (usually) easier to write than OpenAPI and there's already tooling out there to turn it into tests. Unfortunately, it's difficult to debug when something fails (especially in a before hook), doesn't make it easy to run a specific test, and is just generally frustrating.
Its parser and compiler, however, are separate from its CLI, so this package use them to generate Jest tests from your API Blueprint.
npm i @code-like-a-carpenter/contract-tests
Create your jest test file, but instead of writing explicit tests, import
buildContractTests
and pass it your API Blueprint and your API base url.
Make sure to pass the full path to your API Blueprint file, not a relative path.
import path from 'node:path';
import {buildContractTests} from '@code-like-a-carpenter/contract-tests';
describe('contract tests', () => {
buildContractTests({
baseUrl: process.env.API_URL,
blueprint: path.join(__dirname, 'api.apib'),
});
});
Please see contributing guidelines at the project homepage.
MIT © Ian Remmel 2023 until at least now