docs: migration for createHandler (#3129)

Fixes https://github.com/denoland/fresh/issues/2986
This commit is contained in:
Marvin Hagemeister
2025-07-24 16:26:41 +02:00
committed by GitHub
parent ba1a1bc9c2
commit e9f0a4bb0c
+30
View File
@@ -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