mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-01 15:37:32 +08:00
Fix BroadcastChannel errors in vitest
Added mock for BroadcastChannel in vitest setup to resolve type mismatch between Node.js and browser implementations. Pinia uses BroadcastChannel for state synchronization, which was causing unhandled exceptions during test runs. The mock extends EventTarget and provides no-op implementations for postMessage and close methods.
This commit is contained in:
@@ -63,6 +63,31 @@ if (typeof HTMLDialogElement !== "undefined") {
|
||||
HTMLDialogElement.prototype.close = HTMLDialogElement.prototype.close || vi.fn();
|
||||
}
|
||||
|
||||
// Mock BroadcastChannel to fix Pinia state synchronization errors
|
||||
// Node.js's BroadcastChannel has a type mismatch with the browser API
|
||||
class MockBroadcastChannel extends EventTarget {
|
||||
name: string;
|
||||
|
||||
constructor(name: string) {
|
||||
super();
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
postMessage() {
|
||||
// No-op for tests
|
||||
}
|
||||
|
||||
close() {
|
||||
// No-op for tests
|
||||
}
|
||||
}
|
||||
|
||||
Object.defineProperty(global, "BroadcastChannel", {
|
||||
writable: true,
|
||||
configurable: true,
|
||||
value: MockBroadcastChannel,
|
||||
});
|
||||
|
||||
// Import and setup MSW if needed
|
||||
// This will be uncommented when tests using MSW are migrated
|
||||
// import { setupServer } from "msw/node";
|
||||
|
||||
Reference in New Issue
Block a user