/**
 * Test-only side effect: align the global `EventTarget` with jsdom's before any
 * module that `extends EventTarget` is evaluated.
 *
 * The node test runner's jsdom setup installs `globalThis.CustomEvent` from
 * jsdom but leaves `globalThis.EventTarget` as Node's native class. A class that
 * `extends EventTarget` (e.g. {@link ChatDriver}) then inherits Node's native
 * `dispatchEvent`, which rejects the jsdom `CustomEvent` instances it is handed
 * ("The 'event' argument must be an instance of Event. Received an instance of
 * CustomEvent"). Pointing `EventTarget` at jsdom's keeps the whole event family
 * in one realm.
 *
 * No-op in a real browser, where `window.EventTarget === globalThis.EventTarget`
 * already. Import this BEFORE importing anything that subclasses `EventTarget`.
 */
const jsdomWindow = (globalThis as { window?: { EventTarget?: typeof EventTarget } }).window;
if (jsdomWindow?.EventTarget && globalThis.EventTarget !== jsdomWindow.EventTarget) {
  Object.defineProperty(globalThis, 'EventTarget', {
    value: jsdomWindow.EventTarget,
    configurable: true,
    writable: true,
  });
}
