/pactum-api-coverage

API Coverage Reporter for Pactum. Provides operation & response level coverage and supports JSON schemas for swagger/OAS specs.

Primary LanguageJavaScriptMIT LicenseMIT

pactum-api-coverage

Platform

API coverage reporter for Pactum tests. Accepts Swagger/OAS spec data in JSON format.

Installation

npm install --save-dev pactum pactum-api-coverage

Usage

const pactum = require('pactum');
const psc = require('pactum-api-coverage');
const reporter = pactum.reporter;

// global before block
before(() => {
  psc.specData = require("./specs/v1/oas.json");
  reporter.add(psc);
});

// global after block
after(() => {
  return reporter.end();
});

Reporter Options

const psc = require('pactum-api-coverage');

// name of the report file - defaults to "api-cov-report.json"
psc.file = 'report-name.json';

// folder path for the report file - defaults to "./reports"
psc.path = './reports-path';

// Load a local JSON spec file (or a remote one)
psc.specData = require("./specs/v1/oas.json");

// Ignore specific response codes
psc.ignoreResponseCodes = [ 429, 500]

Report Json Output (example)

{
  "basePath": "/v1",
  "coverage": 0.5,
  "coveredApiCount": 4,
  "missedApiCount": 4,
  "totalApiCount": 8,
  "coveredApiList": [
    "200|get|/v1/health",
    "200|get|/v1/getallninjas",
    "200|get|/v1/getninjas/{rank}",
    "200|get|/v1/getninja/{rank}/{name}"
  ],
  "missedApiList": [
    "200|post|/v1/health",
    "200|get|/v1/getninjas/{clan}/{rank}",
    "400|get|/v1/getninjas/{clan}/{rank}",
    "200|get|/v1/getninja/{name}"
  ]
}

Notes

Read more about Pactum here.

Copied from pactum-swagger-coverage and altered.