refactor(test): standardize env helpers across suites

This commit is contained in:
Peter Steinberger
2026-02-21 13:22:16 +00:00
parent ae70bf4dca
commit e588e3cc20
5 changed files with 177 additions and 287 deletions

View File

@@ -1,4 +1,5 @@
import { describe, expect, it } from "vitest";
import { withEnv } from "../test-utils/env.js";
import { resolveBrowserConfig, resolveProfile, shouldStartLocalBrowserServer } from "./config.js";
describe("browser config", () => {
@@ -25,9 +26,7 @@ describe("browser config", () => {
});
it("derives default ports from OPENCLAW_GATEWAY_PORT when unset", () => {
const prev = process.env.OPENCLAW_GATEWAY_PORT;
process.env.OPENCLAW_GATEWAY_PORT = "19001";
try {
withEnv({ OPENCLAW_GATEWAY_PORT: "19001" }, () => {
const resolved = resolveBrowserConfig(undefined);
expect(resolved.controlPort).toBe(19003);
const chrome = resolveProfile(resolved, "chrome");
@@ -38,19 +37,11 @@ describe("browser config", () => {
const openclaw = resolveProfile(resolved, "openclaw");
expect(openclaw?.cdpPort).toBe(19012);
expect(openclaw?.cdpUrl).toBe("http://127.0.0.1:19012");
} finally {
if (prev === undefined) {
delete process.env.OPENCLAW_GATEWAY_PORT;
} else {
process.env.OPENCLAW_GATEWAY_PORT = prev;
}
}
});
});
it("derives default ports from gateway.port when env is unset", () => {
const prev = process.env.OPENCLAW_GATEWAY_PORT;
delete process.env.OPENCLAW_GATEWAY_PORT;
try {
withEnv({ OPENCLAW_GATEWAY_PORT: undefined }, () => {
const resolved = resolveBrowserConfig(undefined, { gateway: { port: 19011 } });
expect(resolved.controlPort).toBe(19013);
const chrome = resolveProfile(resolved, "chrome");
@@ -61,13 +52,7 @@ describe("browser config", () => {
const openclaw = resolveProfile(resolved, "openclaw");
expect(openclaw?.cdpPort).toBe(19022);
expect(openclaw?.cdpUrl).toBe("http://127.0.0.1:19022");
} finally {
if (prev === undefined) {
delete process.env.OPENCLAW_GATEWAY_PORT;
} else {
process.env.OPENCLAW_GATEWAY_PORT = prev;
}
}
});
});
it("normalizes hex colors", () => {