mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 10:59:13 +00:00
refactor: use spawn API across codebase (#14414)
This commit is contained in:
parent
5ad8919d64
commit
4e1ca1d178
25 changed files with 266 additions and 327 deletions
|
@ -1165,11 +1165,13 @@ Deno.test(
|
|||
|
||||
async function client() {
|
||||
const url = `http://${hostname}:${port}/`;
|
||||
const cmd = ["curl", "-X", "DELETE", url];
|
||||
const proc = Deno.run({ cmd, stdout: "null", stderr: "null" });
|
||||
const status = await proc.status();
|
||||
const args = ["-X", "DELETE", url];
|
||||
const { status } = await Deno.spawn("curl", {
|
||||
args,
|
||||
stdout: "null",
|
||||
stderr: "null",
|
||||
});
|
||||
assert(status.success);
|
||||
proc.close();
|
||||
}
|
||||
|
||||
await Promise.all([server(), client()]);
|
||||
|
@ -1277,8 +1279,7 @@ Deno.test({
|
|||
|
||||
async function client() {
|
||||
const url = `http://${hostname}:${port}/`;
|
||||
const cmd = [
|
||||
"curl",
|
||||
const args = [
|
||||
"-i",
|
||||
"--request",
|
||||
"GET",
|
||||
|
@ -1287,13 +1288,14 @@ Deno.test({
|
|||
"--header",
|
||||
"Accept-Encoding: gzip, deflate, br",
|
||||
];
|
||||
const proc = Deno.run({ cmd, stdout: "piped", stderr: "null" });
|
||||
const status = await proc.status();
|
||||
const { status, stdout } = await Deno.spawn("curl", {
|
||||
args,
|
||||
stderr: "null",
|
||||
});
|
||||
assert(status.success);
|
||||
const output = decoder.decode(await proc.output());
|
||||
const output = decoder.decode(stdout);
|
||||
assert(output.includes("vary: Accept-Encoding\r\n"));
|
||||
assert(output.includes("content-encoding: gzip\r\n"));
|
||||
proc.close();
|
||||
}
|
||||
|
||||
await Promise.all([server(), client()]);
|
||||
|
@ -1327,8 +1329,7 @@ Deno.test({
|
|||
|
||||
async function client() {
|
||||
const url = `http://${hostname}:${port}/`;
|
||||
const cmd = [
|
||||
"curl",
|
||||
const args = [
|
||||
"--request",
|
||||
"GET",
|
||||
"--url",
|
||||
|
@ -1336,10 +1337,10 @@ Deno.test({
|
|||
"--header",
|
||||
"Accept-Encoding: gzip, deflate, br",
|
||||
];
|
||||
const proc = Deno.run({ cmd, stdout: "piped", stderr: "null" });
|
||||
const status = await proc.status();
|
||||
const proc = Deno.spawnChild("curl", { args, stderr: "null" });
|
||||
const status = await proc.status;
|
||||
assert(status.success);
|
||||
const stdout = proc.stdout!.readable
|
||||
const stdout = proc.stdout
|
||||
.pipeThrough(new DecompressionStream("gzip"))
|
||||
.pipeThrough(new TextDecoderStream());
|
||||
let body = "";
|
||||
|
@ -1347,7 +1348,6 @@ Deno.test({
|
|||
body += chunk;
|
||||
}
|
||||
assertEquals(JSON.parse(body), data);
|
||||
proc.close();
|
||||
}
|
||||
|
||||
await Promise.all([server(), client()]);
|
||||
|
@ -1382,8 +1382,7 @@ Deno.test({
|
|||
|
||||
async function client() {
|
||||
const url = `http://${hostname}:${port}/`;
|
||||
const cmd = [
|
||||
"curl",
|
||||
const args = [
|
||||
"-i",
|
||||
"--request",
|
||||
"GET",
|
||||
|
@ -1392,13 +1391,14 @@ Deno.test({
|
|||
"--header",
|
||||
"Accept-Encoding: gzip, deflate, br",
|
||||
];
|
||||
const proc = Deno.run({ cmd, stdout: "piped", stderr: "null" });
|
||||
const status = await proc.status();
|
||||
const { status, stdout } = await Deno.spawn("curl", {
|
||||
args,
|
||||
stderr: "null",
|
||||
});
|
||||
assert(status.success);
|
||||
const output = decoder.decode(await proc.output()).toLocaleLowerCase();
|
||||
const output = decoder.decode(stdout).toLocaleLowerCase();
|
||||
assert(output.includes("vary: accept-encoding\r\n"));
|
||||
assert(!output.includes("content-encoding: "));
|
||||
proc.close();
|
||||
}
|
||||
|
||||
await Promise.all([server(), client()]);
|
||||
|
@ -1436,8 +1436,7 @@ Deno.test({
|
|||
|
||||
async function client() {
|
||||
const url = `http://${hostname}:${port}/`;
|
||||
const cmd = [
|
||||
"curl",
|
||||
const args = [
|
||||
"-i",
|
||||
"--request",
|
||||
"GET",
|
||||
|
@ -1446,13 +1445,14 @@ Deno.test({
|
|||
"--header",
|
||||
"Accept-Encoding: gzip;q=0.8, br;q=1.0, *;q=0.1",
|
||||
];
|
||||
const proc = Deno.run({ cmd, stdout: "piped", stderr: "null" });
|
||||
const status = await proc.status();
|
||||
const { status, stdout } = await Deno.spawn("curl", {
|
||||
args,
|
||||
stderr: "null",
|
||||
});
|
||||
assert(status.success);
|
||||
const output = decoder.decode(await proc.output());
|
||||
const output = decoder.decode(stdout);
|
||||
assert(output.includes("vary: Accept-Encoding\r\n"));
|
||||
assert(output.includes("content-encoding: br\r\n"));
|
||||
proc.close();
|
||||
}
|
||||
|
||||
await Promise.all([server(), client()]);
|
||||
|
@ -1487,8 +1487,7 @@ Deno.test({
|
|||
|
||||
async function client() {
|
||||
const url = `http://${hostname}:${port}/`;
|
||||
const cmd = [
|
||||
"curl",
|
||||
const args = [
|
||||
"-i",
|
||||
"--request",
|
||||
"GET",
|
||||
|
@ -1497,13 +1496,14 @@ Deno.test({
|
|||
"--header",
|
||||
"Accept-Encoding: gzip, deflate, br",
|
||||
];
|
||||
const proc = Deno.run({ cmd, stdout: "piped", stderr: "null" });
|
||||
const status = await proc.status();
|
||||
const { status, stdout } = await Deno.spawn("curl", {
|
||||
args,
|
||||
stderr: "null",
|
||||
});
|
||||
assert(status.success);
|
||||
const output = decoder.decode(await proc.output());
|
||||
const output = decoder.decode(stdout);
|
||||
assert(output.includes("vary: Accept-Encoding, Accept\r\n"));
|
||||
assert(output.includes("content-encoding: gzip\r\n"));
|
||||
proc.close();
|
||||
}
|
||||
|
||||
await Promise.all([server(), client()]);
|
||||
|
@ -1541,7 +1541,7 @@ Deno.test({
|
|||
|
||||
async function client() {
|
||||
const url = `http://${hostname}:${port}/`;
|
||||
const cmd = [
|
||||
const args = [
|
||||
"curl",
|
||||
"-i",
|
||||
"--request",
|
||||
|
@ -1551,16 +1551,17 @@ Deno.test({
|
|||
"--header",
|
||||
"Accept-Encoding: gzip, deflate, br",
|
||||
];
|
||||
const proc = Deno.run({ cmd, stdout: "piped", stderr: "null" });
|
||||
const status = await proc.status();
|
||||
const { status, stdout } = await Deno.spawn("curl", {
|
||||
args,
|
||||
stderr: "null",
|
||||
});
|
||||
assert(status.success);
|
||||
const output = decoder.decode(await proc.output());
|
||||
const output = decoder.decode(stdout);
|
||||
assert(output.includes("vary: Accept-Encoding\r\n"));
|
||||
assert(
|
||||
output.includes("etag: W/33a64df551425fcc55e4d42a148795d9f25f89d4\r\n"),
|
||||
);
|
||||
assert(output.includes("content-encoding: gzip\r\n"));
|
||||
proc.close();
|
||||
}
|
||||
|
||||
await Promise.all([server(), client()]);
|
||||
|
@ -1598,8 +1599,7 @@ Deno.test({
|
|||
|
||||
async function client() {
|
||||
const url = `http://${hostname}:${port}/`;
|
||||
const cmd = [
|
||||
"curl",
|
||||
const args = [
|
||||
"-i",
|
||||
"--request",
|
||||
"GET",
|
||||
|
@ -1608,16 +1608,17 @@ Deno.test({
|
|||
"--header",
|
||||
"Accept-Encoding: gzip, deflate, br",
|
||||
];
|
||||
const proc = Deno.run({ cmd, stdout: "piped", stderr: "null" });
|
||||
const status = await proc.status();
|
||||
const { status, stdout } = await Deno.spawn("curl", {
|
||||
args,
|
||||
stderr: "null",
|
||||
});
|
||||
assert(status.success);
|
||||
const output = decoder.decode(await proc.output());
|
||||
const output = decoder.decode(stdout);
|
||||
assert(output.includes("vary: Accept-Encoding\r\n"));
|
||||
assert(
|
||||
output.includes("etag: W/33a64df551425fcc55e4d42a148795d9f25f89d4\r\n"),
|
||||
);
|
||||
assert(output.includes("content-encoding: gzip\r\n"));
|
||||
proc.close();
|
||||
}
|
||||
|
||||
await Promise.all([server(), client()]);
|
||||
|
@ -1655,8 +1656,7 @@ Deno.test({
|
|||
|
||||
async function client() {
|
||||
const url = `http://${hostname}:${port}/`;
|
||||
const cmd = [
|
||||
"curl",
|
||||
const args = [
|
||||
"-i",
|
||||
"--request",
|
||||
"GET",
|
||||
|
@ -1665,13 +1665,14 @@ Deno.test({
|
|||
"--header",
|
||||
"Accept-Encoding: gzip, deflate, br",
|
||||
];
|
||||
const proc = Deno.run({ cmd, stdout: "piped", stderr: "null" });
|
||||
const status = await proc.status();
|
||||
const { status, stdout } = await Deno.spawn("curl", {
|
||||
args,
|
||||
stderr: "null",
|
||||
});
|
||||
assert(status.success);
|
||||
const output = decoder.decode(await proc.output());
|
||||
const output = decoder.decode(stdout);
|
||||
assert(output.includes("vary: Accept-Encoding\r\n"));
|
||||
assert(!output.includes("content-encoding: "));
|
||||
proc.close();
|
||||
}
|
||||
|
||||
await Promise.all([server(), client()]);
|
||||
|
@ -1709,8 +1710,7 @@ Deno.test({
|
|||
|
||||
async function client() {
|
||||
const url = `http://${hostname}:${port}/`;
|
||||
const cmd = [
|
||||
"curl",
|
||||
const args = [
|
||||
"-i",
|
||||
"--request",
|
||||
"GET",
|
||||
|
@ -1719,13 +1719,14 @@ Deno.test({
|
|||
"--header",
|
||||
"Accept-Encoding: gzip, deflate, br",
|
||||
];
|
||||
const proc = Deno.run({ cmd, stdout: "piped", stderr: "null" });
|
||||
const status = await proc.status();
|
||||
const { status, stdout } = await Deno.spawn("curl", {
|
||||
args,
|
||||
stderr: "null",
|
||||
});
|
||||
assert(status.success);
|
||||
const output = decoder.decode(await proc.output());
|
||||
const output = decoder.decode(stdout);
|
||||
assert(output.includes("vary: Accept-Encoding\r\n"));
|
||||
assert(!output.includes("content-encoding: "));
|
||||
proc.close();
|
||||
}
|
||||
|
||||
await Promise.all([server(), client()]);
|
||||
|
@ -1768,7 +1769,7 @@ Deno.test({
|
|||
|
||||
async function client() {
|
||||
const url = `http://${hostname}:${port}/`;
|
||||
const cmd = [
|
||||
const args = [
|
||||
"curl",
|
||||
"-i",
|
||||
"--request",
|
||||
|
@ -1778,13 +1779,14 @@ Deno.test({
|
|||
"--header",
|
||||
"Accept-Encoding: gzip, deflate, br",
|
||||
];
|
||||
const proc = Deno.run({ cmd, stdout: "piped", stderr: "null" });
|
||||
const status = await proc.status();
|
||||
const { status, stdout } = await Deno.spawn("curl", {
|
||||
args,
|
||||
stderr: "null",
|
||||
});
|
||||
assert(status.success);
|
||||
const output = decoder.decode(await proc.output());
|
||||
const output = decoder.decode(stdout);
|
||||
assert(output.includes("vary: Accept-Encoding\r\n"));
|
||||
assert(output.includes("content-encoding: gzip\r\n"));
|
||||
proc.close();
|
||||
}
|
||||
|
||||
await Promise.all([server(), client()]);
|
||||
|
@ -1827,8 +1829,7 @@ Deno.test({
|
|||
|
||||
async function client() {
|
||||
const url = `http://${hostname}:${port}/`;
|
||||
const cmd = [
|
||||
"curl",
|
||||
const args = [
|
||||
"--request",
|
||||
"GET",
|
||||
"--url",
|
||||
|
@ -1836,10 +1837,10 @@ Deno.test({
|
|||
"--header",
|
||||
"Accept-Encoding: gzip, deflate, br",
|
||||
];
|
||||
const proc = Deno.run({ cmd, stdout: "piped", stderr: "null" });
|
||||
const status = await proc.status();
|
||||
const proc = Deno.spawnChild("curl", { args, stderr: "null" });
|
||||
const status = await proc.status;
|
||||
assert(status.success);
|
||||
const stdout = proc.stdout.readable
|
||||
const stdout = proc.stdout
|
||||
.pipeThrough(new DecompressionStream("gzip"))
|
||||
.pipeThrough(new TextDecoderStream());
|
||||
let body = "";
|
||||
|
@ -1847,7 +1848,6 @@ Deno.test({
|
|||
body += chunk;
|
||||
}
|
||||
assertEquals(JSON.parse(body), data);
|
||||
proc.close();
|
||||
}
|
||||
|
||||
await Promise.all([server(), client()]);
|
||||
|
@ -1892,8 +1892,7 @@ Deno.test({
|
|||
|
||||
async function client() {
|
||||
const url = `http://${hostname}:${port}/`;
|
||||
const cmd = [
|
||||
"curl",
|
||||
const args = [
|
||||
"-i",
|
||||
"--request",
|
||||
"GET",
|
||||
|
@ -1902,16 +1901,17 @@ Deno.test({
|
|||
"--header",
|
||||
"Accept-Encoding: gzip, deflate, br",
|
||||
];
|
||||
const proc = Deno.run({ cmd, stdout: "piped", stderr: "null" });
|
||||
const status = await proc.status();
|
||||
const { status, stdout } = await Deno.spawn("curl", {
|
||||
args,
|
||||
stderr: "null",
|
||||
});
|
||||
assert(status.success);
|
||||
const output = decoder.decode(await proc.output());
|
||||
const output = decoder.decode(stdout);
|
||||
assert(output.includes("vary: Accept-Encoding\r\n"));
|
||||
assert(output.includes("content-encoding: gzip\r\n"));
|
||||
// Ensure the content-length header is updated.
|
||||
assert(!output.includes(`content-length: ${contentLength}\r\n`));
|
||||
assert(output.includes("content-length: 72\r\n"));
|
||||
proc.close();
|
||||
}
|
||||
|
||||
await Promise.all([server(), client()]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue