0.2.4 • Published 4 years ago

endpoint-coverage v0.2.4

Weekly downloads
64
License
ISC
Repository
github
Last release
4 years ago

endpoint-coverage

Provides a way to collect API endpoint test coverage in your API tests.

Installation

Via NPM

$ npm install endpoint-coverage --save-dev

Usage

There is one main function exported in the module, coverageMiddleware.

coverageMiddleware

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.

interface CoverageResult {
    coveredRoutes: Record<string, string[]>;
    notCoveredRoutes: string[];
}

Example

server.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);

afterTest.ts

import { CoverageResult } from 'endpoint-coverage';

afterAll(async () => {
	const coverageResult: CoverageResult = await fetch('/coverageResult');
	expect(coverageResult.notCoveredRoutes).toBeEmpty();
});
0.2.4

4 years ago

0.2.3

4 years ago

0.2.1

4 years ago

0.2.2

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago