summaryrefslogtreecommitdiff
path: root/cli/tests/unit
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2022-12-02 14:43:17 +0100
committerGitHub <noreply@github.com>2022-12-02 14:43:17 +0100
commit4d07ed0efa8f0e2cab1a33f1b7b6a3627bfce69f (patch)
tree898aadf1ae739190ed98ec463824f7e9ca8f48eb /cli/tests/unit
parent6982c74e11ec8294ed5bd53d2a9d316d7e20e7d2 (diff)
chore: rewrite tests and utils to use Deno.Command API (#16895)
Since "Deno.spawn()", "Deno.spawnSync()" and "Deno.spawnChild" are getting deprecated, this commits rewrites all tests and utilities to use "Deno.Command" API instead.
Diffstat (limited to 'cli/tests/unit')
-rw-r--r--cli/tests/unit/chown_test.ts8
-rw-r--r--cli/tests/unit/flash_test.ts4
-rw-r--r--cli/tests/unit/flock_test.ts4
-rw-r--r--cli/tests/unit/http_test.ts50
-rw-r--r--cli/tests/unit/os_test.ts12
-rw-r--r--cli/tests/unit/remove_test.ts8
-rw-r--r--cli/tests/unit/signal_test.ts4
-rw-r--r--cli/tests/unit/test_util.ts4
-rw-r--r--cli/tests/unit/tls_test.ts4
-rw-r--r--cli/tests/unit/tty_color_test.ts4
10 files changed, 51 insertions, 51 deletions
diff --git a/cli/tests/unit/chown_test.ts b/cli/tests/unit/chown_test.ts
index 2fa203e18..dd23627ae 100644
--- a/cli/tests/unit/chown_test.ts
+++ b/cli/tests/unit/chown_test.ts
@@ -5,12 +5,12 @@ import { assertEquals, assertRejects, assertThrows } from "./test_util.ts";
async function getUidAndGid(): Promise<{ uid: number; gid: number }> {
// get the user ID and group ID of the current process
- const uidProc = await Deno.spawn("id", {
+ const uidProc = await new Deno.Command("id", {
args: ["-u"],
- });
- const gidProc = await Deno.spawn("id", {
+ }).output();
+ const gidProc = await new Deno.Command("id", {
args: ["-g"],
- });
+ }).output();
assertEquals(uidProc.code, 0);
assertEquals(gidProc.code, 0);
diff --git a/cli/tests/unit/flash_test.ts b/cli/tests/unit/flash_test.ts
index 024069455..836c9b603 100644
--- a/cli/tests/unit/flash_test.ts
+++ b/cli/tests/unit/flash_test.ts
@@ -1033,11 +1033,11 @@ Deno.test(
await listeningPromise;
const url = `http://${hostname}:${port}/`;
const args = ["-X", "DELETE", url];
- const { success } = await Deno.spawn("curl", {
+ const { success } = await new Deno.Command("curl", {
args,
stdout: "null",
stderr: "null",
- });
+ }).output();
assert(success);
await promise;
ac.abort();
diff --git a/cli/tests/unit/flock_test.ts b/cli/tests/unit/flock_test.ts
index 7ece1695c..be463bf12 100644
--- a/cli/tests/unit/flock_test.ts
+++ b/cli/tests/unit/flock_test.ts
@@ -148,10 +148,10 @@ function runFlockTestProcess(opts: { exclusive: boolean; sync: boolean }) {
console.log(JSON.stringify({ enterTime, exitTime }));
`;
- const process = Deno.spawnChild(Deno.execPath(), {
+ const process = new Deno.Command(Deno.execPath(), {
args: ["eval", "--unstable", scriptText],
stdin: "piped",
- });
+ }).spawn();
const waitSignal = async () => {
const reader = process.stdout.getReader({ mode: "byob" });
diff --git a/cli/tests/unit/http_test.ts b/cli/tests/unit/http_test.ts
index 1d2addb2d..0c17c7277 100644
--- a/cli/tests/unit/http_test.ts
+++ b/cli/tests/unit/http_test.ts
@@ -1249,11 +1249,11 @@ Deno.test(
async function client() {
const url = `http://${hostname}:${port}/`;
const args = ["-X", "DELETE", url];
- const { success } = await Deno.spawn("curl", {
+ const { success } = await new Deno.Command("curl", {
args,
stdout: "null",
stderr: "null",
- });
+ }).output();
assert(success);
}
@@ -1380,10 +1380,10 @@ Deno.test({
"--header",
"Accept-Encoding: gzip, deflate, br",
];
- const { success, stdout } = await Deno.spawn("curl", {
+ const { success, stdout } = await new Deno.Command("curl", {
args,
stderr: "null",
- });
+ }).output();
assert(success);
const output = decoder.decode(stdout);
assert(output.includes("vary: Accept-Encoding\r\n"));
@@ -1430,7 +1430,7 @@ Deno.test({
"--header",
"Accept-Encoding: gzip, deflate, br",
];
- const proc = Deno.spawnChild("curl", { args, stderr: "null" });
+ const proc = new Deno.Command("curl", { args, stderr: "null" }).spawn();
const status = await proc.status;
assert(status.success);
const stdout = proc.stdout
@@ -1485,10 +1485,10 @@ Deno.test({
"--header",
"Accept-Encoding: gzip, deflate, br",
];
- const { success, stdout } = await Deno.spawn("curl", {
+ const { success, stdout } = await new Deno.Command("curl", {
args,
stderr: "null",
- });
+ }).output();
assert(success);
const output = decoder.decode(stdout).toLocaleLowerCase();
assert(output.includes("vary: accept-encoding\r\n"));
@@ -1540,10 +1540,10 @@ Deno.test({
"--header",
"Accept-Encoding: gzip;q=0.8, br;q=1.0, *;q=0.1",
];
- const { success, stdout } = await Deno.spawn("curl", {
+ const { success, stdout } = await new Deno.Command("curl", {
args,
stderr: "null",
- });
+ }).output();
assert(success);
const output = decoder.decode(stdout);
assert(output.includes("vary: Accept-Encoding\r\n"));
@@ -1592,10 +1592,10 @@ Deno.test({
"--header",
"Accept-Encoding: gzip, deflate, br",
];
- const { success, stdout } = await Deno.spawn("curl", {
+ const { success, stdout } = await new Deno.Command("curl", {
args,
stderr: "null",
- });
+ }).output();
assert(success);
const output = decoder.decode(stdout);
assert(output.includes("vary: Accept-Encoding, Accept\r\n"));
@@ -1648,10 +1648,10 @@ Deno.test({
"--header",
"Accept-Encoding: gzip, deflate, br",
];
- const { success, stdout } = await Deno.spawn("curl", {
+ const { success, stdout } = await new Deno.Command("curl", {
args,
stderr: "null",
- });
+ }).output();
assert(success);
const output = decoder.decode(stdout);
assert(output.includes("vary: Accept-Encoding\r\n"));
@@ -1706,10 +1706,10 @@ Deno.test({
"--header",
"Accept-Encoding: gzip, deflate, br",
];
- const { success, stdout } = await Deno.spawn("curl", {
+ const { success, stdout } = await new Deno.Command("curl", {
args,
stderr: "null",
- });
+ }).output();
assert(success);
const output = decoder.decode(stdout);
assert(output.includes("vary: Accept-Encoding\r\n"));
@@ -1764,10 +1764,10 @@ Deno.test({
"--header",
"Accept-Encoding: gzip, deflate, br",
];
- const { success, stdout } = await Deno.spawn("curl", {
+ const { success, stdout } = await new Deno.Command("curl", {
args,
stderr: "null",
- });
+ }).output();
assert(success);
const output = decoder.decode(stdout);
assert(output.includes("vary: Accept-Encoding\r\n"));
@@ -1819,10 +1819,10 @@ Deno.test({
"--header",
"Accept-Encoding: gzip, deflate, br",
];
- const { success, stdout } = await Deno.spawn("curl", {
+ const { success, stdout } = await new Deno.Command("curl", {
args,
stderr: "null",
- });
+ }).output();
assert(success);
const output = decoder.decode(stdout);
assert(output.includes("vary: Accept-Encoding\r\n"));
@@ -1880,10 +1880,10 @@ Deno.test({
"--header",
"Accept-Encoding: gzip, deflate, br",
];
- const { success, stdout } = await Deno.spawn("curl", {
+ const { success, stdout } = await new Deno.Command("curl", {
args,
stderr: "null",
- });
+ }).output();
assert(success);
const output = decoder.decode(stdout);
assert(output.includes("vary: Accept-Encoding\r\n"));
@@ -1939,7 +1939,7 @@ Deno.test({
"--header",
"Accept-Encoding: gzip, deflate, br",
];
- const proc = Deno.spawnChild("curl", { args, stderr: "null" });
+ const proc = new Deno.Command("curl", { args, stderr: "null" }).spawn();
const status = await proc.status;
assert(status.success);
const stdout = proc.stdout
@@ -2004,10 +2004,10 @@ Deno.test({
"--header",
"Accept-Encoding: gzip, deflate, br",
];
- const { success, stdout } = await Deno.spawn("curl", {
+ const { success, stdout } = await new Deno.Command("curl", {
args,
stderr: "null",
- });
+ }).output();
assert(success);
const output = decoder.decode(stdout);
assert(output.includes("vary: Accept-Encoding\r\n"));
@@ -2569,7 +2569,7 @@ Deno.test({
"Accept-Encoding: gzip, deflate, br",
"--no-buffer",
];
- const proc = Deno.spawnChild("curl", { args, stderr: "null" });
+ const proc = new Deno.Command("curl", { args, stderr: "null" }).spawn();
const stdout = proc.stdout
.pipeThrough(new DecompressionStream("gzip"))
.pipeThrough(new TextDecoderStream());
diff --git a/cli/tests/unit/os_test.ts b/cli/tests/unit/os_test.ts
index 04ddf8ae0..72e0b57ba 100644
--- a/cli/tests/unit/os_test.ts
+++ b/cli/tests/unit/os_test.ts
@@ -74,10 +74,10 @@ Deno.test(
console.log(
${JSON.stringify(Object.keys(expectedEnv))}.map(k => Deno.env.get(k))
)`;
- const { success, stdout } = await Deno.spawn(Deno.execPath(), {
+ const { success, stdout } = await new Deno.Command(Deno.execPath(), {
args: ["eval", src],
env: { ...inputEnv, NO_COLOR: "1" },
- });
+ }).output();
assertEquals(success, true);
const expectedValues = Object.values(expectedEnv);
const actualValues = JSON.parse(new TextDecoder().decode(stdout));
@@ -162,10 +162,10 @@ Deno.test(
{ permissions: { run: true, read: true } },
async function osPpidIsEqualToPidOfParentProcess() {
const decoder = new TextDecoder();
- const { stdout } = await Deno.spawn(Deno.execPath(), {
+ const { stdout } = await new Deno.Command(Deno.execPath(), {
args: ["eval", "-p", "--unstable", "Deno.ppid"],
env: { NO_COLOR: "true" },
- });
+ }).output();
const expected = Deno.pid;
const actual = parseInt(decoder.decode(stdout));
@@ -212,9 +212,9 @@ Deno.test(
{ permissions: { run: [Deno.execPath()], read: true } },
// See https://github.com/denoland/deno/issues/16527
async function hostnameWithoutOtherNetworkUsages() {
- const { stdout } = await Deno.spawn(Deno.execPath(), {
+ const { stdout } = await new Deno.Command(Deno.execPath(), {
args: ["eval", "-p", "Deno.hostname()"],
- });
+ }).output();
const hostname = new TextDecoder().decode(stdout).trim();
assert(hostname.length > 0);
},
diff --git a/cli/tests/unit/remove_test.ts b/cli/tests/unit/remove_test.ts
index ae439e305..0032459eb 100644
--- a/cli/tests/unit/remove_test.ts
+++ b/cli/tests/unit/remove_test.ts
@@ -260,10 +260,10 @@ if (Deno.build.os === "windows") {
Deno.test(
{ permissions: { run: true, write: true, read: true } },
async function removeFileSymlink() {
- const { success } = await Deno.spawn("cmd", {
+ const { success } = await new Deno.Command("cmd", {
args: ["/c", "mklink", "file_link", "bar"],
stdout: "null",
- });
+ }).output();
assert(success);
await Deno.remove("file_link");
@@ -276,10 +276,10 @@ if (Deno.build.os === "windows") {
Deno.test(
{ permissions: { run: true, write: true, read: true } },
async function removeDirSymlink() {
- const { success } = await Deno.spawn("cmd", {
+ const { success } = await new Deno.Command("cmd", {
args: ["/c", "mklink", "/d", "dir_link", "bar"],
stdout: "null",
- });
+ }).output();
assert(success);
await Deno.remove("dir_link");
diff --git a/cli/tests/unit/signal_test.ts b/cli/tests/unit/signal_test.ts
index 86092a298..25143da1f 100644
--- a/cli/tests/unit/signal_test.ts
+++ b/cli/tests/unit/signal_test.ts
@@ -185,13 +185,13 @@ Deno.test(
permissions: { run: true, read: true },
},
async function canExitWhileListeningToSignal() {
- const { code } = await Deno.spawn(Deno.execPath(), {
+ const { code } = await new Deno.Command(Deno.execPath(), {
args: [
"eval",
"--unstable",
"Deno.addSignalListener('SIGINT', () => {})",
],
- });
+ }).output();
assertEquals(code, 0);
},
);
diff --git a/cli/tests/unit/test_util.ts b/cli/tests/unit/test_util.ts
index c33da5338..9a1b13038 100644
--- a/cli/tests/unit/test_util.ts
+++ b/cli/tests/unit/test_util.ts
@@ -32,13 +32,13 @@ export function pathToAbsoluteFileUrl(path: string): URL {
const decoder = new TextDecoder();
export async function execCode(code: string): Promise<[number, string]> {
- const output = await Deno.spawn(Deno.execPath(), {
+ const output = await new Deno.Command(Deno.execPath(), {
args: [
"eval",
"--unstable",
"--no-check",
code,
],
- });
+ }).output();
return [output.code, decoder.decode(output.stdout)];
}
diff --git a/cli/tests/unit/tls_test.ts b/cli/tests/unit/tls_test.ts
index d3ef4d0bf..e5ad6e66c 100644
--- a/cli/tests/unit/tls_test.ts
+++ b/cli/tests/unit/tls_test.ts
@@ -1046,9 +1046,9 @@ function createHttpsListener(port: number): Deno.Listener {
}
async function curl(url: string): Promise<string> {
- const { success, code, stdout } = await Deno.spawn("curl", {
+ const { success, code, stdout } = await new Deno.Command("curl", {
args: ["--insecure", url],
- });
+ }).output();
if (!success) {
throw new Error(`curl ${url} failed: ${code}`);
diff --git a/cli/tests/unit/tty_color_test.ts b/cli/tests/unit/tty_color_test.ts
index 7662d039b..f819a1a63 100644
--- a/cli/tests/unit/tty_color_test.ts
+++ b/cli/tests/unit/tty_color_test.ts
@@ -6,9 +6,9 @@ import { assertEquals } from "./test_util.ts";
Deno.test(
{ permissions: { run: true, read: true } },
async function noColorIfNotTty() {
- const { stdout } = await Deno.spawn(Deno.execPath(), {
+ const { stdout } = await new Deno.Command(Deno.execPath(), {
args: ["eval", "console.log(1)"],
- });
+ }).output();
const output = new TextDecoder().decode(stdout);
assertEquals(output, "1\n");
},