import { installRoutes, oak, processRoutes } from "../server.ts"; import { assert, assertEquals, assertStringIncludes } from "./deps.ts"; import routes from "./fixture/routes.gen.ts"; const router = new oak.Router(); installRoutes(router, ...processRoutes(routes)); const app = new oak.Application(); app.use(router.routes()); app.use(router.allowedMethods()); Deno.test("/ page prerender", async () => { const resp = await app.handle(new Request("https://fresh.deno.dev/")); assert(resp); assertEquals(resp.status, 200); assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8"); const body = await resp.text(); assertStringIncludes(body, "index.js"); assertStringIncludes(body, "

Viewing JIT render.

"); assertStringIncludes( body, ``, ); }); Deno.test("/[name] page prerender", async () => { const resp = await app.handle(new Request("https://fresh.deno.dev/foo")); assert(resp); assertEquals(resp.status, 200); assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8"); const body = await resp.text(); assertStringIncludes(body, "[name].js"); assertStringIncludes(body, "
Hello foo
"); assertStringIncludes( body, ``, ); }); Deno.test("/api/name", async () => { const resp = await app.handle(new Request("https://fresh.deno.dev/api/name")); assert(resp); assertEquals(resp.status, 200); assertEquals( resp.headers.get("content-type"), "application/json; charset=utf-8", ); const body = await resp.json(); assertEquals(body, { name: "fresh" }); }); Deno.test("/api/xyz not found", async () => { const resp = await app.handle(new Request("https://fresh.deno.dev/api/xyz")); assert(resp); assertEquals(resp.status, 404); });