refactor(test): reuse env snapshots in unit suites

This commit is contained in:
Peter Steinberger
2026-02-16 00:02:32 +00:00
parent 07dea4c6cc
commit ee2fa5f411
4 changed files with 13 additions and 37 deletions

View File

@@ -1,4 +1,5 @@
import { describe, expect, it } from "vitest";
import { captureEnv } from "../test-utils/env.js";
import { runCommandWithTimeout, shouldSpawnWithShell } from "./exec.js";
describe("runCommandWithTimeout", () => {
@@ -25,7 +26,7 @@ describe("runCommandWithTimeout", () => {
});
it("merges custom env with process.env", async () => {
const previous = process.env.OPENCLAW_BASE_ENV;
const envSnapshot = captureEnv(["OPENCLAW_BASE_ENV"]);
process.env.OPENCLAW_BASE_ENV = "base";
try {
const result = await runCommandWithTimeout(
@@ -43,11 +44,7 @@ describe("runCommandWithTimeout", () => {
expect(result.code).toBe(0);
expect(result.stdout).toBe("base|ok");
} finally {
if (previous === undefined) {
delete process.env.OPENCLAW_BASE_ENV;
} else {
process.env.OPENCLAW_BASE_ENV = previous;
}
envSnapshot.restore();
}
});
});