test(harness): support node-side control plane specs

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
2026-03-24 18:34:56 +08:00
parent c177fbefa4
commit 7b51090823
2 changed files with 61 additions and 57 deletions
+22 -18
View File
@@ -7,22 +7,25 @@ import { matchesMediaQuery, resetAccessibilityPreferences } from "./a11y";
afterEach(() => { afterEach(() => {
resetAccessibilityPreferences(); resetAccessibilityPreferences();
if (typeof document !== "undefined") {
cleanup(); cleanup();
}
}); });
class ResizeObserverMock { if (typeof window !== "undefined" && typeof MouseEvent !== "undefined") {
class ResizeObserverMock {
observe() {} observe() {}
unobserve() {} unobserve() {}
disconnect() {} disconnect() {}
} }
class PointerEventMock extends MouseEvent { class PointerEventMock extends MouseEvent {
constructor(type: string, props: PointerEventInit = {}) { constructor(type: string, props: PointerEventInit = {}) {
super(type, props); super(type, props);
} }
} }
Object.defineProperty(window, "matchMedia", { Object.defineProperty(window, "matchMedia", {
writable: true, writable: true,
value: vi.fn().mockImplementation((query: string) => ({ value: vi.fn().mockImplementation((query: string) => ({
matches: matchesMediaQuery(query), matches: matchesMediaQuery(query),
@@ -34,34 +37,35 @@ Object.defineProperty(window, "matchMedia", {
removeListener: vi.fn(), removeListener: vi.fn(),
dispatchEvent: vi.fn() dispatchEvent: vi.fn()
})) }))
}); });
Object.defineProperty(window, "ResizeObserver", { Object.defineProperty(window, "ResizeObserver", {
writable: true, writable: true,
value: ResizeObserverMock value: ResizeObserverMock
}); });
Object.defineProperty(window, "PointerEvent", { Object.defineProperty(window, "PointerEvent", {
writable: true, writable: true,
value: PointerEventMock value: PointerEventMock
}); });
Object.defineProperty(window.HTMLElement.prototype, "scrollIntoView", { Object.defineProperty(window.HTMLElement.prototype, "scrollIntoView", {
configurable: true, configurable: true,
value: vi.fn() value: vi.fn()
}); });
Object.defineProperty(window.HTMLElement.prototype, "hasPointerCapture", { Object.defineProperty(window.HTMLElement.prototype, "hasPointerCapture", {
configurable: true, configurable: true,
value: vi.fn(() => false) value: vi.fn(() => false)
}); });
Object.defineProperty(window.HTMLElement.prototype, "releasePointerCapture", { Object.defineProperty(window.HTMLElement.prototype, "releasePointerCapture", {
configurable: true, configurable: true,
value: vi.fn() value: vi.fn()
}); });
Object.defineProperty(window.HTMLElement.prototype, "setPointerCapture", { Object.defineProperty(window.HTMLElement.prototype, "setPointerCapture", {
configurable: true, configurable: true,
value: vi.fn() value: vi.fn()
}); });
}
+1 -1
View File
@@ -49,7 +49,7 @@ export default defineConfig({
test: { test: {
clearMocks: true, clearMocks: true,
environment: "jsdom", environment: "jsdom",
include: ["packages/ui/src/**/*.test.{ts,tsx}"], include: ["packages/ui/src/**/*.test.{ts,tsx}", "scripts/harness/**/*.test.ts"],
restoreMocks: true, restoreMocks: true,
setupFiles: [path.resolve(rootDir, "packages/ui/src/test/setup.ts")] setupFiles: [path.resolve(rootDir, "packages/ui/src/test/setup.ts")]
} }