refactor(test): dedupe env setup across suites

This commit is contained in:
Peter Steinberger
2026-02-21 13:12:53 +00:00
parent f903603722
commit 7724abeee0
5 changed files with 43 additions and 122 deletions

View File

@@ -1,6 +1,7 @@
import path from "node:path";
import { Command } from "commander";
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { withEnvAsync } from "../test-utils/env.js";
const copyToClipboard = vi.fn();
const runtime = {
@@ -167,11 +168,8 @@ describe("browser extension install (fs-mocked)", () => {
});
it("copies extension path to clipboard", async () => {
const prev = process.env.OPENCLAW_STATE_DIR;
const tmp = abs("/tmp/openclaw-ext-path");
process.env.OPENCLAW_STATE_DIR = tmp;
try {
await withEnvAsync({ OPENCLAW_STATE_DIR: tmp }, async () => {
copyToClipboard.mockResolvedValue(true);
const dir = path.join(tmp, "browser", "chrome-extension");
@@ -186,12 +184,6 @@ describe("browser extension install (fs-mocked)", () => {
await program.parseAsync(["browser", "extension", "path"], { from: "user" });
expect(copyToClipboard).toHaveBeenCalledWith(dir);
} finally {
if (prev === undefined) {
delete process.env.OPENCLAW_STATE_DIR;
} else {
process.env.OPENCLAW_STATE_DIR = prev;
}
}
});
});
});