mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 05:20:43 +00:00
perf: slim browser tab tests
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { withFetchPreconnect } from "../../test-support.js";
|
||||
import { withBrowserFetchPreconnect } from "../../test-fetch.js";
|
||||
import * as cdpModule from "./cdp.js";
|
||||
import { BrowserCdpEndpointBlockedError } from "./errors.js";
|
||||
import { createBrowserRouteContext } from "./server-context.js";
|
||||
@@ -33,7 +33,7 @@ describe("browser server-context loopback direct WebSocket profiles", () => {
|
||||
} as unknown as Response;
|
||||
});
|
||||
|
||||
global.fetch = withFetchPreconnect(fetchMock);
|
||||
global.fetch = withBrowserFetchPreconnect(fetchMock);
|
||||
const state = makeState("openclaw");
|
||||
state.resolved.ssrfPolicy = {};
|
||||
state.resolved.profiles.openclaw = {
|
||||
@@ -78,7 +78,7 @@ describe("browser server-context loopback direct WebSocket profiles", () => {
|
||||
throw new Error(`unexpected fetch: ${u}`);
|
||||
});
|
||||
|
||||
global.fetch = withFetchPreconnect(fetchMock);
|
||||
global.fetch = withBrowserFetchPreconnect(fetchMock);
|
||||
const state = makeState("openclaw");
|
||||
state.resolved.ssrfPolicy = {};
|
||||
state.resolved.profiles.openclaw = {
|
||||
@@ -127,7 +127,7 @@ describe("browser server-context loopback direct WebSocket profiles", () => {
|
||||
throw new Error(`unexpected fetch: ${u}`);
|
||||
});
|
||||
|
||||
global.fetch = withFetchPreconnect(fetchMock);
|
||||
global.fetch = withBrowserFetchPreconnect(fetchMock);
|
||||
const state = makeState("openclaw");
|
||||
state.resolved.profiles.openclaw = {
|
||||
cdpUrl: "wss://127.0.0.1:18800/cdp?token=abc",
|
||||
@@ -148,7 +148,7 @@ describe("browser server-context loopback direct WebSocket profiles", () => {
|
||||
throw new Error("unexpected fetch");
|
||||
});
|
||||
|
||||
global.fetch = withFetchPreconnect(fetchMock);
|
||||
global.fetch = withBrowserFetchPreconnect(fetchMock);
|
||||
const state = makeState("openclaw");
|
||||
state.resolved.ssrfPolicy = {
|
||||
dangerouslyAllowPrivateNetwork: false,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { vi } from "vitest";
|
||||
import { withFetchPreconnect } from "../../test-support.js";
|
||||
import { withBrowserFetchPreconnect } from "../../test-fetch.js";
|
||||
import type { BrowserServerState } from "./server-context.js";
|
||||
import { createBrowserRouteContext } from "./server-context.js";
|
||||
|
||||
@@ -50,7 +50,7 @@ export function makeUnexpectedFetchMock() {
|
||||
|
||||
export function createRemoteRouteHarness(fetchMock?: (url: unknown) => Promise<Response>) {
|
||||
const activeFetchMock = fetchMock ?? makeUnexpectedFetchMock();
|
||||
global.fetch = withFetchPreconnect(activeFetchMock);
|
||||
global.fetch = withBrowserFetchPreconnect(activeFetchMock);
|
||||
const state = makeState("remote");
|
||||
const ctx = createBrowserRouteContext({ getState: () => state });
|
||||
return { state, remote: ctx.forProfile("remote"), fetchMock: activeFetchMock };
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { withFetchPreconnect } from "../../test-support.js";
|
||||
import { withBrowserFetchPreconnect } from "../../test-fetch.js";
|
||||
|
||||
vi.hoisted(() => {
|
||||
vi.resetModules();
|
||||
@@ -82,7 +82,7 @@ async function openManagedTabWithRunningProfile(params: {
|
||||
fetchMock: ReturnType<typeof vi.fn>;
|
||||
url?: string;
|
||||
}) {
|
||||
global.fetch = withFetchPreconnect(params.fetchMock);
|
||||
global.fetch = withBrowserFetchPreconnect(params.fetchMock);
|
||||
const state = makeState("openclaw");
|
||||
seedRunningProfileState(state);
|
||||
const ctx = createBrowserRouteContext({ getState: () => state });
|
||||
@@ -115,7 +115,7 @@ describe("browser server-context tab selection state", () => {
|
||||
} as unknown as Response;
|
||||
});
|
||||
|
||||
global.fetch = withFetchPreconnect(fetchMock);
|
||||
global.fetch = withBrowserFetchPreconnect(fetchMock);
|
||||
const state = makeState("openclaw");
|
||||
const ctx = createBrowserRouteContext({ getState: () => state });
|
||||
const openclaw = ctx.forProfile("openclaw");
|
||||
@@ -159,7 +159,7 @@ describe("browser server-context tab selection state", () => {
|
||||
} as unknown as Response;
|
||||
});
|
||||
|
||||
global.fetch = withFetchPreconnect(fetchMock);
|
||||
global.fetch = withBrowserFetchPreconnect(fetchMock);
|
||||
const state = makeState("openclaw");
|
||||
state.resolved.ssrfPolicy = {};
|
||||
const ctx = createBrowserRouteContext({ getState: () => state });
|
||||
@@ -225,7 +225,7 @@ describe("browser server-context tab selection state", () => {
|
||||
throw new Error(`unexpected fetch: ${value}`);
|
||||
});
|
||||
|
||||
global.fetch = withFetchPreconnect(fetchMock);
|
||||
global.fetch = withBrowserFetchPreconnect(fetchMock);
|
||||
const state = makeState("openclaw");
|
||||
seedRunningProfileState(state);
|
||||
const ctx = createBrowserRouteContext({ getState: () => state });
|
||||
@@ -245,7 +245,7 @@ describe("browser server-context tab selection state", () => {
|
||||
},
|
||||
});
|
||||
|
||||
global.fetch = withFetchPreconnect(fetchMock);
|
||||
global.fetch = withBrowserFetchPreconnect(fetchMock);
|
||||
const state = makeState("openclaw");
|
||||
state.resolved.attachOnly = true;
|
||||
const ctx = createBrowserRouteContext({ getState: () => state });
|
||||
@@ -287,7 +287,7 @@ describe("browser server-context tab selection state", () => {
|
||||
throw new Error("unexpected fetch");
|
||||
});
|
||||
|
||||
global.fetch = withFetchPreconnect(fetchMock);
|
||||
global.fetch = withBrowserFetchPreconnect(fetchMock);
|
||||
const state = makeState("openclaw");
|
||||
const ctx = createBrowserRouteContext({ getState: () => state });
|
||||
const openclaw = ctx.forProfile("openclaw");
|
||||
|
||||
22
extensions/browser/test-fetch.ts
Normal file
22
extensions/browser/test-fetch.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
type FetchPreconnectOptions = {
|
||||
dns?: boolean;
|
||||
tcp?: boolean;
|
||||
http?: boolean;
|
||||
https?: boolean;
|
||||
};
|
||||
|
||||
type FetchWithPreconnect = {
|
||||
preconnect: (url: string | URL, options?: FetchPreconnectOptions) => void;
|
||||
__openclawAcceptsDispatcher: true;
|
||||
};
|
||||
|
||||
export function withBrowserFetchPreconnect<T extends typeof fetch>(fn: T): T & FetchWithPreconnect;
|
||||
export function withBrowserFetchPreconnect<T extends object>(
|
||||
fn: T,
|
||||
): T & FetchWithPreconnect & typeof fetch;
|
||||
export function withBrowserFetchPreconnect(fn: object) {
|
||||
return Object.assign(fn, {
|
||||
preconnect: (_url: string | URL, _options?: FetchPreconnectOptions) => {},
|
||||
__openclawAcceptsDispatcher: true as const,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user