A lightweight wrapper that combines fetch-mock and light-my-request to allow Node.js fetch-based HTTP clients to be tested against plain HTTP or Fastify servers without real network calls. Version 0.1.4, early-stage package, requires Node >=20 and Fastify >=4 as a peer dependency. Ships TypeScript types. Differentiates by enabling fetch-mock's full mocking capabilities while using light-my-request's fast in-process request injection, allowing seamless testing of fetch-using code against Fastify or simple HTTP handlers.
npm install fetch-light-my-requestNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a fetch mock using a plain HTTP request handler, calls it, and logs the response body.
Use Node 20+ with ESM. Do not use require().
Use fastify 4.x. Monitor for updates.
Use fetchMock.fetchHandler directly, not global fetch(). To mock global fetch, you must reassign global.fetch = fetchMock.fetchHandler.
Use the signature (req, res) => { ... } where req is IncomingMessage and res is ServerResponse.Use createFetchMockLightMyRequest if you need to set up multiple URL patterns.
Use ES6 import statements or dynamic import(). Ensure project type is 'module' in package.json.
Verify import: import { createFetchMockLightMyRequest } from 'fetch-light-my-request'. Then call the factory function.Install fastify as a dev dependency, or use createFetchMockLightMyRequest with a plain handler.
Ensure handler signature is (req, res) and use res.end() to send response.