From 10f7085764c333278f6fa38e1819af87c94cbb54 Mon Sep 17 00:00:00 2001 From: "Aryan Singh K." <70511529+aryansk@users.noreply.github.com> Date: Thu, 6 Aug 2026 20:04:34 +0530 Subject: [PATCH] Cover Express not-found delegation Fixes https://github.com/fedify-dev/fedify/issues/857 Assisted-by: Codex:gpt-5 --- packages/express/src/index.test.ts | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 packages/express/src/index.test.ts diff --git a/packages/express/src/index.test.ts b/packages/express/src/index.test.ts new file mode 100644 index 000000000..ee8a3d051 --- /dev/null +++ b/packages/express/src/index.test.ts @@ -0,0 +1,41 @@ +import type { Federation } from "@fedify/fedify"; +import type { + NextFunction, + Request as ERequest, + Response as EResponse, +} from "express"; +import { strict as assert } from "node:assert"; +import { test } from "node:test"; + +import { integrateFederation } from "./index.ts"; + +test("integrateFederation delegates not-found requests to Express", async () => { + let nextCalls = 0; + const federation = { + fetch: ( + _request: Request, + options: { onNotFound: () => Response }, + ) => { + options.onNotFound(); + return new Response("unused", { status: 404 }); + }, + } as unknown as Federation; + + const request = { + protocol: "https", + host: "example.com", + url: "/not-a-federation-route", + method: "GET", + headers: {}, + } as ERequest; + const response = {} as EResponse; + const next: NextFunction = () => { + nextCalls++; + }; + + const middleware = integrateFederation(federation, () => undefined); + middleware(request, response, next); + await new Promise((resolve) => setImmediate(resolve)); + + assert.equal(nextCalls, 1); +});