mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 02:01:36 +00:00
refactor(test): snapshot daemon cli env in coverage e2e
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { Command } from "commander";
|
import { Command } from "commander";
|
||||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
|
import { captureEnv } from "../test-utils/env.js";
|
||||||
import { createCliRuntimeCapture } from "./test-runtime-capture.js";
|
import { createCliRuntimeCapture } from "./test-runtime-capture.js";
|
||||||
|
|
||||||
const callGateway = vi.fn(async (..._args: unknown[]) => ({ ok: true }));
|
const callGateway = vi.fn(async (..._args: unknown[]) => ({ ok: true }));
|
||||||
@@ -92,14 +93,15 @@ function parseFirstJsonRuntimeLine<T>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe("daemon-cli coverage", () => {
|
describe("daemon-cli coverage", () => {
|
||||||
const originalEnv = {
|
let envSnapshot: ReturnType<typeof captureEnv>;
|
||||||
OPENCLAW_STATE_DIR: process.env.OPENCLAW_STATE_DIR,
|
|
||||||
OPENCLAW_CONFIG_PATH: process.env.OPENCLAW_CONFIG_PATH,
|
|
||||||
OPENCLAW_GATEWAY_PORT: process.env.OPENCLAW_GATEWAY_PORT,
|
|
||||||
OPENCLAW_PROFILE: process.env.OPENCLAW_PROFILE,
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
envSnapshot = captureEnv([
|
||||||
|
"OPENCLAW_STATE_DIR",
|
||||||
|
"OPENCLAW_CONFIG_PATH",
|
||||||
|
"OPENCLAW_GATEWAY_PORT",
|
||||||
|
"OPENCLAW_PROFILE",
|
||||||
|
]);
|
||||||
process.env.OPENCLAW_STATE_DIR = "/tmp/openclaw-cli-state";
|
process.env.OPENCLAW_STATE_DIR = "/tmp/openclaw-cli-state";
|
||||||
process.env.OPENCLAW_CONFIG_PATH = "/tmp/openclaw-cli-state/openclaw.json";
|
process.env.OPENCLAW_CONFIG_PATH = "/tmp/openclaw-cli-state/openclaw.json";
|
||||||
delete process.env.OPENCLAW_GATEWAY_PORT;
|
delete process.env.OPENCLAW_GATEWAY_PORT;
|
||||||
@@ -108,29 +110,7 @@ describe("daemon-cli coverage", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
if (originalEnv.OPENCLAW_STATE_DIR !== undefined) {
|
envSnapshot.restore();
|
||||||
process.env.OPENCLAW_STATE_DIR = originalEnv.OPENCLAW_STATE_DIR;
|
|
||||||
} else {
|
|
||||||
delete process.env.OPENCLAW_STATE_DIR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (originalEnv.OPENCLAW_CONFIG_PATH !== undefined) {
|
|
||||||
process.env.OPENCLAW_CONFIG_PATH = originalEnv.OPENCLAW_CONFIG_PATH;
|
|
||||||
} else {
|
|
||||||
delete process.env.OPENCLAW_CONFIG_PATH;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (originalEnv.OPENCLAW_GATEWAY_PORT !== undefined) {
|
|
||||||
process.env.OPENCLAW_GATEWAY_PORT = originalEnv.OPENCLAW_GATEWAY_PORT;
|
|
||||||
} else {
|
|
||||||
delete process.env.OPENCLAW_GATEWAY_PORT;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (originalEnv.OPENCLAW_PROFILE !== undefined) {
|
|
||||||
process.env.OPENCLAW_PROFILE = originalEnv.OPENCLAW_PROFILE;
|
|
||||||
} else {
|
|
||||||
delete process.env.OPENCLAW_PROFILE;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("probes gateway status by default", async () => {
|
it("probes gateway status by default", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user