summaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/serve_test.ts28
-rw-r--r--tests/unit/test_util.ts33
2 files changed, 35 insertions, 26 deletions
diff --git a/tests/unit/serve_test.ts b/tests/unit/serve_test.ts
index 5d83aa5fc..9b2870ebd 100644
--- a/tests/unit/serve_test.ts
+++ b/tests/unit/serve_test.ts
@@ -8,6 +8,8 @@ import {
assertEquals,
assertStringIncludes,
assertThrows,
+ curlRequest,
+ curlRequestWithStdErr,
execCode,
fail,
tmpUnixSocketPath,
@@ -3793,32 +3795,6 @@ Deno.test(
},
);
-async function curlRequest(args: string[]) {
- const { success, stdout, stderr } = await new Deno.Command("curl", {
- args,
- stdout: "piped",
- stderr: "piped",
- }).output();
- assert(
- success,
- `Failed to cURL ${args}: stdout\n\n${stdout}\n\nstderr:\n\n${stderr}`,
- );
- return new TextDecoder().decode(stdout);
-}
-
-async function curlRequestWithStdErr(args: string[]) {
- const { success, stdout, stderr } = await new Deno.Command("curl", {
- args,
- stdout: "piped",
- stderr: "piped",
- }).output();
- assert(
- success,
- `Failed to cURL ${args}: stdout\n\n${stdout}\n\nstderr:\n\n${stderr}`,
- );
- return [new TextDecoder().decode(stdout), new TextDecoder().decode(stderr)];
-}
-
Deno.test("Deno.HttpServer is not thenable", async () => {
// deno-lint-ignore require-await
async function serveTest() {
diff --git a/tests/unit/test_util.ts b/tests/unit/test_util.ts
index c73f52b15..ba9bf1839 100644
--- a/tests/unit/test_util.ts
+++ b/tests/unit/test_util.ts
@@ -1,6 +1,7 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import * as colors from "@std/fmt/colors.ts";
+import { assert } from "@std/assert/mod.ts";
export { colors };
import { join, resolve } from "@std/path/mod.ts";
export {
@@ -85,3 +86,35 @@ export function tmpUnixSocketPath(): string {
const folder = Deno.makeTempDirSync();
return join(folder, "socket");
}
+
+export async function curlRequest(args: string[]) {
+ const { success, stdout, stderr } = await new Deno.Command("curl", {
+ args,
+ stdout: "piped",
+ stderr: "piped",
+ }).output();
+ const decoder = new TextDecoder();
+ assert(
+ success,
+ `Failed to cURL ${args}: stdout\n\n${
+ decoder.decode(stdout)
+ }\n\nstderr:\n\n${decoder.decode(stderr)}`,
+ );
+ return decoder.decode(stdout);
+}
+
+export async function curlRequestWithStdErr(args: string[]) {
+ const { success, stdout, stderr } = await new Deno.Command("curl", {
+ args,
+ stdout: "piped",
+ stderr: "piped",
+ }).output();
+ const decoder = new TextDecoder();
+ assert(
+ success,
+ `Failed to cURL ${args}: stdout\n\n${
+ decoder.decode(stdout)
+ }\n\nstderr:\n\n${decoder.decode(stderr)}`,
+ );
+ return [decoder.decode(stdout), decoder.decode(stderr)];
+}