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
+60 -56
View File
@@ -7,61 +7,65 @@ import { matchesMediaQuery, resetAccessibilityPreferences } from "./a11y";
afterEach(() => { afterEach(() => {
resetAccessibilityPreferences(); resetAccessibilityPreferences();
cleanup(); if (typeof document !== "undefined") {
}); cleanup();
class ResizeObserverMock {
observe() {}
unobserve() {}
disconnect() {}
}
class PointerEventMock extends MouseEvent {
constructor(type: string, props: PointerEventInit = {}) {
super(type, props);
} }
});
if (typeof window !== "undefined" && typeof MouseEvent !== "undefined") {
class ResizeObserverMock {
observe() {}
unobserve() {}
disconnect() {}
}
class PointerEventMock extends MouseEvent {
constructor(type: string, props: PointerEventInit = {}) {
super(type, props);
}
}
Object.defineProperty(window, "matchMedia", {
writable: true,
value: vi.fn().mockImplementation((query: string) => ({
matches: matchesMediaQuery(query),
media: query,
onchange: null,
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
addListener: vi.fn(),
removeListener: vi.fn(),
dispatchEvent: vi.fn()
}))
});
Object.defineProperty(window, "ResizeObserver", {
writable: true,
value: ResizeObserverMock
});
Object.defineProperty(window, "PointerEvent", {
writable: true,
value: PointerEventMock
});
Object.defineProperty(window.HTMLElement.prototype, "scrollIntoView", {
configurable: true,
value: vi.fn()
});
Object.defineProperty(window.HTMLElement.prototype, "hasPointerCapture", {
configurable: true,
value: vi.fn(() => false)
});
Object.defineProperty(window.HTMLElement.prototype, "releasePointerCapture", {
configurable: true,
value: vi.fn()
});
Object.defineProperty(window.HTMLElement.prototype, "setPointerCapture", {
configurable: true,
value: vi.fn()
});
} }
Object.defineProperty(window, "matchMedia", {
writable: true,
value: vi.fn().mockImplementation((query: string) => ({
matches: matchesMediaQuery(query),
media: query,
onchange: null,
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
addListener: vi.fn(),
removeListener: vi.fn(),
dispatchEvent: vi.fn()
}))
});
Object.defineProperty(window, "ResizeObserver", {
writable: true,
value: ResizeObserverMock
});
Object.defineProperty(window, "PointerEvent", {
writable: true,
value: PointerEventMock
});
Object.defineProperty(window.HTMLElement.prototype, "scrollIntoView", {
configurable: true,
value: vi.fn()
});
Object.defineProperty(window.HTMLElement.prototype, "hasPointerCapture", {
configurable: true,
value: vi.fn(() => false)
});
Object.defineProperty(window.HTMLElement.prototype, "releasePointerCapture", {
configurable: true,
value: vi.fn()
});
Object.defineProperty(window.HTMLElement.prototype, "setPointerCapture", {
configurable: true,
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")]
} }