Skip to content

Commit c1ff731

Browse files
docs: migration for createHandler
1 parent 0841940 commit c1ff731

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

docs/canary/examples/migration-guide.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,36 @@ re-use existing objects internally as a minor performance optimization.
233233
| `ctx.basePath` | `ctx.config.basePath` |
234234
| `ctx.remoteAddr` | `ctx.info.remoteAddr` |
235235

236+
## `createHandler`
237+
238+
The `createHandler` function was often used to launch Fresh for tests. This can
239+
be now done via the [`Builder`](/docs/canary/concepts/builder).
240+
241+
```ts
242+
// Best to do this once instead of for every test case for
243+
// performance reasons.
244+
const builder = new Builder();
245+
const applySnapshot = await builder.build({ snapshot: "memory" });
246+
247+
function testApp() {
248+
const app = new App()
249+
.get("/", () => new Response("hello"));
250+
// Applies build snapshot to this app instance.
251+
applySnapshot(app);
252+
}
253+
254+
Deno.test("My Test", () => {
255+
const handler = testApp().handler();
256+
257+
const response = await handler(new Request("http://localhost"));
258+
const text = await response.text();
259+
260+
if (text !== "hello") {
261+
throw new Error("fail");
262+
}
263+
});
264+
```
265+
236266
## Getting help
237267

238268
If you run into problems with upgrading your app, reach out to us by creating an

0 commit comments

Comments
 (0)