npm.io
0.23.3 • Published yesterday

@tracecov/fetch

Licence
LicenseRef-TraceCov-Community-1.0
Version
0.23.3
Deps
1
Size
7 kB
Vulns
0
Weekly
0

npm npm downloads License

@tracecov/fetch

Automatic OpenAPI coverage capture for fetch. Wraps fetch so every call is recorded into a @tracecov/core coverage map — no record() by hand.

Installation

npm install @tracecov/fetch

Quick Start

import { CoverageMap } from '@tracecov/core';
import { instrumentFetch } from '@tracecov/fetch';

const coverage = CoverageMap.fromPath('openapi.json');
const restore = instrumentFetch(coverage); // patches globalThis.fetch

await fetch('https://api.example.com/users');

restore(); // undo the patch, e.g. in afterAll
coverage.saveHtmlReport({ outputFile: 'coverage.html' });

wrapFetch(fetch, coverage) returns an instrumented fetch without touching the global. For multi-file coverage in Vitest, see @tracecov/vitest.

Documentation

Keywords