pactum-swagger-coverage
JSON swagger/openapi3 coverage reporter for Pactum tests. It's capable of reading the swagger/oas3 definitions from either swagger.yaml
or swagger.json
or openapi3.yaml
(served on a http server endpoint).
Installation
npm install --save-dev pactum pactum-swagger-coverage
Usage
const pactum = require('pactum');
const psc = require('pactum-swagger-coverage');
const reporter = pactum.reporter;
before(() => {
reporter.add(psc);
});
after(() => {
return reporter.end();
});
Reporter Options
const psc = require('pactum-swagger-coverage');
psc.reportFile = 'report-name.json';
psc.reportPath = './reports-path';
psc.basePath = '/api/server/v1';
psc.swaggerJsonUrl = "http://localhost:3010/api/server/v1/json";
psc.swaggerYamlPath = './tests/testObjects/swagger.yaml';
Report Json Output (example)
{
"basePath": "/api/server/v1",
"coverage": 0.2,
"coveredApiCount": 1,
"missedApiCount": 4,
"totalApiCount": 5,
"coveredApiList": [
"/getallninjas"
],
"missedApiList": [
"/health",
"/getninjabyid/{id}",
"/getninjabyname/{name}",
"/getninjabyrank/{rank}"
]
}
Note: Either 'swaggerJsonUrl' or 'swaggerYamlPath' should be provided for reporter to work.
Notes
Read more about Pactum here.
Inspired by swagger-coverage-postman.