mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
test: replace ui prototype method patches with instance stubs
This commit is contained in:
@@ -73,6 +73,7 @@
|
|||||||
- Never add `@ts-nocheck` and do not disable `no-explicit-any`; fix root causes and update Oxlint/Oxfmt config only when required.
|
- Never add `@ts-nocheck` and do not disable `no-explicit-any`; fix root causes and update Oxlint/Oxfmt config only when required.
|
||||||
- Never share class behavior via prototype mutation (`applyPrototypeMixins`, `Object.defineProperty` on `.prototype`, or exporting `Class.prototype` for merges). Use explicit inheritance/composition (`A extends B extends C`) or helper composition so TypeScript can typecheck.
|
- Never share class behavior via prototype mutation (`applyPrototypeMixins`, `Object.defineProperty` on `.prototype`, or exporting `Class.prototype` for merges). Use explicit inheritance/composition (`A extends B extends C`) or helper composition so TypeScript can typecheck.
|
||||||
- If this pattern is needed, stop and get explicit approval before shipping; default behavior is to split/refactor into an explicit class hierarchy and keep members strongly typed.
|
- If this pattern is needed, stop and get explicit approval before shipping; default behavior is to split/refactor into an explicit class hierarchy and keep members strongly typed.
|
||||||
|
- In tests, prefer per-instance stubs over prototype mutation (`SomeClass.prototype.method = ...`) unless a test explicitly documents why prototype-level patching is required.
|
||||||
- Add brief code comments for tricky or non-obvious logic.
|
- Add brief code comments for tricky or non-obvious logic.
|
||||||
- Keep files concise; extract helpers instead of “V2” copies. Use existing patterns for CLI options and dependency injection via `createDefaultDeps`.
|
- Keep files concise; extract helpers instead of “V2” copies. Use existing patterns for CLI options and dependency injection via `createDefaultDeps`.
|
||||||
- Aim to keep files under ~700 LOC; guideline only (not a hard guardrail). Split/refactor when it improves clarity or testability.
|
- Aim to keep files under ~700 LOC; guideline only (not a hard guardrail). Split/refactor when it improves clarity or testability.
|
||||||
|
|||||||
@@ -1,15 +1,11 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
import { OpenClawApp } from "./app.ts";
|
|
||||||
import "../styles.css";
|
import "../styles.css";
|
||||||
|
import { mountApp as mountTestApp, registerAppMountHooks } from "./test-helpers/app-mount.ts";
|
||||||
|
|
||||||
// oxlint-disable-next-line typescript/unbound-method
|
registerAppMountHooks();
|
||||||
const originalConnect = OpenClawApp.prototype.connect;
|
|
||||||
|
|
||||||
function mountApp(pathname: string) {
|
function mountApp(pathname: string) {
|
||||||
window.history.replaceState({}, "", pathname);
|
return mountTestApp(pathname);
|
||||||
const app = document.createElement("openclaw-app") as OpenClawApp;
|
|
||||||
document.body.append(app);
|
|
||||||
return app;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function nextFrame() {
|
function nextFrame() {
|
||||||
@@ -18,22 +14,6 @@ function nextFrame() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
OpenClawApp.prototype.connect = () => {
|
|
||||||
// no-op: avoid real gateway WS connections in browser tests
|
|
||||||
};
|
|
||||||
window.__OPENCLAW_CONTROL_UI_BASE_PATH__ = undefined;
|
|
||||||
localStorage.clear();
|
|
||||||
document.body.innerHTML = "";
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
OpenClawApp.prototype.connect = originalConnect;
|
|
||||||
window.__OPENCLAW_CONTROL_UI_BASE_PATH__ = undefined;
|
|
||||||
localStorage.clear();
|
|
||||||
document.body.innerHTML = "";
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("control UI routing", () => {
|
describe("control UI routing", () => {
|
||||||
it("hydrates the tab from the location", async () => {
|
it("hydrates the tab from the location", async () => {
|
||||||
const app = mountApp("/sessions");
|
const app = mountApp("/sessions");
|
||||||
|
|||||||
@@ -1,28 +1,24 @@
|
|||||||
import { afterEach, beforeEach } from "vitest";
|
import { afterEach, beforeEach } from "vitest";
|
||||||
import { OpenClawApp } from "../app.ts";
|
import { OpenClawApp } from "../app.ts";
|
||||||
|
|
||||||
// oxlint-disable-next-line typescript/unbound-method
|
|
||||||
const originalConnect = OpenClawApp.prototype.connect;
|
|
||||||
|
|
||||||
export function mountApp(pathname: string) {
|
export function mountApp(pathname: string) {
|
||||||
window.history.replaceState({}, "", pathname);
|
window.history.replaceState({}, "", pathname);
|
||||||
const app = document.createElement("openclaw-app") as OpenClawApp;
|
const app = document.createElement("openclaw-app") as OpenClawApp;
|
||||||
|
app.connect = () => {
|
||||||
|
// no-op: avoid real gateway WS connections in browser tests
|
||||||
|
};
|
||||||
document.body.append(app);
|
document.body.append(app);
|
||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function registerAppMountHooks() {
|
export function registerAppMountHooks() {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
OpenClawApp.prototype.connect = () => {
|
|
||||||
// no-op: avoid real gateway WS connections in browser tests
|
|
||||||
};
|
|
||||||
window.__OPENCLAW_CONTROL_UI_BASE_PATH__ = undefined;
|
window.__OPENCLAW_CONTROL_UI_BASE_PATH__ = undefined;
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
document.body.innerHTML = "";
|
document.body.innerHTML = "";
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
OpenClawApp.prototype.connect = originalConnect;
|
|
||||||
window.__OPENCLAW_CONTROL_UI_BASE_PATH__ = undefined;
|
window.__OPENCLAW_CONTROL_UI_BASE_PATH__ = undefined;
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
document.body.innerHTML = "";
|
document.body.innerHTML = "";
|
||||||
|
|||||||
Reference in New Issue
Block a user