refactor: remove deno.run (#1036)
Co-authored-by: Luca Casonato <hello@lcas.dev>
This commit is contained in:
co-authored by
Luca Casonato
parent
891503e77f
commit
7e72fa236c
+7
-8
@@ -134,24 +134,23 @@ const manifest = {
|
||||
export default manifest;
|
||||
`;
|
||||
|
||||
const proc = Deno.run({
|
||||
cmd: [Deno.execPath(), "fmt", "-"],
|
||||
const proc = new Deno.Command(Deno.execPath(), {
|
||||
args: ["fmt", "-"],
|
||||
stdin: "piped",
|
||||
stdout: "piped",
|
||||
stderr: "null",
|
||||
});
|
||||
}).spawn();
|
||||
|
||||
const raw = new ReadableStream({
|
||||
start(controller) {
|
||||
controller.enqueue(new TextEncoder().encode(output));
|
||||
controller.close();
|
||||
},
|
||||
});
|
||||
await raw.pipeTo(proc.stdin.writable);
|
||||
const out = await proc.output();
|
||||
await proc.status();
|
||||
proc.close();
|
||||
await raw.pipeTo(proc.stdin);
|
||||
const { stdout } = await proc.output();
|
||||
|
||||
const manifestStr = new TextDecoder().decode(out);
|
||||
const manifestStr = new TextDecoder().decode(stdout);
|
||||
const manifestPath = join(directory, "./fresh.gen.ts");
|
||||
|
||||
await Deno.writeTextFile(manifestPath, manifestStr);
|
||||
|
||||
+28
-49
@@ -42,9 +42,8 @@ Deno.test({
|
||||
const tmpDirName = await Deno.makeTempDir();
|
||||
|
||||
await t.step("execute init command", async () => {
|
||||
const cliProcess = Deno.run({
|
||||
cmd: [
|
||||
"deno",
|
||||
const cliProcess = new Deno.Command(Deno.execPath(), {
|
||||
args: [
|
||||
"run",
|
||||
"-A",
|
||||
"init.ts",
|
||||
@@ -53,8 +52,7 @@ Deno.test({
|
||||
stdin: "null",
|
||||
stdout: "null",
|
||||
});
|
||||
const { code } = await cliProcess.status();
|
||||
cliProcess.close();
|
||||
const { code } = await cliProcess.output();
|
||||
assertEquals(code, 0);
|
||||
});
|
||||
|
||||
@@ -113,15 +111,15 @@ Deno.test({
|
||||
});
|
||||
|
||||
await t.step("start up the server and access the root page", async () => {
|
||||
const serverProcess = Deno.run({
|
||||
cmd: ["deno", "run", "-A", "--check", "main.ts"],
|
||||
const serverProcess = new Deno.Command(Deno.execPath(), {
|
||||
args: ["run", "-A", "--check", "main.ts"],
|
||||
stdin: "null",
|
||||
stdout: "piped",
|
||||
stderr: "inherit",
|
||||
cwd: tmpDirName,
|
||||
});
|
||||
}).spawn();
|
||||
|
||||
const lines = serverProcess.stdout.readable
|
||||
const lines = serverProcess.stdout
|
||||
.pipeThrough(new TextDecoderStream())
|
||||
.pipeThrough(new TextLineStream());
|
||||
|
||||
@@ -166,13 +164,11 @@ Deno.test({
|
||||
|
||||
await lines.cancel();
|
||||
serverProcess.kill("SIGTERM");
|
||||
await serverProcess.status();
|
||||
serverProcess.close();
|
||||
await delay(100);
|
||||
});
|
||||
|
||||
await retry(() => Deno.remove(tmpDirName, { recursive: true }));
|
||||
},
|
||||
sanitizeOps: false,
|
||||
sanitizeResources: false,
|
||||
});
|
||||
|
||||
@@ -183,9 +179,8 @@ Deno.test({
|
||||
const tmpDirName = await Deno.makeTempDir();
|
||||
|
||||
await t.step("execute init command", async () => {
|
||||
const cliProcess = Deno.run({
|
||||
cmd: [
|
||||
"deno",
|
||||
const cliProcess = new Deno.Command(Deno.execPath(), {
|
||||
args: [
|
||||
"run",
|
||||
"-A",
|
||||
"init.ts",
|
||||
@@ -196,8 +191,7 @@ Deno.test({
|
||||
stdin: "null",
|
||||
stdout: "null",
|
||||
});
|
||||
const { code } = await cliProcess.status();
|
||||
cliProcess.close();
|
||||
const { code } = await cliProcess.output();
|
||||
assertEquals(code, 0);
|
||||
});
|
||||
|
||||
@@ -265,15 +259,15 @@ Deno.test({
|
||||
});
|
||||
|
||||
await t.step("start up the server and access the root page", async () => {
|
||||
const serverProcess = Deno.run({
|
||||
cmd: ["deno", "run", "-A", "--check", "main.ts"],
|
||||
const serverProcess = new Deno.Command(Deno.execPath(), {
|
||||
args: ["run", "-A", "--check", "main.ts"],
|
||||
stdin: "null",
|
||||
stdout: "piped",
|
||||
stderr: "inherit",
|
||||
cwd: tmpDirName,
|
||||
});
|
||||
}).spawn();
|
||||
|
||||
const lines = serverProcess.stdout.readable
|
||||
const lines = serverProcess.stdout
|
||||
.pipeThrough(new TextDecoderStream())
|
||||
.pipeThrough(new TextLineStream());
|
||||
|
||||
@@ -322,13 +316,11 @@ Deno.test({
|
||||
|
||||
await lines.cancel();
|
||||
serverProcess.kill("SIGTERM");
|
||||
await serverProcess.status();
|
||||
serverProcess.close();
|
||||
await delay(100);
|
||||
});
|
||||
|
||||
await retry(() => Deno.remove(tmpDirName, { recursive: true }));
|
||||
},
|
||||
sanitizeOps: false,
|
||||
sanitizeResources: false,
|
||||
});
|
||||
|
||||
@@ -338,18 +330,15 @@ Deno.test("fresh-init error(help)", async function (t) {
|
||||
await t.step(
|
||||
"execute invalid init command (deno run -A init.ts)",
|
||||
async () => {
|
||||
const cliProcess = Deno.run({
|
||||
cmd: ["deno", "run", "-A", "init.ts"],
|
||||
const cliProcess = new Deno.Command(Deno.execPath(), {
|
||||
args: ["run", "-A", "init.ts"],
|
||||
stdin: "null",
|
||||
stderr: "piped",
|
||||
});
|
||||
const { code } = await cliProcess.status();
|
||||
cliProcess.close();
|
||||
const { code, stderr } = await cliProcess.output();
|
||||
assertEquals(code, 1);
|
||||
|
||||
const rawError = await cliProcess.stderrOutput();
|
||||
const errorString = new TextDecoder().decode(rawError);
|
||||
|
||||
const errorString = new TextDecoder().decode(stderr);
|
||||
assertStringIncludes(errorString, includeText);
|
||||
},
|
||||
);
|
||||
@@ -357,18 +346,13 @@ Deno.test("fresh-init error(help)", async function (t) {
|
||||
await t.step(
|
||||
"execute invalid init command (deno run -A init.ts -f)",
|
||||
async () => {
|
||||
const cliProcess = Deno.run({
|
||||
cmd: ["deno", "run", "-A", "init.ts", "-f"],
|
||||
stdin: "null",
|
||||
stderr: "piped",
|
||||
const cliProcess = new Deno.Command(Deno.execPath(), {
|
||||
args: ["run", "-A", "init.ts", "-f"],
|
||||
});
|
||||
const { code } = await cliProcess.status();
|
||||
cliProcess.close();
|
||||
const { code, stderr } = await cliProcess.output();
|
||||
assertEquals(code, 1);
|
||||
|
||||
const rawError = await cliProcess.stderrOutput();
|
||||
const errorString = new TextDecoder().decode(rawError);
|
||||
|
||||
const errorString = new TextDecoder().decode(stderr);
|
||||
assertStringIncludes(errorString, includeText);
|
||||
},
|
||||
);
|
||||
@@ -376,18 +360,13 @@ Deno.test("fresh-init error(help)", async function (t) {
|
||||
await t.step(
|
||||
"execute invalid init command (deno run -A init.ts --foo)",
|
||||
async () => {
|
||||
const cliProcess = Deno.run({
|
||||
cmd: ["deno", "run", "-A", "init.ts", "--foo"],
|
||||
stdin: "null",
|
||||
stderr: "piped",
|
||||
const cliProcess = new Deno.Command(Deno.execPath(), {
|
||||
args: ["run", "-A", "init.ts", "--foo"],
|
||||
});
|
||||
const { code } = await cliProcess.status();
|
||||
cliProcess.close();
|
||||
const { code, stderr } = await cliProcess.output();
|
||||
assertEquals(code, 1);
|
||||
|
||||
const rawError = await cliProcess.stderrOutput();
|
||||
const errorString = new TextDecoder().decode(rawError);
|
||||
|
||||
const errorString = new TextDecoder().decode(stderr);
|
||||
assertStringIncludes(errorString, includeText);
|
||||
},
|
||||
);
|
||||
|
||||
+8
-10
@@ -10,14 +10,14 @@ Deno.test({
|
||||
name: "island tests",
|
||||
async fn(t) {
|
||||
// Preparation
|
||||
const serverProcess = Deno.run({
|
||||
cmd: ["deno", "run", "-A", "./tests/fixture/main.ts"],
|
||||
const serverProcess = new Deno.Command(Deno.execPath(), {
|
||||
args: ["run", "-A", "./tests/fixture/main.ts"],
|
||||
stdout: "piped",
|
||||
stderr: "inherit",
|
||||
});
|
||||
}).spawn();
|
||||
|
||||
const decoder = new TextDecoderStream();
|
||||
const lines = serverProcess.stdout.readable
|
||||
const lines = serverProcess.stdout
|
||||
.pipeThrough(decoder)
|
||||
.pipeThrough(new TextLineStream());
|
||||
|
||||
@@ -77,7 +77,6 @@ Deno.test({
|
||||
|
||||
await lines.cancel();
|
||||
serverProcess.kill("SIGTERM");
|
||||
serverProcess.close();
|
||||
},
|
||||
sanitizeOps: false,
|
||||
sanitizeResources: false,
|
||||
@@ -87,14 +86,14 @@ Deno.test({
|
||||
name: "island tests with </script>",
|
||||
async fn(t) {
|
||||
// Preparation
|
||||
const serverProcess = Deno.run({
|
||||
cmd: ["deno", "run", "-A", "./tests/fixture/main.ts"],
|
||||
const serverProcess = new Deno.Command(Deno.execPath(), {
|
||||
args: ["run", "-A", "./tests/fixture/main.ts"],
|
||||
stdout: "piped",
|
||||
stderr: "inherit",
|
||||
});
|
||||
}).spawn();
|
||||
|
||||
const decoder = new TextDecoderStream();
|
||||
const lines = serverProcess.stdout.readable
|
||||
const lines = serverProcess.stdout
|
||||
.pipeThrough(decoder)
|
||||
.pipeThrough(new TextLineStream());
|
||||
|
||||
@@ -136,7 +135,6 @@ Deno.test({
|
||||
|
||||
await lines.cancel();
|
||||
serverProcess.kill("SIGTERM");
|
||||
serverProcess.close();
|
||||
},
|
||||
sanitizeOps: false,
|
||||
sanitizeResources: false,
|
||||
|
||||
+8
-11
@@ -500,9 +500,8 @@ Deno.test("experimental Deno.serve", {
|
||||
ignore: Deno.build.os === "windows", // TODO: Deno.serve hang on Windows?
|
||||
}, async (t) => {
|
||||
// Preparation
|
||||
const serverProcess = Deno.run({
|
||||
cmd: [
|
||||
"deno",
|
||||
const serverProcess = new Deno.Command(Deno.execPath(), {
|
||||
args: [
|
||||
"run",
|
||||
"-A",
|
||||
"--unstable",
|
||||
@@ -511,10 +510,10 @@ Deno.test("experimental Deno.serve", {
|
||||
],
|
||||
stdout: "piped",
|
||||
stderr: "inherit",
|
||||
});
|
||||
}).spawn();
|
||||
|
||||
const decoder = new TextDecoderStream();
|
||||
const lines = serverProcess.stdout.readable
|
||||
const lines = serverProcess.stdout
|
||||
.pipeThrough(decoder)
|
||||
.pipeThrough(new TextLineStream());
|
||||
|
||||
@@ -562,7 +561,6 @@ Deno.test("experimental Deno.serve", {
|
||||
|
||||
await lines.cancel();
|
||||
serverProcess.kill("SIGTERM");
|
||||
serverProcess.close();
|
||||
});
|
||||
|
||||
Deno.test("jsx pragma works", {
|
||||
@@ -570,14 +568,14 @@ Deno.test("jsx pragma works", {
|
||||
sanitizeResources: false,
|
||||
}, async (t) => {
|
||||
// Preparation
|
||||
const serverProcess = Deno.run({
|
||||
cmd: ["deno", "run", "-A", "./tests/fixture_jsx_pragma/main.ts"],
|
||||
const serverProcess = new Deno.Command(Deno.execPath(), {
|
||||
args: ["run", "-A", "./tests/fixture_jsx_pragma/main.ts"],
|
||||
stdout: "piped",
|
||||
stderr: "inherit",
|
||||
});
|
||||
}).spawn();
|
||||
|
||||
const decoder = new TextDecoderStream();
|
||||
const lines = serverProcess.stdout.readable
|
||||
const lines = serverProcess.stdout
|
||||
.pipeThrough(decoder)
|
||||
.pipeThrough(new TextLineStream());
|
||||
|
||||
@@ -617,5 +615,4 @@ Deno.test("jsx pragma works", {
|
||||
|
||||
await lines.cancel();
|
||||
serverProcess.kill("SIGTERM");
|
||||
serverProcess.close();
|
||||
});
|
||||
|
||||
@@ -54,14 +54,14 @@ Deno.test({
|
||||
name: "/with-island hydration",
|
||||
async fn(t) {
|
||||
// Preparation
|
||||
const serverProcess = Deno.run({
|
||||
cmd: ["deno", "run", "-A", "./tests/fixture_plugin/main.ts"],
|
||||
const serverProcess = new Deno.Command(Deno.execPath(), {
|
||||
args: ["run", "-A", "./tests/fixture_plugin/main.ts"],
|
||||
stdout: "piped",
|
||||
stderr: "inherit",
|
||||
});
|
||||
}).spawn();
|
||||
|
||||
const decoder = new TextDecoderStream();
|
||||
const lines = serverProcess.stdout.readable
|
||||
const lines = serverProcess.stdout
|
||||
.pipeThrough(decoder)
|
||||
.pipeThrough(new TextLineStream());
|
||||
|
||||
@@ -98,7 +98,6 @@ Deno.test({
|
||||
|
||||
await lines.cancel();
|
||||
serverProcess.kill("SIGTERM");
|
||||
serverProcess.close();
|
||||
},
|
||||
sanitizeOps: false,
|
||||
sanitizeResources: false,
|
||||
|
||||
+8
-5
@@ -1,17 +1,19 @@
|
||||
import { assertEquals } from "$std/testing/asserts.ts";
|
||||
import { TextLineStream } from "$std/streams/delimiter.ts";
|
||||
import { delay } from "$std/async/delay.ts";
|
||||
|
||||
Deno.test("CORS should not set on GET /fresh-badge.svg", {
|
||||
sanitizeResources: false,
|
||||
}, async () => {
|
||||
const serverProcess = Deno.run({
|
||||
cmd: ["deno", "run", "-A", "./main.ts"],
|
||||
const serverProcess = new Deno.Command(Deno.execPath(), {
|
||||
args: ["run", "-A", "./main.ts"],
|
||||
stdin: "null",
|
||||
stdout: "piped",
|
||||
stderr: "inherit",
|
||||
});
|
||||
}).spawn();
|
||||
|
||||
const decoder = new TextDecoderStream();
|
||||
const lines = serverProcess.stdout.readable
|
||||
const lines = serverProcess.stdout
|
||||
.pipeThrough(decoder)
|
||||
.pipeThrough(new TextLineStream());
|
||||
|
||||
@@ -33,5 +35,6 @@ Deno.test("CORS should not set on GET /fresh-badge.svg", {
|
||||
|
||||
await lines.cancel();
|
||||
serverProcess.kill("SIGTERM");
|
||||
serverProcess.close();
|
||||
// await for the server to close
|
||||
await delay(100);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user