mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 06:32:43 +00:00
perf(test): fold browser server-context helper into utils suite
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
import { describe, expect, it, vi } from "vitest";
|
import { describe, expect, it, vi } from "vitest";
|
||||||
|
import type { BrowserServerState } from "./server-context.js";
|
||||||
import { appendCdpPath, getHeadersWithAuth } from "./cdp.helpers.js";
|
import { appendCdpPath, getHeadersWithAuth } from "./cdp.helpers.js";
|
||||||
import { __test } from "./client-fetch.js";
|
import { __test } from "./client-fetch.js";
|
||||||
|
import { resolveBrowserConfig, resolveProfile } from "./config.js";
|
||||||
import { shouldRejectBrowserMutation } from "./csrf.js";
|
import { shouldRejectBrowserMutation } from "./csrf.js";
|
||||||
import { toBoolean } from "./routes/utils.js";
|
import { toBoolean } from "./routes/utils.js";
|
||||||
|
import { listKnownProfileNames } from "./server-context.js";
|
||||||
import { resolveTargetIdFromTabs } from "./target-id.js";
|
import { resolveTargetIdFromTabs } from "./target-id.js";
|
||||||
|
|
||||||
describe("toBoolean", () => {
|
describe("toBoolean", () => {
|
||||||
@@ -176,3 +179,39 @@ describe("fetchBrowserJson loopback auth (bridge auth registry)", () => {
|
|||||||
expect(getBridgeAuthForPort).toHaveBeenCalledWith(port);
|
expect(getBridgeAuthForPort).toHaveBeenCalledWith(port);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("browser server-context listKnownProfileNames", () => {
|
||||||
|
it("includes configured and runtime-only profile names", () => {
|
||||||
|
const resolved = resolveBrowserConfig({
|
||||||
|
defaultProfile: "openclaw",
|
||||||
|
profiles: {
|
||||||
|
openclaw: { cdpPort: 18800, color: "#FF4500" },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const openclaw = resolveProfile(resolved, "openclaw");
|
||||||
|
if (!openclaw) {
|
||||||
|
throw new Error("expected openclaw profile");
|
||||||
|
}
|
||||||
|
|
||||||
|
const state: BrowserServerState = {
|
||||||
|
server: null as unknown as BrowserServerState["server"],
|
||||||
|
port: 18791,
|
||||||
|
resolved,
|
||||||
|
profiles: new Map([
|
||||||
|
[
|
||||||
|
"stale-removed",
|
||||||
|
{
|
||||||
|
profile: { ...openclaw, name: "stale-removed" },
|
||||||
|
running: null,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
]),
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(listKnownProfileNames(state).toSorted()).toEqual([
|
||||||
|
"chrome",
|
||||||
|
"openclaw",
|
||||||
|
"stale-removed",
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
|
||||||
import type { BrowserServerState } from "./server-context.js";
|
|
||||||
import { resolveBrowserConfig, resolveProfile } from "./config.js";
|
|
||||||
import { listKnownProfileNames } from "./server-context.js";
|
|
||||||
|
|
||||||
describe("browser server-context listKnownProfileNames", () => {
|
|
||||||
it("includes configured and runtime-only profile names", () => {
|
|
||||||
const resolved = resolveBrowserConfig({
|
|
||||||
defaultProfile: "openclaw",
|
|
||||||
profiles: {
|
|
||||||
openclaw: { cdpPort: 18800, color: "#FF4500" },
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const openclaw = resolveProfile(resolved, "openclaw");
|
|
||||||
if (!openclaw) {
|
|
||||||
throw new Error("expected openclaw profile");
|
|
||||||
}
|
|
||||||
|
|
||||||
const state: BrowserServerState = {
|
|
||||||
server: null as unknown as BrowserServerState["server"],
|
|
||||||
port: 18791,
|
|
||||||
resolved,
|
|
||||||
profiles: new Map([
|
|
||||||
[
|
|
||||||
"stale-removed",
|
|
||||||
{
|
|
||||||
profile: { ...openclaw, name: "stale-removed" },
|
|
||||||
running: null,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
]),
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(listKnownProfileNames(state).toSorted()).toEqual([
|
|
||||||
"chrome",
|
|
||||||
"openclaw",
|
|
||||||
"stale-removed",
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user