Registry / testing / fetch-light-my-request

fetch-light-my-request

JSON →
library0.1.4jsnpmunverified

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-request
INSTALL
IMPORT
SIG · FETCH-LIGHT-MY-REQ
F
fetch-light-my-request
testingjavascriptv0.1.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createFetchMockLightMyRequest
✓ import { createFetchMockLightMyRequest } from 'fetch-light-my-request'
✗ const createFetchMockLightMyRequest = require('fetch-light-my-request')
ESM-only package, named export. CommonJS require will fail.
createFetchMockLightMyRequestFromFastify
✓ import { createFetchMockLightMyRequestFromFastify } from 'fetch-light-my-request'
Only works if fastify is installed; returns a FetchMock instance.
createFetchLightMyRequest
✓ import { createFetchLightMyRequest } from 'fetch-light-my-request'
Directly returns the fetch function, not FetchMock instance.

Creates a fetch mock using a plain HTTP request handler, calls it, and logs the response body.

import { createFetchMockLightMyRequest } from 'fetch-light-my-request'; const fetchMock = createFetchMockLightMyRequest((req, res) => { res.end('Hello, World!'); }); async function main() { const res = await fetchMock.fetchHandler('http://localhost/hello'); const text = await res.text(); console.log(text); // 'Hello, World!' } main();
Debug
Known issues
breakingRequires Node >=20, ESM-only. CommonJS not supported.
fix
Use Node 20+ with ESM. Do not use require().
affects: >=0.1.0
deprecatedFastify 5 is not yet supported; fastify peer dependency is >=4 and may not work with future versions.
fix
Use fastify 4.x. Monitor for updates.
affects: >=0.1.0
gotchafetchMock.fetchHandler mimics fetch but does not use global fetch; it is a standalone function.
fix
Use fetchMock.fetchHandler directly, not global fetch(). To mock global fetch, you must reassign global.fetch = fetchMock.fetchHandler.
affects: >=0.1.0
gotchaThe request handler (req, res) must be a plain Node.js HTTP request listener, not an Express or Koa middleware.
fix
Use the signature (req, res) => { ... } where req is IncomingMessage and res is ServerResponse.
affects: >=0.1.0
gotchaWhen using createFetchLightMyRequest (not mock), the returned function does not have fetch-mock methods like mock() or restore().
fix
Use createFetchMockLightMyRequest if you need to set up multiple URL patterns.
affects: >=0.1.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module ... from ... not supported.
The package is ESM-only; CommonJS require() doesn't work.
fix
Use ES6 import statements or dynamic import(). Ensure project type is 'module' in package.json.
TypeError: fetchMock.fetchHandler is not a function
Import was done incorrectly or wrong symbol used.
fix
Verify import: import { createFetchMockLightMyRequest } from 'fetch-light-my-request'. Then call the factory function.
Error: Cannot find module 'fastify' ... Did you mean to set the 'fastify' peerDependency?
Using createFetchMockLightMyRequestFromFastify without installing fastify.
fix
Install fastify as a dev dependency, or use createFetchMockLightMyRequest with a plain handler.
TypeError: res.end is not a function
The request handler callback is not receiving proper Node.js response object.
fix
Ensure handler signature is (req, res) and use res.end() to send response.
Upgrade
Version history
0.1.4latest on npm
Audit
Dependencies
fastifyoptionalPeer dependency for creating mock from Fastify instance
Agent activity
4 hits · last 30 days
node
4
Resources
fetch-light-my-request — npm install fetch-light-my-request · libregistry