Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove deno.run #1036

Merged
merged 18 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/dev/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
77 changes: 28 additions & 49 deletions tests/cli_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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);
});

Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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,
});

Expand All @@ -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",
Expand All @@ -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);
});

Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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,
});

Expand All @@ -338,56 +330,43 @@ 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);
},
);

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);
},
);

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);
},
);
Expand Down
18 changes: 8 additions & 10 deletions tests/islands_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -77,7 +77,6 @@ Deno.test({

await lines.cancel();
serverProcess.kill("SIGTERM");
serverProcess.close();
},
sanitizeOps: false,
sanitizeResources: false,
Expand All @@ -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());

Expand Down Expand Up @@ -136,7 +135,6 @@ Deno.test({

await lines.cancel();
serverProcess.kill("SIGTERM");
serverProcess.close();
},
sanitizeOps: false,
sanitizeResources: false,
Expand Down
19 changes: 8 additions & 11 deletions tests/main_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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());

Expand Down Expand Up @@ -562,22 +561,21 @@ Deno.test("experimental Deno.serve", {

await lines.cancel();
serverProcess.kill("SIGTERM");
serverProcess.close();
});

Deno.test("jsx pragma works", {
sanitizeOps: false,
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());

Expand Down Expand Up @@ -617,5 +615,4 @@ Deno.test("jsx pragma works", {

await lines.cancel();
serverProcess.kill("SIGTERM");
serverProcess.close();
});
9 changes: 4 additions & 5 deletions tests/plugin_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -98,7 +98,6 @@ Deno.test({

await lines.cancel();
serverProcess.kill("SIGTERM");
serverProcess.close();
},
sanitizeOps: false,
sanitizeResources: false,
Expand Down
13 changes: 8 additions & 5 deletions www/main_test.ts
Original file line number Diff line number Diff line change
@@ -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());

Expand All @@ -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);
});