in-process-request is a lightweight Node.js library designed to execute HTTP handler functions directly within the current process, bypassing the need to start and manage a local HTTP server. This makes it ideal for integration testing of API routes or for internal service-to-service communication within the same application without network overhead. The library provides a unified interface for interacting with handlers from popular web frameworks including Express.js (v3, v4, v5), Koa (v2), Hapi (v19, v20), NestJS (v7), Fastify (v3), Connect (v3), Polka, and Apollo Server (v2, v3). Its current stable version is 0.3.1, with releases typically focusing on bug fixes, dependency updates, and ensuring compatibility with newer versions of supported frameworks. It differentiates itself by offering a robust mocking layer for HTTP requests and responses, allowing for precise control over the input and examination of the output.
npm install in-process-requestVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up an Express.js application and use `in-process-request` to execute both GET and POST requests against its handler, capturing the response details.
Check the `in-process-request` README for specific framework version compatibility. Upgrade `in-process-request` or adjust your framework version if conflicts arise.
Always provide a valid non-empty `path` string in the `requestOptions` object, e.g., `{ path: '/my-endpoint?query=value' }`.Limit interactions with the request and response objects to standard HTTP methods, headers, body, and status codes. Avoid relying on low-level `socket` properties or stream events unless explicitly documented as supported by `in-process-request`'s mocks.
Ensure that `requestOptions` includes a non-empty `path` string, e.g., `handler({ path: '/api/resource', method: 'GET' })`.Pass `koaApp.callback()` to `inProcessRequest`, not `koaApp`. Correct usage: `const handler = inProcessRequest(koaApp.callback());`
Use the `HapiListener` helper class. Create an instance of `HapiListener`, pass it to `Hapi.server({ listener: myListener })`, and then use `myListener.handler` with `inProcessRequest`. Example: `const myListener = new HapiListener(); const server = Hapi.server({ listener: myListener }); const handler = inProcessRequest(myListener.handler);`No dependency data recorded yet.