refactor(test): reuse env snapshots in unit suites
This commit is contained in:
@@ -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();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user