fix: middleware state reset between middlewares (#1500)

This commit is contained in:
Marvin Hagemeister
2023-07-24 11:03:11 +02:00
committed by GitHub
parent 0b96db4bae
commit 38d4b90091
10 changed files with 277 additions and 13 deletions
+20 -1
View File
@@ -9,7 +9,7 @@ import {
import manifest from "./fixture/fresh.gen.ts";
import options from "./fixture/options.ts";
import { BUILD_ID } from "../src/server/build_id.ts";
import { startFreshServer, withPageName } from "./test_utils.ts";
import { parseHtml, startFreshServer, withPageName } from "./test_utils.ts";
import { assertMatch } from "https://deno.land/std@0.193.0/testing/asserts.ts";
const ctx = await ServerContext.fromManifest(manifest, options);
@@ -563,6 +563,25 @@ Deno.test({
},
});
Deno.test({
name: "/middleware - should pass state through all middlewares",
fn: async () => {
const resp = await handler(
new Request("https://fresh.deno.dev/state-middleware/foo"),
);
assert(resp);
assertEquals(resp.status, Status.OK);
const body = await resp.text();
const doc = parseHtml(body);
assertEquals(JSON.parse(doc.querySelector("pre").textContent), {
handler1: "it works",
handler2: "it works",
handler3: "it works",
});
},
});
Deno.test({
name: "/middleware - middlewareParams",
fn: async () => {