Skip to content

Commit 1bb0911

Browse files
author
Test
committed
Revert to tinyexec
1 parent e3ba451 commit 1bb0911

File tree

3 files changed

+102
-223
lines changed

3 files changed

+102
-223
lines changed

deno.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"@std/testing": "jsr:@std/testing@1",
2323
"ts-expect": "npm:ts-expect@1.3.0",
2424
"@std/expect": "jsr:@std/expect@1",
25-
"ctrlc-windows": "npm:ctrlc-windows@2.2.0"
25+
"ctrlc-windows": "npm:ctrlc-windows@2.2.0",
26+
"tinyexec": "npm:tinyexec@1.0.1"
2627
},
2728
"version": "4.0.0-alpha.8"
2829
}

test/main.test.ts

Lines changed: 45 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,101 @@
1-
import { buffer, describe, detect, expect, it, useCommand } from "./suite.ts";
2-
import { run } from "../mod.ts";
1+
import { describe, expect, it, x } from "./suite.ts";
2+
import { each, run, type Stream } from "../mod.ts";
3+
4+
function* detect(stream: Stream<string, void>, text: string) {
5+
for (const line of yield* each(stream)) {
6+
if (line.includes(text)) {
7+
return;
8+
}
9+
yield* each.next();
10+
}
11+
}
312

413
describe("main", () => {
514
it("gracefully shuts down on SIGINT", async () => {
615
await run(function* () {
7-
let daemon = yield* useCommand("deno", {
8-
stdout: "piped",
9-
args: ["run", "--allow-env", "test/main/ok.daemon.ts"],
10-
});
11-
let stdout = yield* buffer(daemon.stdout);
12-
yield* detect(stdout, "started");
16+
let proc = yield* x("deno", ["run", "test/main/ok.daemon.ts"]);
1317

14-
daemon.kill("SIGINT");
18+
yield* detect(proc.lines, "started");
1519

16-
let status = yield* daemon.status;
20+
const { exitCode, stdout } = yield* proc.kill("SIGINT");
1721

18-
expect(status.code).toBe(130);
22+
expect(stdout).toContain("gracefully stopped");
1923

20-
yield* detect(stdout, "gracefully stopped");
24+
expect(exitCode).toBe(130);
2125
});
2226
});
2327

2428
if (Deno.build.os !== "windows") {
2529
it("gracefully shuts down on SIGTERM", async () => {
2630
await run(function* () {
27-
let daemon = yield* useCommand("deno", {
28-
stdout: "piped",
29-
args: ["run", "--allow-env", "test/main/ok.daemon.ts"],
30-
});
31-
let stdout = yield* buffer(daemon.stdout);
32-
yield* detect(stdout, "started");
31+
let proc = yield* x("deno", ["run", "test/main/ok.daemon.ts"]);
3332

34-
daemon.kill("SIGTERM");
33+
yield* detect(proc.lines, "started");
3534

36-
let status = yield* daemon.status;
35+
const { exitCode, stdout } = yield* proc.kill("SIGTERM");
3736

38-
expect(status.code).toBe(143);
37+
expect(stdout).toContain("gracefully stopped");
3938

40-
yield* detect(stdout, "gracefully stopped");
39+
expect(exitCode).toBe(143);
4140
});
4241
});
4342
}
4443

4544
it("exits gracefully on explicit exit()", async () => {
4645
await run(function* () {
47-
let cmd = yield* useCommand("deno", {
48-
stdout: "piped",
49-
args: ["run", "--allow-env", "test/main/ok.exit.ts"],
50-
});
46+
let proc = yield* x("deno", ["run", "test/main/ok.exit.ts"]);
5147

52-
let stdout = yield* buffer(cmd.stdout);
53-
54-
yield* detect(stdout, "goodbye.\nOk, computer.");
48+
yield* detect(proc.lines, "goodbye.");
49+
yield* detect(proc.lines, "Ok, computer.");
5550
});
5651
});
5752

5853
it("exits gracefully with 0 on implicit exit", async () => {
5954
await run(function* () {
60-
let cmd = yield* useCommand("deno", {
61-
stdout: "piped",
62-
args: ["run", "--allow-env", "test/main/ok.implicit.ts"],
63-
});
55+
let proc = yield* x("deno", ["run", "test/main/ok.implicit.ts"]);
56+
57+
yield* detect(proc.lines, "goodbye.");
6458

65-
let stdout = yield* buffer(cmd.stdout);
66-
let status = yield* cmd.status;
59+
const { exitCode } = yield* proc;
6760

68-
yield* detect(stdout, "goodbye.");
69-
expect(status.code).toEqual(0);
61+
expect(exitCode).toEqual(0);
7062
});
7163
});
7264

7365
it("exits gracefully on explicit exit failure exit()", async () => {
7466
await run(function* () {
75-
let cmd = yield* useCommand("deno", {
76-
stdout: "piped",
77-
stderr: "piped",
78-
args: ["run", "--allow-env", "test/main/fail.exit.ts"],
79-
});
80-
let stdout = yield* buffer(cmd.stdout);
81-
let stderr = yield* buffer(cmd.stderr);
82-
let status = yield* cmd.status;
67+
let proc = yield* x("deno", ["run", "test/main/fail.exit.ts"]);
68+
69+
const { stderr, exitCode, stdout } = yield* proc;
8370

84-
yield* detect(stdout, "graceful goodbye");
85-
yield* detect(stderr, "It all went horribly wrong");
86-
expect(status.code).toEqual(23);
71+
expect(stdout).toContain("graceful goodbye");
72+
expect(stderr).toContain("It all went horribly wrong");
73+
expect(exitCode).toEqual(23);
8774
});
8875
});
8976

9077
it("error exits gracefully on unexpected errors", async () => {
9178
await run(function* () {
92-
let cmd = yield* useCommand("deno", {
93-
stdout: "piped",
94-
stderr: "piped",
95-
args: ["run", "--allow-env", "test/main/fail.unexpected.ts"],
96-
});
79+
let proc = yield* x("deno", ["run", "test/main/fail.unexpected.ts"]);
9780

98-
let stdout = yield* buffer(cmd.stdout);
99-
let stderr = yield* buffer(cmd.stderr);
100-
let status = yield* cmd.status;
81+
const { stderr, stdout, exitCode } = yield* proc;
10182

102-
yield* detect(stdout, "graceful goodbye");
103-
yield* detect(stderr, "Error: moo");
104-
expect(status.code).toEqual(1);
83+
expect(stdout).toContain("graceful goodbye");
84+
expect(stderr).toContain("Error: moo");
85+
expect(exitCode).toEqual(1);
10586
});
10687
});
10788

10889
it("works even if suspend is the only operation", async () => {
10990
await run(function* () {
110-
let process = yield* useCommand("deno", {
111-
stdout: "piped",
112-
args: ["run", "--allow-env", "test/main/just.suspend.ts"],
113-
});
114-
let stdout = yield* buffer(process.stdout);
115-
yield* detect(stdout, "started");
116-
117-
process.kill("SIGINT");
91+
let proc = yield* x("deno", ["run", "test/main/just.suspend.ts"]);
11892

119-
let status = yield* process.status;
93+
yield* detect(proc.lines, "started");
12094

121-
expect(status.code).toBe(130);
95+
const { exitCode, stdout } = yield* proc.kill("SIGINT");
12296

123-
yield* detect(stdout, "gracefully stopped");
97+
expect(exitCode).toBe(130);
98+
expect(stdout).toContain("gracefully stopped");
12499
});
125100
});
126101
});

0 commit comments

Comments
 (0)