summaryrefslogtreecommitdiff
path: root/std/http/server_test.ts
diff options
context:
space:
mode:
authorCasper Beyer <caspervonb@pm.me>2020-09-14 18:58:43 +0800
committerGitHub <noreply@github.com>2020-09-14 12:58:43 +0200
commitbee36a4de8516aa222bbb2b6650974bdd7cb57f4 (patch)
tree68abd673e6fa3e1fbcf68772e79eb904680e4d16 /std/http/server_test.ts
parentf874b83aa06c183400bbe04bc35e87acbaad9699 (diff)
test(std/http): make tests runnable from any directory (#7441)
This makes std/http tests runnable from any directory by spawning test processes in the module directory resolved from import.meta.url and resolving test data relative to the same module directory.
Diffstat (limited to 'std/http/server_test.ts')
-rw-r--r--std/http/server_test.ts18
1 files changed, 12 insertions, 6 deletions
diff --git a/std/http/server_test.ts b/std/http/server_test.ts
index bc9b52341..564ec4e07 100644
--- a/std/http/server_test.ts
+++ b/std/http/server_test.ts
@@ -25,6 +25,10 @@ import { BufReader, BufWriter } from "../io/bufio.ts";
import { delay } from "../async/delay.ts";
import { encode, decode } from "../encoding/utf8.ts";
import { mockConn } from "./_mock_conn.ts";
+import { resolve, dirname, join, fromFileUrl } from "../path/mod.ts";
+
+const moduleDir = dirname(fromFileUrl(import.meta.url));
+const testdataDir = resolve(moduleDir, "testdata");
interface ResponseTest {
response: Response;
@@ -367,8 +371,9 @@ Deno.test({
Deno.execPath(),
"run",
"--allow-net",
- "http/testdata/simple_server.ts",
+ "testdata/simple_server.ts",
],
+ cwd: moduleDir,
stdout: "piped",
});
@@ -412,8 +417,9 @@ Deno.test({
"run",
"--allow-net",
"--allow-read",
- "http/testdata/simple_https_server.ts",
+ "testdata/simple_https_server.ts",
],
+ cwd: moduleDir,
stdout: "piped",
});
@@ -436,7 +442,7 @@ Deno.test({
const conn = await Deno.connectTls({
hostname: "localhost",
port: 4503,
- certFile: "http/testdata/tls/RootCA.pem",
+ certFile: join(testdataDir, "tls/RootCA.pem"),
});
await Deno.writeAll(
conn,
@@ -570,8 +576,8 @@ Deno.test({
const tlsOptions = {
hostname: "localhost",
port,
- certFile: "./http/testdata/tls/localhost.crt",
- keyFile: "./http/testdata/tls/localhost.key",
+ certFile: join(testdataDir, "tls/localhost.crt"),
+ keyFile: join(testdataDir, "tls/localhost.key"),
};
const server = serveTLS(tlsOptions);
const p = iteratorReq(server);
@@ -593,7 +599,7 @@ Deno.test({
const conn = await Deno.connectTls({
hostname: "localhost",
port,
- certFile: "http/testdata/tls/RootCA.pem",
+ certFile: join(testdataDir, "tls/RootCA.pem"),
});
await Deno.writeAll(