Skip to main content
Module

x/fastro/test/server_test.ts

Fast and simple web application framework for deno
Go to Latest
File
const { test } = Deno;import { assertEquals } from "../deps.ts";import { Fastro } from "../mod.ts";const addr = "http://localhost:8000";const port = 8000;
test({ name: "GET", async fn() { const server = new Fastro(); server.route({ method: "GET", url: "/", handler(req) { req.respond({ body: "hello" }); }, }); server.listen({ port }); const result = await fetch(addr); const text = await result.text(); assertEquals(text, "hello"); server.close(); },});
test({ name: "GET URL PARAMETER", async fn() { const server = new Fastro(); server.route({ method: "GET", url: "/login/user", handler(req) { const [, , name] = req.parameter; req.respond({ body: `hello, ${name}` }); }, }); server.listen({ port }); const result = await fetch(addr + "/login/user/agus"); const text = await result.text(); assertEquals(text, "hello, agus"); server.close(); },});
test({ name: "STATIC FILE", async fn() { const server = new Fastro({ static: true }); server.static("/", "public"); server.listen({ port }); const result = await fetch(addr + "/text"); const text = await result.text(); assertEquals(text, "ok"); server.close(); },});