fix(std/examples): add tests for examples (#4094)

This commit is contained in:
uki00a 2020-02-24 22:31:40 +09:00 committed by GitHub
parent 162d66d23f
commit fe9ac35a65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 258 additions and 5 deletions

View file

@ -1,3 +1,4 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { assert, assertEquals } from "../../testing/asserts.ts";
import { TextProtoReader } from "../../textproto/mod.ts";
import { BufReader } from "../../io/bufio.ts";
@ -22,10 +23,12 @@ async function startServer(): Promise<void> {
const { test } = Deno;
await startServer();
test("beforeAll", async () => {
await startServer();
});
test("GET / should serve html", async () => {
const resp = await fetch("http://0.0.0.0:8080/");
const resp = await fetch("http://127.0.0.1:8080/");
assertEquals(resp.status, 200);
assertEquals(resp.headers.get("content-type"), "text/html");
const html = await resp.body.text();
@ -34,7 +37,7 @@ test("GET / should serve html", async () => {
let ws: WebSocket | undefined;
test("GET /ws should upgrade conn to ws", async () => {
ws = await connectWebSocket("http://0.0.0.0:8080/ws");
ws = await connectWebSocket("http://127.0.0.1:8080/ws");
const it = ws.receive();
assertEquals((await it.next()).value, "Connected: [1]");
ws.send("Hello");