Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions docs/canary/examples/migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading