refactor(test): snapshot tailscale test env per case

This commit is contained in:
Peter Steinberger
2026-02-21 18:36:09 +00:00
parent 2a0ea7cb97
commit 1b585b2959

View File

@@ -1,4 +1,5 @@
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 * as tailscale from "./tailscale.js"; import * as tailscale from "./tailscale.js";
const { const {
@@ -12,18 +13,15 @@ const {
const tailscaleBin = expect.stringMatching(/tailscale$/i); const tailscaleBin = expect.stringMatching(/tailscale$/i);
describe("tailscale helpers", () => { describe("tailscale helpers", () => {
const originalForcedBinary = process.env.OPENCLAW_TEST_TAILSCALE_BINARY; let envSnapshot: ReturnType<typeof captureEnv>;
beforeEach(() => { beforeEach(() => {
envSnapshot = captureEnv(["OPENCLAW_TEST_TAILSCALE_BINARY"]);
process.env.OPENCLAW_TEST_TAILSCALE_BINARY = "tailscale"; process.env.OPENCLAW_TEST_TAILSCALE_BINARY = "tailscale";
}); });
afterEach(() => { afterEach(() => {
if (originalForcedBinary === undefined) { envSnapshot.restore();
delete process.env.OPENCLAW_TEST_TAILSCALE_BINARY;
} else {
process.env.OPENCLAW_TEST_TAILSCALE_BINARY = originalForcedBinary;
}
vi.restoreAllMocks(); vi.restoreAllMocks();
}); });