Skip to main content
Module

x/fastro/test/plugin_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: "PLUGIN", async fn() { const server = new Fastro(); server .register((fastro, done) => { fastro.get("/ok", (req) => { req.send("PLUGIN"); }); done(); }); server.listen({ port }); const result = await fetch(addr + "/ok"); const text = await result.text(); assertEquals(text, "PLUGIN"); server.close(); },});
test({ name: "PLUGIN WITH PREFIX", async fn() { const server = new Fastro(); server .register("v1", (fastro, done) => { fastro.get("/ok", (req) => { req.send("PLUGIN"); }); done(); }) .register("v2", (fastro, done) => { fastro.get("/oke", (req) => { req.send("PLUGIN"); }); done(); }); server.listen({ port }); const result = await fetch(addr + "/v1/ok"); const text = await result.text(); assertEquals(text, "PLUGIN"); server.close(); },});
test({ name: "MULTIPLE PLUGIN", async fn() { const server = new Fastro();
const plugin = (server: Fastro, done: Function) => { server.get("/ok", (req) => req.send("PLUGIN")); };
server .register(plugin) .register("v1", plugin); server.listen({ port }); const result = await fetch(addr + "/v1/ok"); const text = await result.text(); assertEquals(text, "PLUGIN"); server.close(); },});