From e9f0a4bb0c90dd54f2b3ed3f9a26a836e15a0a6d Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Thu, 24 Jul 2025 16:26:41 +0200 Subject: [PATCH] docs: migration for createHandler (#3129) Fixes https://github.com/denoland/fresh/issues/2986 --- docs/canary/examples/migration-guide.md | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docs/canary/examples/migration-guide.md b/docs/canary/examples/migration-guide.md index c17545cb..355b661e 100644 --- a/docs/canary/examples/migration-guide.md +++ b/docs/canary/examples/migration-guide.md @@ -233,6 +233,36 @@ re-use existing objects internally as a minor performance optimization. | `ctx.basePath` | `ctx.config.basePath` | | `ctx.remoteAddr` | `ctx.info.remoteAddr` | +## `createHandler` + +The `createHandler` function was often used to launch Fresh for tests. This can +be now done via the [`Builder`](/docs/canary/concepts/builder). + +```ts +// Best to do this once instead of for every test case for +// performance reasons. +const builder = new Builder(); +const applySnapshot = await builder.build({ snapshot: "memory" }); + +function testApp() { + const app = new App() + .get("/", () => new Response("hello")); + // Applies build snapshot to this app instance. + applySnapshot(app); +} + +Deno.test("My Test", () => { + const handler = testApp().handler(); + + const response = await handler(new Request("http://localhost")); + const text = await response.text(); + + if (text !== "hello") { + throw new Error("fail"); + } +}); +``` + ## Getting help If you run into problems with upgrading your app, reach out to us by creating an