test: micro-optimize slow suites and CLI command setup
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { Command } from "commander";
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { runRegisteredCli } from "../../test-utils/command-runner.js";
|
||||
import { createCliRuntimeCapture } from "../test-runtime-capture.js";
|
||||
|
||||
const callGatewayCli = vi.fn(async (_method: string, _opts: unknown, _params?: unknown) => ({
|
||||
@@ -113,9 +112,13 @@ vi.mock("./discover.js", () => ({
|
||||
|
||||
describe("gateway register option collisions", () => {
|
||||
let registerGatewayCli: typeof import("./register.js").registerGatewayCli;
|
||||
let sharedProgram: Command;
|
||||
|
||||
beforeAll(async () => {
|
||||
({ registerGatewayCli } = await import("./register.js"));
|
||||
sharedProgram = new Command();
|
||||
sharedProgram.exitOverride();
|
||||
registerGatewayCli(sharedProgram);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -125,9 +128,8 @@ describe("gateway register option collisions", () => {
|
||||
});
|
||||
|
||||
it("forwards --token to gateway call when parent and child option names collide", async () => {
|
||||
await runRegisteredCli({
|
||||
register: registerGatewayCli as (program: Command) => void,
|
||||
argv: ["gateway", "call", "health", "--token", "tok_call", "--json"],
|
||||
await sharedProgram.parseAsync(["gateway", "call", "health", "--token", "tok_call", "--json"], {
|
||||
from: "user",
|
||||
});
|
||||
|
||||
expect(callGatewayCli).toHaveBeenCalledWith(
|
||||
@@ -140,9 +142,8 @@ describe("gateway register option collisions", () => {
|
||||
});
|
||||
|
||||
it("forwards --token to gateway probe when parent and child option names collide", async () => {
|
||||
await runRegisteredCli({
|
||||
register: registerGatewayCli as (program: Command) => void,
|
||||
argv: ["gateway", "probe", "--token", "tok_probe", "--json"],
|
||||
await sharedProgram.parseAsync(["gateway", "probe", "--token", "tok_probe", "--json"], {
|
||||
from: "user",
|
||||
});
|
||||
|
||||
expect(gatewayStatusCommand).toHaveBeenCalledWith(
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Command } from "commander";
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { runRegisteredCli } from "../../test-utils/command-runner.js";
|
||||
import { createCliRuntimeCapture } from "../test-runtime-capture.js";
|
||||
|
||||
const startGatewayServer = vi.fn(async (_port: number, _opts?: unknown) => ({
|
||||
@@ -93,9 +92,14 @@ vi.mock("./run-loop.js", () => ({
|
||||
|
||||
describe("gateway run option collisions", () => {
|
||||
let addGatewayRunCommand: typeof import("./run.js").addGatewayRunCommand;
|
||||
let sharedProgram: Command;
|
||||
|
||||
beforeAll(async () => {
|
||||
({ addGatewayRunCommand } = await import("./run.js"));
|
||||
sharedProgram = new Command();
|
||||
sharedProgram.exitOverride();
|
||||
const gateway = addGatewayRunCommand(sharedProgram.command("gateway"));
|
||||
addGatewayRunCommand(gateway.command("run"));
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -109,13 +113,7 @@ describe("gateway run option collisions", () => {
|
||||
});
|
||||
|
||||
async function runGatewayCli(argv: string[]) {
|
||||
await runRegisteredCli({
|
||||
register: ((program: Command) => {
|
||||
const gateway = addGatewayRunCommand(program.command("gateway"));
|
||||
addGatewayRunCommand(gateway.command("run"));
|
||||
}) as (program: Command) => void,
|
||||
argv,
|
||||
});
|
||||
await sharedProgram.parseAsync(argv, { from: "user" });
|
||||
}
|
||||
|
||||
function expectAuthOverrideMode(mode: string) {
|
||||
|
||||
Reference in New Issue
Block a user