Allows checking the API endpoint coverage of you server.
npm install endpoint-coverageProvides a way to collect API endpoint test coverage in your API tests.
sh
$ npm install endpoint-coverage --save-dev
`Usage
There is one main function exported in the module, coverageMiddleware. $3
Express.js middleware that collects all HTTP requests made against the server. Scans all request handlers registered in the application and pre-attaches middleware checking whether the given handler was called. Registers endpoint (
GET /collectCoverage) for collecting the coverage.Middleware has to be registered only in the test environment.
`ts
interface CoverageResult {
coveredRoutes: Record;
notCoveredRoutes: string[];
}
`Example
$3
`ts
import express from 'express';
import { coverageMiddleware } from 'endpoint-coverage';const app = express();
const port = 12345;
if(isTestEnv()) {
app.use(coverageMiddleware());
}
app.get('/path/:param', () => {...});
app.post('/anotherPath', () => {...});
return app.listen(port);
`$3
`ts
import { CoverageResult } from 'endpoint-coverage';afterAll(async () => {
const coverageResult: CoverageResult = await fetch('/coverageResult');
expect(coverageResult.notCoveredRoutes).toBeEmpty();
});
``