vcr-test is a testing utility that records and replays HTTP interactions, enabling fast, deterministic, and accurate tests by eliminating reliance on live external APIs. It intercepts HTTP traffic from any client (`fetch`, `axios`, `got`, etc.) using `@mswjs/interceptors` and stores request/response pairs in YAML "cassette" files. The current stable version is 1.4.0. It provides flexible recording modes (once, none, update, all) and extensibility for request masking, pass-through, and custom matching. Its key differentiator is its framework-agnostic nature and support for modern JavaScript features like `await using`, while also offering a callback API for older environments. While no explicit release cadence is stated, the project appears actively maintained on GitHub.
npm install vcr-testVerified import paths — ran on the pinned version, not inferred.
Demonstrates recording and replaying an HTTP interaction using `VCR` and `FileStorage` with the modern `await using` syntax. It shows how to initialize VCR, wrap an API call with `useCassette`, and assert the replayed result.
For older environments, use the callback-based API: `await vcr.useCassette('cassette_name', async () => { /* test code */ });`.Recalculate the byte length of the modified response body and update the `content-length` header accordingly, or re-record the cassette to automatically generate correct headers.
Be aware of `VCR_MODE` in deployment environments. To ensure consistent behavior, explicitly unset `VCR_MODE` if you intend to use programmatic mode settings, or rely solely on the environment variable for mode control in pipelines.
Change the `vcr.mode` to `RecordMode.once` (default), `RecordMode.update`, or `RecordMode.all` to allow recording the cassette, or ensure the cassette exists before running the test in `none` mode.
Open the YAML cassette file and ensure the `content-length` header value for the affected interaction is an integer representing the byte length of the response body, or delete the cassette and re-record it.
No dependency data recorded yet.