Skip to content

Commit 402ebe2

Browse files
committed
fix(tests): stabilize shell mocks across bun test suite
1 parent d305e2d commit 402ebe2

3 files changed

Lines changed: 23 additions & 25 deletions

File tree

tests/global-command.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ mock.module("../src/lib/shell.ts", () => ({
4343
runCalls.push([...cmd]);
4444
return 0;
4545
},
46-
findExecutableInPath: async (name?: string) =>
46+
findExecutableInPath: (name?: string) =>
4747
name === "hack" ? "/usr/local/bin/hack" : "/usr/bin/mkcert",
48+
CommandError: class CommandError extends Error {},
4849
}));
4950

5051
mock.module("../src/lib/os.ts", () => ({

tests/log-backend.test.ts

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
import { beforeEach, expect, mock, test } from "bun:test";
22

3-
const runCalls: string[][] = [];
43
const dockerJsonCalls: Record<string, unknown>[] = [];
4+
const dockerPlainCalls: Record<string, unknown>[] = [];
55
const dockerPrettyCalls: Record<string, unknown>[] = [];
66
const lokiCalls: Record<string, unknown>[] = [];
77

8-
mock.module("../src/lib/shell.ts", () => ({
9-
run: async (cmd: readonly string[]) => {
10-
runCalls.push([...cmd]);
11-
return 0;
12-
},
13-
}));
14-
158
mock.module("../src/ui/docker-logs.ts", () => ({
169
dockerComposeLogsJson: async (opts: Record<string, unknown>) => {
1710
dockerJsonCalls.push(opts);
1811
return 0;
1912
},
13+
dockerComposeLogsPlain: async (opts: Record<string, unknown>) => {
14+
dockerPlainCalls.push(opts);
15+
return 0;
16+
},
2017
dockerComposeLogsPretty: async (opts: Record<string, unknown>) => {
2118
dockerPrettyCalls.push(opts);
2219
return 0;
@@ -37,8 +34,8 @@ import {
3734
} from "../src/backends/log-backend.ts";
3835

3936
beforeEach(() => {
40-
runCalls.length = 0;
4137
dockerJsonCalls.length = 0;
38+
dockerPlainCalls.length = 0;
4239
dockerPrettyCalls.length = 0;
4340
lokiCalls.length = 0;
4441
});
@@ -81,21 +78,15 @@ test("composeLogBackend routes plain output to docker compose logs", async () =>
8178
profiles: ["ops"],
8279
});
8380

84-
expect(runCalls[0]).toEqual([
85-
"docker",
86-
"compose",
87-
"-p",
88-
"proj",
89-
"-f",
90-
"docker-compose.yml",
91-
"--profile",
92-
"ops",
93-
"logs",
94-
"-f",
95-
"--tail",
96-
"10",
97-
"api",
98-
]);
81+
expect(dockerPlainCalls.length).toBe(1);
82+
expect(dockerPlainCalls[0]).toMatchObject({
83+
composeFile: "docker-compose.yml",
84+
follow: true,
85+
tail: 10,
86+
service: "api",
87+
composeProject: "proj",
88+
profiles: ["ops"],
89+
});
9990
});
10091

10192
test("lokiLogBackend.isAvailable proxies canReachLoki", async () => {

tests/runtime-backend.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@ mock.module("../src/lib/shell.ts", () => ({
88
execCalls.push([...cmd]);
99
return { exitCode: 0, stdout: "", stderr: "" };
1010
},
11+
execOrThrow: async (cmd: readonly string[]) => {
12+
execCalls.push([...cmd]);
13+
return { exitCode: 0, stdout: "", stderr: "" };
14+
},
1115
run: async (cmd: readonly string[]) => {
1216
runCalls.push([...cmd]);
1317
return 0;
1418
},
19+
findExecutableInPath: () => "/usr/bin/docker",
20+
CommandError: class CommandError extends Error {},
1521
}));
1622

1723
import { composeRuntimeBackend } from "../src/backends/runtime-backend.ts";

0 commit comments

Comments
 (0)