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