From 0fff2b04dae0f5562cfb01c752dde2ba8aa7af51 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Thu, 26 Mar 2026 09:01:34 +0100 Subject: [PATCH] chore: minor code cleanups (#3103) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bartek IwaƄczuk Co-authored-by: Claude Opus 4.6 (1M context) --- .../src/middlewares/static_files_test.ts | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/packages/fresh/src/middlewares/static_files_test.ts b/packages/fresh/src/middlewares/static_files_test.ts index 84a8ba79..d131bccc 100644 --- a/packages/fresh/src/middlewares/static_files_test.ts +++ b/packages/fresh/src/middlewares/static_files_test.ts @@ -1,5 +1,5 @@ import { staticFiles } from "./static_files.ts"; -import { serveMiddleware } from "../test_utils.ts"; +import { FakeServer, serveMiddleware } from "../test_utils.ts"; import type { BuildCache, StaticFile } from "../build_cache.ts"; import { expect } from "@std/expect"; import { ASSET_CACHE_BUST_KEY } from "../constants.ts"; @@ -10,6 +10,7 @@ import { getContentType, systemPathToUrlEncoded, } from "../dev/dev_build_cache.ts"; +import { App, setBuildCache } from "../app.ts"; class MockBuildCache implements BuildCache { root = ""; @@ -260,16 +261,34 @@ Deno.test("static files - fallthrough", async () => { "foo.css": { content: "body {}", hash: null }, }); - const server = serveMiddleware( - staticFiles(), - { buildCache, next: () => Promise.resolve(new Response("it works")) }, - ); + let called: string[] = []; + const app = new App<{ text: string }>() + .use((ctx) => { + ctx.state.text = "it"; + called.push("before"); + return ctx.next(); + }) + .use(staticFiles()) + .use((ctx) => { + ctx.state.text += " works"; + called.push("after"); + return ctx.next(); + }) + .get("/", (ctx) => new Response(ctx.state.text)); + + setBuildCache(app, buildCache, "production"); + + const server = new FakeServer(app.handler()); let res = await server.get("foo.css"); let text = await res.text(); expect(text).toEqual("body {}"); + expect(called).toEqual(["before"]); + + called = []; res = await server.get("/"); text = await res.text(); expect(text).toEqual("it works"); + expect(called).toEqual(["before", "after"]); });