chore: minor code cleanups (#3103)
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Bartek Iwańczuk
Claude Opus 4.6
parent
9509b087ff
commit
0fff2b04da
@@ -1,5 +1,5 @@
|
|||||||
import { staticFiles } from "./static_files.ts";
|
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 type { BuildCache, StaticFile } from "../build_cache.ts";
|
||||||
import { expect } from "@std/expect";
|
import { expect } from "@std/expect";
|
||||||
import { ASSET_CACHE_BUST_KEY } from "../constants.ts";
|
import { ASSET_CACHE_BUST_KEY } from "../constants.ts";
|
||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
getContentType,
|
getContentType,
|
||||||
systemPathToUrlEncoded,
|
systemPathToUrlEncoded,
|
||||||
} from "../dev/dev_build_cache.ts";
|
} from "../dev/dev_build_cache.ts";
|
||||||
|
import { App, setBuildCache } from "../app.ts";
|
||||||
|
|
||||||
class MockBuildCache implements BuildCache {
|
class MockBuildCache implements BuildCache {
|
||||||
root = "";
|
root = "";
|
||||||
@@ -260,16 +261,34 @@ Deno.test("static files - fallthrough", async () => {
|
|||||||
"foo.css": { content: "body {}", hash: null },
|
"foo.css": { content: "body {}", hash: null },
|
||||||
});
|
});
|
||||||
|
|
||||||
const server = serveMiddleware(
|
let called: string[] = [];
|
||||||
staticFiles(),
|
const app = new App<{ text: string }>()
|
||||||
{ buildCache, next: () => Promise.resolve(new Response("it works")) },
|
.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 res = await server.get("foo.css");
|
||||||
let text = await res.text();
|
let text = await res.text();
|
||||||
expect(text).toEqual("body {}");
|
expect(text).toEqual("body {}");
|
||||||
|
expect(called).toEqual(["before"]);
|
||||||
|
|
||||||
|
called = [];
|
||||||
|
|
||||||
res = await server.get("/");
|
res = await server.get("/");
|
||||||
text = await res.text();
|
text = await res.text();
|
||||||
expect(text).toEqual("it works");
|
expect(text).toEqual("it works");
|
||||||
|
expect(called).toEqual(["before", "after"]);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user