mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 23:40:45 +00:00
test(perf): reuse cli programs in coverage tests
This commit is contained in:
@@ -74,6 +74,7 @@ vi.mock("./progress.js", () => ({
|
||||
}));
|
||||
|
||||
const { registerDaemonCli } = await import("./daemon-cli.js");
|
||||
let daemonProgram: Command;
|
||||
|
||||
function createDaemonProgram() {
|
||||
const program = new Command();
|
||||
@@ -83,8 +84,7 @@ function createDaemonProgram() {
|
||||
}
|
||||
|
||||
async function runDaemonCommand(args: string[]) {
|
||||
const program = createDaemonProgram();
|
||||
await program.parseAsync(args, { from: "user" });
|
||||
await daemonProgram.parseAsync(args, { from: "user" });
|
||||
}
|
||||
|
||||
function parseFirstJsonRuntimeLine<T>() {
|
||||
@@ -96,6 +96,7 @@ describe("daemon-cli coverage", () => {
|
||||
let envSnapshot: ReturnType<typeof captureEnv>;
|
||||
|
||||
beforeEach(() => {
|
||||
daemonProgram = createDaemonProgram();
|
||||
envSnapshot = captureEnv([
|
||||
"OPENCLAW_STATE_DIR",
|
||||
"OPENCLAW_CONFIG_PATH",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Command } from "commander";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { withEnvOverride } from "../config/test-helpers.js";
|
||||
import { createCliRuntimeCapture } from "./test-runtime-capture.js";
|
||||
|
||||
@@ -86,6 +86,7 @@ vi.mock("../commands/gateway-status.js", () => ({
|
||||
}));
|
||||
|
||||
const { registerGatewayCli } = await import("./gateway-cli.js");
|
||||
let gatewayProgram: Command;
|
||||
|
||||
function createGatewayProgram() {
|
||||
const program = new Command();
|
||||
@@ -95,8 +96,7 @@ function createGatewayProgram() {
|
||||
}
|
||||
|
||||
async function runGatewayCommand(args: string[]) {
|
||||
const program = createGatewayProgram();
|
||||
await program.parseAsync(args, { from: "user" });
|
||||
await gatewayProgram.parseAsync(args, { from: "user" });
|
||||
}
|
||||
|
||||
async function expectGatewayExit(args: string[]) {
|
||||
@@ -104,6 +104,10 @@ async function expectGatewayExit(args: string[]) {
|
||||
}
|
||||
|
||||
describe("gateway-cli coverage", () => {
|
||||
beforeEach(() => {
|
||||
gatewayProgram = createGatewayProgram();
|
||||
});
|
||||
|
||||
it("registers call/health commands and routes to callGateway", async () => {
|
||||
resetRuntimeCapture();
|
||||
callGateway.mockClear();
|
||||
|
||||
Reference in New Issue
Block a user