import { ServerContext, Status } from "../server.ts"; import { assert, assertEquals, assertStringIncludes, delay, puppeteer, } from "./deps.ts"; import manifest from "./fixture_plugin/fresh.gen.ts"; import options from "./fixture_plugin/options.ts"; import { startFreshServer } from "./test_utils.ts"; const ctx = await ServerContext.fromManifest(manifest, options); const handler = ctx.handler(); const router = (req: Request) => { return handler(req, { remoteAddr: { transport: "tcp", hostname: "127.0.0.1", port: 80, }, }); }; Deno.test("/static page prerender", async () => { const resp = await router(new Request("https://fresh.deno.dev/static")); assert(resp); assertEquals(resp.status, Status.OK); const body = await resp.text(); assertStringIncludes(body, ''); assert(!body.includes(`>{"v":[[],[]]}`)); assert(!body.includes(`import`)); assertStringIncludes( body, '', ); }); Deno.test("/with-island prerender", async () => { const resp = await router(new Request("https://fresh.deno.dev/with-island")); assert(resp); assertEquals(resp.status, Status.OK); const body = await resp.text(); assertStringIncludes( body, '', ); assertStringIncludes(body, `>{"v":[[{}],["JS injected!"]]}`); assertStringIncludes(body, `/plugin-js-inject-main.js"`); assertStringIncludes( body, '', ); }); Deno.test("plugin routes and middleware", async () => { const resp = await router(new Request("https://fresh.deno.dev/test")); assert(resp); assertEquals(resp.status, Status.OK); const body = await resp.text(); assertStringIncludes( body, `