diff options
author | Casper Beyer <caspervonb@pm.me> | 2020-09-10 02:57:49 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-09 20:57:49 +0200 |
commit | 5b89e82164f997da863f92c829ff026beabf5abe (patch) | |
tree | 60461ce91f3f3976115a7535dd2bc6b9fe3a5f81 /std/examples/tests | |
parent | 25053f92ffcefa7659ac8c7b1aa2d80986942c4f (diff) |
test(std/examples): make tests runnable from any directory (#7399)
Diffstat (limited to 'std/examples/tests')
-rw-r--r-- | std/examples/tests/cat_test.ts | 5 | ||||
-rw-r--r-- | std/examples/tests/catj_test.ts | 5 | ||||
-rw-r--r-- | std/examples/tests/colors_test.ts | 5 | ||||
-rw-r--r-- | std/examples/tests/curl_test.ts | 5 | ||||
-rw-r--r-- | std/examples/tests/echo_server_test.ts | 5 | ||||
-rw-r--r-- | std/examples/tests/welcome_test.ts | 5 | ||||
-rw-r--r-- | std/examples/tests/xeval_test.ts | 7 |
7 files changed, 30 insertions, 7 deletions
diff --git a/std/examples/tests/cat_test.ts b/std/examples/tests/cat_test.ts index 8fb124460..3b6f0d40f 100644 --- a/std/examples/tests/cat_test.ts +++ b/std/examples/tests/cat_test.ts @@ -1,5 +1,8 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { assertStrictEquals } from "../../testing/asserts.ts"; +import { resolve, dirname, fromFileUrl } from "../../path/mod.ts"; + +const moduleDir = resolve(dirname(fromFileUrl(import.meta.url)), ".."); Deno.test("[examples/cat] print multiple files", async () => { const decoder = new TextDecoder(); @@ -12,7 +15,7 @@ Deno.test("[examples/cat] print multiple files", async () => { "testdata/cat/hello.txt", "testdata/cat/world.txt", ], - cwd: "examples", + cwd: moduleDir, stdout: "piped", }); diff --git a/std/examples/tests/catj_test.ts b/std/examples/tests/catj_test.ts index 99320fd1d..c79403421 100644 --- a/std/examples/tests/catj_test.ts +++ b/std/examples/tests/catj_test.ts @@ -1,5 +1,8 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { assertStrictEquals } from "../../testing/asserts.ts"; +import { resolve, dirname, fromFileUrl } from "../../path/mod.ts"; + +const moduleDir = resolve(dirname(fromFileUrl(import.meta.url)), ".."); Deno.test("[examples/catj] print an array", async () => { const decoder = new TextDecoder(); @@ -80,7 +83,7 @@ function catj( ): Deno.Process<Deno.RunOptions & { stdin: "piped"; stdout: "piped" }> { return Deno.run({ cmd: [Deno.execPath(), "run", "--allow-read", "catj.ts", ...files], - cwd: "examples", + cwd: moduleDir, stdin: "piped", stdout: "piped", env: { NO_COLOR: "true" }, diff --git a/std/examples/tests/colors_test.ts b/std/examples/tests/colors_test.ts index 1a3e4f418..91d016232 100644 --- a/std/examples/tests/colors_test.ts +++ b/std/examples/tests/colors_test.ts @@ -1,11 +1,14 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { assertStrictEquals } from "../../testing/asserts.ts"; +import { resolve, dirname, fromFileUrl } from "../../path/mod.ts"; + +const moduleDir = resolve(dirname(fromFileUrl(import.meta.url)), ".."); Deno.test("[examples/colors] print a colored text", async () => { const decoder = new TextDecoder(); const process = Deno.run({ cmd: [Deno.execPath(), "run", "colors.ts"], - cwd: "examples", + cwd: moduleDir, stdout: "piped", }); try { diff --git a/std/examples/tests/curl_test.ts b/std/examples/tests/curl_test.ts index 4449d11ea..f35edab4c 100644 --- a/std/examples/tests/curl_test.ts +++ b/std/examples/tests/curl_test.ts @@ -1,6 +1,9 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { serve } from "../../http/server.ts"; import { assertStrictEquals } from "../../testing/asserts.ts"; +import { resolve, dirname, fromFileUrl } from "../../path/mod.ts"; + +const moduleDir = resolve(dirname(fromFileUrl(import.meta.url)), ".."); Deno.test({ name: "[examples/curl] send a request to a specified url", @@ -21,7 +24,7 @@ Deno.test({ "curl.ts", "http://localhost:8081", ], - cwd: "examples", + cwd: moduleDir, stdout: "piped", }); diff --git a/std/examples/tests/echo_server_test.ts b/std/examples/tests/echo_server_test.ts index 61afb9756..6bfcbbc3d 100644 --- a/std/examples/tests/echo_server_test.ts +++ b/std/examples/tests/echo_server_test.ts @@ -1,13 +1,16 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { assertStrictEquals, assertNotEquals } from "../../testing/asserts.ts"; import { BufReader, ReadLineResult } from "../../io/bufio.ts"; +import { resolve, dirname, fromFileUrl } from "../../path/mod.ts"; + +const moduleDir = resolve(dirname(fromFileUrl(import.meta.url)), ".."); Deno.test("[examples/echo_server]", async () => { const encoder = new TextEncoder(); const decoder = new TextDecoder(); const process = Deno.run({ cmd: [Deno.execPath(), "run", "--allow-net", "echo_server.ts"], - cwd: "examples", + cwd: moduleDir, stdout: "piped", }); diff --git a/std/examples/tests/welcome_test.ts b/std/examples/tests/welcome_test.ts index d585211a1..5f8d81988 100644 --- a/std/examples/tests/welcome_test.ts +++ b/std/examples/tests/welcome_test.ts @@ -1,11 +1,14 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { assertStrictEquals } from "../../testing/asserts.ts"; +import { resolve, dirname, fromFileUrl } from "../../path/mod.ts"; + +const moduleDir = resolve(dirname(fromFileUrl(import.meta.url)), ".."); Deno.test("[examples/welcome] print a welcome message", async () => { const decoder = new TextDecoder(); const process = Deno.run({ cmd: [Deno.execPath(), "run", "welcome.ts"], - cwd: "examples", + cwd: moduleDir, stdout: "piped", }); try { diff --git a/std/examples/tests/xeval_test.ts b/std/examples/tests/xeval_test.ts index cc74c5226..d3493d397 100644 --- a/std/examples/tests/xeval_test.ts +++ b/std/examples/tests/xeval_test.ts @@ -7,6 +7,9 @@ import { assertStringContains, assert, } from "../../testing/asserts.ts"; +import { resolve, dirname, fromFileUrl } from "../../path/mod.ts"; + +const moduleDir = resolve(dirname(fromFileUrl(import.meta.url)), ".."); Deno.test("xevalSuccess", async function (): Promise<void> { const chunks: string[] = []; @@ -26,7 +29,7 @@ Deno.test("xevalDelimiter", async function (): Promise<void> { assertEquals(chunks, ["!MAD", "ADAM!"]); }); -const xevalPath = "examples/xeval.ts"; +const xevalPath = "xeval.ts"; Deno.test({ name: "xevalCliReplvar", @@ -39,6 +42,7 @@ Deno.test({ "--replvar=abc", "console.log(abc)", ], + cwd: moduleDir, stdin: "piped", stdout: "piped", stderr: "null", @@ -55,6 +59,7 @@ Deno.test({ Deno.test("xevalCliSyntaxError", async function (): Promise<void> { const p = Deno.run({ cmd: [Deno.execPath(), "run", xevalPath, "("], + cwd: moduleDir, stdin: "null", stdout: "piped", stderr: "piped", |