diff options
Diffstat (limited to 'std/examples')
-rw-r--r-- | std/examples/catj.ts | 44 | ||||
-rw-r--r-- | std/examples/chat/server_test.ts | 40 | ||||
-rw-r--r-- | std/examples/tests/xeval_test.ts | 1 |
3 files changed, 52 insertions, 33 deletions
diff --git a/std/examples/catj.ts b/std/examples/catj.ts index 4329d27b1..3ef14ce0b 100644 --- a/std/examples/catj.ts +++ b/std/examples/catj.ts @@ -81,28 +81,30 @@ function print(data: any): void { } } -const parsedArgs = parse(Deno.args); - -if (parsedArgs.h || parsedArgs.help || parsedArgs._.length === 0) { - console.log("Usage: catj [-h|--help] [file...]"); - console.log(); - console.log("Examples:"); - console.log(); - console.log("// print file:\n catj file.json"); - console.log(); - console.log("// print multiple files:\n catj file1.json file2.json"); - console.log(); - console.log("// print from stdin:\n cat file.json | catj -"); -} +if (import.meta.main) { + const parsedArgs = parse(Deno.args); + + if (parsedArgs.h || parsedArgs.help || parsedArgs._.length === 0) { + console.log("Usage: catj [-h|--help] [file...]"); + console.log(); + console.log("Examples:"); + console.log(); + console.log("// print file:\n catj file.json"); + console.log(); + console.log("// print multiple files:\n catj file1.json file2.json"); + console.log(); + console.log("// print from stdin:\n cat file.json | catj -"); + } -if (parsedArgs._[0] === "-") { - const contents = await Deno.readAll(Deno.stdin); - const json = JSON.parse(decoder.decode(contents)); - print(json); -} else { - for (const fileName of parsedArgs._) { - const fileContents = await Deno.readFile(fileName); - const json = JSON.parse(decoder.decode(fileContents)); + if (parsedArgs._[0] === "-") { + const contents = await Deno.readAll(Deno.stdin); + const json = JSON.parse(decoder.decode(contents)); print(json); + } else { + for (const fileName of parsedArgs._) { + const fileContents = await Deno.readFile(fileName.toString()); + const json = JSON.parse(decoder.decode(fileContents)); + print(json); + } } } diff --git a/std/examples/chat/server_test.ts b/std/examples/chat/server_test.ts index 3e2a62ee0..c63453a19 100644 --- a/std/examples/chat/server_test.ts +++ b/std/examples/chat/server_test.ts @@ -24,29 +24,47 @@ async function startServer(): Promise<void> { const { test, build } = Deno; // TODO: https://github.com/denoland/deno/issues/4108 -if (build.os !== "win") { - test("beforeAll", async () => { +const skip = build.os == "win"; + +test({ + skip, + name: "beforeAll", + async fn() { await startServer(); - }); + } +}); - test("GET / should serve html", async () => { +test({ + skip, + name: "GET / should serve html", + async fn() { 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(); assert(html.includes("ws chat example"), "body is ok"); - }); + } +}); + +let ws: WebSocket | undefined; - let ws: WebSocket | undefined; - test("GET /ws should upgrade conn to ws", async () => { +test({ + skip, + name: "GET /ws should upgrade conn to ws", + async fn() { ws = await connectWebSocket("http://127.0.0.1:8080/ws"); const it = ws.receive(); assertEquals((await it.next()).value, "Connected: [1]"); ws.send("Hello"); assertEquals((await it.next()).value, "[1]: Hello"); - }); - test("afterAll", () => { + } +}); + +test({ + skip, + name: "afterAll", + fn() { server?.close(); ws?.conn.close(); - }); -} + } +}); diff --git a/std/examples/tests/xeval_test.ts b/std/examples/tests/xeval_test.ts index 870a00acf..128b6e3da 100644 --- a/std/examples/tests/xeval_test.ts +++ b/std/examples/tests/xeval_test.ts @@ -23,7 +23,6 @@ Deno.test(async function xevalDelimiter(): Promise<void> { assertEquals(chunks, ["!MAD", "ADAM!"]); }); -// https://github.com/denoland/deno/issues/2861 const xevalPath = "examples/xeval.ts"; Deno.test(async function xevalCliReplvar(): Promise<void> { |