From c1ff7314adfaeac7d1f9e466e71130326fa6209f Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Thu, 24 Jul 2025 16:22:24 +0200 Subject: [PATCH] docs: migration for createHandler --- 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 c17545cbecd..355b661ede3 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