Caching mock fetch implementation (v2.3.1, 2023, MIT) that automatically caches real HTTP responses on first call and replays them on subsequent calls. Supports node, bun, deno and testing frameworks like jest, vitest, node:test. Key differentiator: no manual mock writing – just run real fetch once, cache auto-saved to filesystem (or custom stores). Used by yahoo-finance2 for 1400+ API calls in <1s. Active development with semantic releases. Alternative to nock, msw, jest-fetch-mock that offers zero-config caching and team/CI cache sharing via committed fixtures.
npm install fetch-mock-cacheNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows basic setup: createFetchCache with filesystem store, mock global fetch, then first call misses (real request), second hits cache.
Upgrade to v2: see MIGRATING.md; replace 'jest-fetch-mock-cache' with 'fetch-mock-cache' and use new API.
Migrate to fetch-mock-cache v2 as above.
Use correct import: import FsStore from 'fetch-mock-cache/stores/fs'.
Use import syntax. If using CommonJS, dynamic import: import('fetch-mock-cache').then(m => ...).Run tests with network access at least once to generate cache, or pre-populate fixture files.
Only check for this header in tests using mocked fetch.
Use import syntax or dynamic import().
Use: import createFetchCache from 'fetch-mock-cache'; (without curly braces).
Ensure fetch-mock-cache v2+ is installed, and import from 'fetch-mock-cache/stores/fs' (not 'stores/fs').
Use Node.js 18+ or install node-fetch and polyfill global fetch.
No dependency data recorded yet.