import { assertEquals, assertStringIncludes,} from "https://deno.land/std@0.95.0/testing/asserts.ts";
import { accumulate, Cache } from "./mod.ts";
Deno.test("accumulate - accumulates the file from the iterable", async () => { const cache = {} as Cache; await accumulate(gen(), cache); assertEquals(Object.keys(cache), [ "/foo.txt", "/foo/bar.html", "/foo/bar/baz.txt", ]);});
Deno.test("serve - serves the given assets", async () => { const p = Deno.run({ cmd: [ Deno.execPath(), "run", "--allow-net", "--unstable", "test_server.ts", ], });
await new Promise((resolve) => setTimeout(resolve, 2000));
let res: Response; res = await fetch("http://0.0.0.0:3030/__debug__"); assertStringIncludes(await res.text(), "debug page");
res = await fetch("http://0.0.0.0:3030/foo.txt"); assertEquals(await res.text(), "foo"); res = await fetch("http://0.0.0.0:3030/foo/bar.html"); assertEquals(await res.text(), "bar"); res = await fetch("http://0.0.0.0:3030/foo/bar/baz.txt"); assertEquals(await res.text(), "baz");
res = await fetch("http://0.0.0.0:3030/"); assertEquals(await res.text(), "index"); res = await fetch("http://0.0.0.0:3030/foo"); assertEquals(await res.text(), "404 Not Found"); res = await fetch("http://0.0.0.0:3030/foo/"); assertEquals(await res.text(), "foo/index");
res = await fetch("http://0.0.0.0:3030/asdf.txt"); assertEquals(await res.text(), "404 Not Found");
Deno.kill(p.pid, Deno.Signal.SIGINT); p.close();});
async function* gen() { yield Object.assign(new Blob(["foo"]), { name: "foo.txt" }); yield Object.assign(new Blob(["bar"]), { name: "foo/bar.html" }); yield Object.assign(new Blob(["baz"]), { name: "foo/bar/baz.txt" });}