import { expect } from "@std/expect"; import { FreshReqContext } from "./context.ts"; import { App } from "fresh"; import { asset } from "fresh/runtime"; import { FakeServer } from "./test_utils.ts"; import { BUILD_ID } from "./runtime/build_id.ts"; import { parseHtml } from "../tests/test_utils.tsx"; Deno.test("FreshReqContext.prototype.redirect", () => { let res = FreshReqContext.prototype.redirect("/"); expect(res.status).toEqual(302); expect(res.headers.get("Location")).toEqual("/"); res = FreshReqContext.prototype.redirect("//evil.com"); expect(res.status).toEqual(302); expect(res.headers.get("Location")).toEqual("/evil.com"); res = FreshReqContext.prototype.redirect("//evil.com/foo//bar"); expect(res.status).toEqual(302); expect(res.headers.get("Location")).toEqual("/evil.com/foo/bar"); res = FreshReqContext.prototype.redirect("https://deno.com"); expect(res.status).toEqual(302); expect(res.headers.get("Location")).toEqual("https://deno.com"); res = FreshReqContext.prototype.redirect("/", 307); expect(res.status).toEqual(307); }); Deno.test("render asset()", async () => { const app = new App() .get("/", (ctx) => ctx.render( <>
{asset("/foo")}