UNPKG

kequapp

Version:

DEPRECATED: renamed to @kequtech/arbor

20 lines (19 loc) 729 B
import { createGetResponse } from "../body/create-get-response.js"; import { FakeReq, FakeRes } from "../utils/fake-http.js"; export function inject(app, options = {}) { const req = new FakeReq(options); const res = new FakeRes(); // Create the getResponse helper first so consumers can attach readers before // the application writes to the response. Schedule the app invocation // asynchronously to avoid races where the app writes before getResponse is used. const getResponse = createGetResponse(res); setImmediate(() => { // run the app in the next turn so tests can attach their readers app(req, res); }); return { req, res, getResponse, }; }