test: group remaining suite cleanups

This commit is contained in:
Peter Steinberger
2026-02-21 21:43:24 +00:00
parent 5c8f0b5a77
commit 861718e4dc
32 changed files with 870 additions and 922 deletions

View File

@@ -61,15 +61,17 @@ describe("dns cli", () => {
});
describe("parseByteSize", () => {
it("parses bytes with units", () => {
expect(parseByteSize("10kb")).toBe(10 * 1024);
expect(parseByteSize("1mb")).toBe(1024 * 1024);
expect(parseByteSize("2gb")).toBe(2 * 1024 * 1024 * 1024);
});
it("parses shorthand units", () => {
expect(parseByteSize("5k")).toBe(5 * 1024);
expect(parseByteSize("1m")).toBe(1024 * 1024);
it("parses byte-size units and shorthand values", () => {
const cases = [
["parses 10kb", "10kb", 10 * 1024],
["parses 1mb", "1mb", 1024 * 1024],
["parses 2gb", "2gb", 2 * 1024 * 1024 * 1024],
["parses shorthand 5k", "5k", 5 * 1024],
["parses shorthand 1m", "1m", 1024 * 1024],
] as const;
for (const [name, input, expected] of cases) {
expect(parseByteSize(input), name).toBe(expected);
}
});
it("uses default unit when omitted", () => {
@@ -84,27 +86,17 @@ describe("parseByteSize", () => {
});
describe("parseDurationMs", () => {
it("parses bare ms", () => {
expect(parseDurationMs("10000")).toBe(10_000);
});
it("parses seconds suffix", () => {
expect(parseDurationMs("10s")).toBe(10_000);
});
it("parses minutes suffix", () => {
expect(parseDurationMs("1m")).toBe(60_000);
});
it("parses hours suffix", () => {
expect(parseDurationMs("2h")).toBe(7_200_000);
});
it("parses days suffix", () => {
expect(parseDurationMs("2d")).toBe(172_800_000);
});
it("supports decimals", () => {
expect(parseDurationMs("0.5s")).toBe(500);
it("parses duration strings", () => {
const cases = [
["parses bare ms", "10000", 10_000],
["parses seconds suffix", "10s", 10_000],
["parses minutes suffix", "1m", 60_000],
["parses hours suffix", "2h", 7_200_000],
["parses days suffix", "2d", 172_800_000],
["supports decimals", "0.5s", 500],
] as const;
for (const [name, input, expected] of cases) {
expect(parseDurationMs(input), name).toBe(expected);
}
});
});

View File

@@ -1,5 +1,5 @@
import { Command } from "commander";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import type { ConfigFileSnapshot, OpenClawConfig } from "../config/types.js";
/**
@@ -53,8 +53,9 @@ function setSnapshot(resolved: OpenClawConfig, config: OpenClawConfig) {
mockReadConfigFileSnapshot.mockResolvedValueOnce(buildSnapshot({ resolved, config }));
}
let registerConfigCli: typeof import("./config-cli.js").registerConfigCli;
async function runConfigCommand(args: string[]) {
const { registerConfigCli } = await import("./config-cli.js");
const program = new Command();
program.exitOverride();
registerConfigCli(program);
@@ -62,6 +63,10 @@ async function runConfigCommand(args: string[]) {
}
describe("config cli", () => {
beforeAll(async () => {
({ registerConfigCli } = await import("./config-cli.js"));
});
beforeEach(() => {
vi.clearAllMocks();
});
@@ -166,7 +171,6 @@ describe("config cli", () => {
});
it("shows --strict-json and keeps --json as a legacy alias in help", async () => {
const { registerConfigCli } = await import("./config-cli.js");
const program = new Command();
registerConfigCli(program);

View File

@@ -57,7 +57,7 @@ describe("cli program (smoke)", () => {
"123e4567-e89b-12d3-a456-426614174000",
],
},
])("$label", async ({ argv }) => {
])("message command: $label", async ({ argv }) => {
await expect(runProgram(argv)).rejects.toThrow("exit");
expect(messageCommand).toHaveBeenCalled();
});
@@ -92,7 +92,7 @@ describe("cli program (smoke)", () => {
expectedTimeoutMs: undefined,
expectedWarning: 'warning: invalid --timeout-ms "nope"; ignoring',
},
])("$label", async ({ argv, expectedTimeoutMs, expectedWarning }) => {
])("tui command: $label", async ({ argv, expectedTimeoutMs, expectedWarning }) => {
await runProgram(argv);
if (expectedWarning) {
expect(runtime.error).toHaveBeenCalledWith(expectedWarning);
@@ -118,7 +118,7 @@ describe("cli program (smoke)", () => {
expectSetupCalled: false,
expectOnboardCalled: true,
},
])("$label", async ({ argv, expectSetupCalled, expectOnboardCalled }) => {
])("setup command: $label", async ({ argv, expectSetupCalled, expectOnboardCalled }) => {
await runProgram(argv);
expect(setupCommand).toHaveBeenCalledTimes(expectSetupCalled ? 1 : 0);
expect(onboardCommand).toHaveBeenCalledTimes(expectOnboardCalled ? 1 : 0);
@@ -248,7 +248,7 @@ describe("cli program (smoke)", () => {
runtime,
),
},
])("$label", async ({ argv, expectCall }) => {
])("channels command: $label", async ({ argv, expectCall }) => {
await runProgram(argv);
expectCall();
});