Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 5 additions & 4 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,12 @@ export class App<State> {
return this;
}

async handler(): Promise<
(request: Request, info?: Deno.ServeHandlerInfo) => Promise<Response>
> {
handler(): (
request: Request,
info?: Deno.ServeHandlerInfo,
) => Promise<Response> {
if (this.#buildCache === null) {
this.#buildCache = await ProdBuildCache.fromSnapshot(
this.#buildCache = ProdBuildCache.fromSnapshot(
this.config,
this.#islandRegistry.size,
);
Expand Down
48 changes: 24 additions & 24 deletions src/app_test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Deno.test("FreshApp - .use()", async () => {
})
.get("/", (ctx) => new Response(ctx.state.text));

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());

const res = await server.get("/");
expect(await res.text()).toEqual("AB");
Expand All @@ -27,7 +27,7 @@ Deno.test("FreshApp - .use() #2", async () => {
.get("/foo/bar", () => new Response("ok #2"))
.get("/", () => new Response("ok #3"));

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());

const res = await server.get("/");
expect(await res.text()).toEqual("ok #1");
Expand All @@ -40,7 +40,7 @@ Deno.test("FreshApp - .get()", async () => {
.get("/", () => new Response("ok"))
.get("/foo", () => new Response("ok"));

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());

let res = await server.get("/");
expect(await res.text()).toEqual("ok");
Expand All @@ -54,7 +54,7 @@ Deno.test("FreshApp - .get() with basePath", async () => {
.get("/", () => new Response("ok"))
.get("/foo", () => new Response("ok"));

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());

let res = await server.get("/");
expect(res.status).toEqual(404);
Expand All @@ -74,7 +74,7 @@ Deno.test("FreshApp - .post()", async () => {
.post("/", () => new Response("ok"))
.post("/foo", () => new Response("ok"));

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());

let res = await server.post("/");
expect(await res.text()).toEqual("ok");
Expand All @@ -88,7 +88,7 @@ Deno.test("FreshApp - .post() with basePath", async () => {
.post("/", () => new Response("ok"))
.post("/foo", () => new Response("ok"));

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());

let res = await server.post("/");
expect(res.status).toEqual(404);
Expand All @@ -108,7 +108,7 @@ Deno.test("FreshApp - .patch()", async () => {
.patch("/", () => new Response("ok"))
.patch("/foo", () => new Response("ok"));

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());

let res = await server.patch("/");
expect(await res.text()).toEqual("ok");
Expand All @@ -122,7 +122,7 @@ Deno.test("FreshApp - .patch() with basePath", async () => {
.patch("/", () => new Response("ok"))
.patch("/foo", () => new Response("ok"));

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());

let res = await server.patch("/");
expect(res.status).toEqual(404);
Expand All @@ -142,7 +142,7 @@ Deno.test("FreshApp - .put()", async () => {
.put("/", () => new Response("ok"))
.put("/foo", () => new Response("ok"));

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());

let res = await server.put("/");
expect(await res.text()).toEqual("ok");
Expand All @@ -156,7 +156,7 @@ Deno.test("FreshApp - .put() with basePath", async () => {
.put("/", () => new Response("ok"))
.put("/foo", () => new Response("ok"));

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());

let res = await server.put("/");
expect(res.status).toEqual(404);
Expand All @@ -176,7 +176,7 @@ Deno.test("FreshApp - .delete()", async () => {
.delete("/", () => new Response("ok"))
.delete("/foo", () => new Response("ok"));

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());

let res = await server.delete("/");
expect(await res.text()).toEqual("ok");
Expand All @@ -190,7 +190,7 @@ Deno.test("FreshApp - .delete() with basePath", async () => {
.delete("/", () => new Response("ok"))
.delete("/foo", () => new Response("ok"));

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());

let res = await server.delete("/");
expect(res.status).toEqual(404);
Expand All @@ -208,7 +208,7 @@ Deno.test("FreshApp - wrong method match", async () => {
.get("/", () => new Response("ok"))
.post("/", () => new Response("ok"));

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());

let res = await server.put("/");
expect(res.status).toEqual(405);
Expand All @@ -228,7 +228,7 @@ Deno.test("FreshApp - methods with middleware", async () => {
.get("/", (ctx) => new Response(ctx.state.text))
.post("/", (ctx) => new Response(ctx.state.text));

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());

let res = await server.get("/");
expect(await res.text()).toEqual("A");
Expand All @@ -250,7 +250,7 @@ Deno.test("FreshApp - .mountApp() compose apps", async () => {
.get("/", () => new Response("ok"))
.mountApp("/foo", innerApp);

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());

let res = await server.get("/");
expect(await res.text()).toEqual("ok");
Expand All @@ -275,7 +275,7 @@ Deno.test("FreshApp - .mountApp() self mount, no middleware", async () => {
.get("/", () => new Response("ok"))
.mountApp("/", innerApp);

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());

let res = await server.get("/");
expect(await res.text()).toEqual("ok");
Expand Down Expand Up @@ -306,7 +306,7 @@ Deno.test(
.get("/", () => new Response("ok"))
.mountApp("/", innerApp);

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());

let res = await server.get("/");
expect(await res.text()).toEqual("ok");
Expand Down Expand Up @@ -338,7 +338,7 @@ Deno.test(
.get("/", () => new Response("ok"))
.mountApp("/", innerApp);

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());

let res = await server.get("/");
expect(await res.text()).toEqual("ok");
Expand All @@ -362,7 +362,7 @@ Deno.test("FreshApp - .mountApp() self mount empty", async () => {
const app = new App<{ text: string }>()
.mountApp("/", innerApp);

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());

const res = await server.get("/foo");
expect(await res.text()).toEqual("A");
Expand All @@ -385,7 +385,7 @@ Deno.test(
})
.mountApp("/", innerApp);

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());

const res = await server.get("/");
expect(await res.text()).toEqual("Outer_Inner");
Expand All @@ -408,7 +408,7 @@ Deno.test("FreshApp - catches errors", async () => {
throw new Error("fail");
});

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());

const res = await server.get("/");
expect(res.status).toEqual(500);
Expand All @@ -432,7 +432,7 @@ Deno.test.ignore("FreshApp - finish setup", async () => {
}, getIslandRegistry(app).size),
);

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());
const res = await server.get("/");
const text = await res.text();
expect(text).toContain("Finish setting up");
Expand Down Expand Up @@ -462,7 +462,7 @@ Deno.test("FreshApp - sets error on context", async () => {
throw "<mock error>";
});

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());

const res = await server.get("/");
await res.body?.cancel();
Expand All @@ -480,7 +480,7 @@ Deno.test("FreshApp - support setting request init in ctx.render()", async () =>
});
});

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());
const res = await server.get("/");
await res.body?.cancel();
expect(res.status).toEqual(416);
Expand Down
4 changes: 2 additions & 2 deletions src/build_cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ export interface BuildCache {
}

export class ProdBuildCache implements BuildCache {
static async fromSnapshot(config: ResolvedFreshConfig, islandCount: number) {
static fromSnapshot(config: ResolvedFreshConfig, islandCount: number) {
const snapshotPath = getSnapshotPath(config);

const staticFiles = new Map<string, FileSnapshot>();
const islandToChunk = new Map<string, string>();

let hasSnapshot = false;
try {
const content = await Deno.readTextFile(snapshotPath);
const content = Deno.readTextFileSync(snapshotPath);
const snapshot = JSON.parse(content) as BuildSnapshot;
hasSnapshot = true;
setBuildId(snapshot.buildId);
Expand Down
6 changes: 3 additions & 3 deletions src/context_test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Deno.test("render asset()", async () => {
</>,
));

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());
const res = await server.get("/");
const doc = parseHtml(await res.text());

Expand All @@ -52,7 +52,7 @@ Deno.test("ctx.render - throw with no arguments", async () => {
const app = new App()
// deno-lint-ignore no-explicit-any
.get("/", (ctx) => (ctx as any).render());
const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());
const res = await server.get("/");

await res.body?.cancel();
Expand All @@ -63,7 +63,7 @@ Deno.test("ctx.render - throw with invalid first arg", async () => {
const app = new App()
// deno-lint-ignore no-explicit-any
.get("/", (ctx) => (ctx as any).render({}));
const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());
const res = await server.get("/");

await res.body?.cancel();
Expand Down
8 changes: 4 additions & 4 deletions src/dev/middlewares/error_overlay/middleware_test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Deno.test("error overlay - show when error is thrown", async () => {
throw new Error("fail");
});

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());
const res = await server.get("/", {
headers: {
accept: "text/html",
Expand All @@ -36,7 +36,7 @@ Deno.test("error overlay - should not be visible for HttpError <500", async () =
throw new HttpError(500);
});

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());
let res = await server.get("/", {
headers: {
accept: "text/html",
Expand Down Expand Up @@ -74,7 +74,7 @@ Deno.test(
throw new HttpError(404);
});

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());
const res = await server.get("/", {
headers: {
accept: "text/html",
Expand All @@ -94,7 +94,7 @@ Deno.test("error overlay - should not be visible in prod", async () => {
throw new HttpError(500);
});

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());
const res = await server.get("/", {
headers: {
accept: "text/html",
Expand Down
4 changes: 2 additions & 2 deletions src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { STATUS_TEXT } from "@std/http/status";
* throw new HttpError(404, "Nothing here");
* });
*
* const handler = await app.handler();
* const handler = app.handler();
*
* try {
* await handler(new Request("http://localhost/not-found"))
Expand All @@ -43,7 +43,7 @@ export class HttpError extends Error {
* throw new HttpError(404, "Nothing here");
* });
*
* const handler = await app.handler();
* const handler = app.handler();
*
* try {
* await handler(new Request("http://localhost/not-found"))
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/fs_routes/mod_test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async function createServer<T>(
_fs: createFakeFs(files),
} as FsRoutesOptions & TESTING_ONLY__FsRoutesOptions,
);
return new FakeServer(await app.handler());
return new FakeServer(app.handler());
}

Deno.test("fsRoutes - throws error when file has no exports", async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/active_links_test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Deno.test({
return ctx.render(<View />);
});

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());
let res = await server.get("/active_nav");
let doc = parseHtml(await res.text());

Expand Down
2 changes: 1 addition & 1 deletion tests/fixture_precompile/valid/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const app = new App({ staticDir: "./static" }).get(
),
);

const handler = await app.handler();
const handler = app.handler();
const res = await handler(new Request("http://localhost/"));
// deno-lint-ignore no-console
console.log(await res.text());
2 changes: 1 addition & 1 deletion tests/islands_test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ Deno.test({
</Doc>,
));

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());
const res = await server.get("/");
await res.body?.cancel();

Expand Down
6 changes: 3 additions & 3 deletions tests/partials_test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ Deno.test({
);
});

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());
let checked = false;
try {
const res = await server.get("/");
Expand Down Expand Up @@ -306,7 +306,7 @@ Deno.test({
});

await buildProd(app);
const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());
let checked = false;
try {
const res = await server.get("/");
Expand Down Expand Up @@ -845,7 +845,7 @@ Deno.test({
);
});

const server = new FakeServer(await app.handler());
const server = new FakeServer(app.handler());
const res = await server.get("/");
const html = await res.text();

Expand Down
Loading
Loading