Absolute or relative path to the OpenAPI specification file (JSON or YAML)
The recommended approach is to call this from a Vitest setup file so it runs once before the entire suite:
// tests/setup.ts
import { setupOpenapi } from '@map-colonies/vitest-utils';
setupOpenapi('/path/to/openapi.yaml');
// vitest.config.ts
export default defineProject({
test: {
setupFiles: ['./tests/setup.ts'],
},
});
Alternatively, call it inside a beforeAll when you need per-suite control:
beforeAll(function () {
setupOpenapi('/path/to/openapi.yaml');
});
it('should satisfy the OpenAPI spec', async function () {
const response = await supertest(app).get('/resource');
expect(response).toSatisfyApiSpec();
});
Configures
jest-openapito validate responses against an OpenAPI specification.This function bridges
jest-openapi(which relies on a globalexpect) with Vitest's localexpectinstance, then resets the global to avoid polluting other tests.