mirror of
https://github.com/coder/coder.git
synced 2026-06-06 14:38:23 +00:00
30 lines
1.0 KiB
TypeScript
30 lines
1.0 KiB
TypeScript
import { Blob as NativeBlob } from "node:buffer";
|
|
import ResizeObserver from "resize-observer-polyfill";
|
|
|
|
// JSDom `Blob` is missing important methods[1] that have been standardized for
|
|
// years. MDN categorizes this API as baseline[2].
|
|
// [1]: https://github.com/jsdom/jsdom/issues/2555
|
|
// [2]: https://developer.mozilla.org/en-US/docs/Web/API/Blob/arrayBuffer
|
|
// @ts-expect-error - Minor type incompatibilities due to TypeScript's
|
|
// introduction of the `ArrayBufferLife` type and the related generic parameters
|
|
// changes.
|
|
globalThis.Blob = NativeBlob;
|
|
|
|
globalThis.ResizeObserver = ResizeObserver;
|
|
|
|
// JSDOM does not implement window.matchMedia. Monaco editor (and other
|
|
// libraries) rely on it for dark/light theme detection.
|
|
if (typeof globalThis.matchMedia !== "function") {
|
|
globalThis.matchMedia = (query: string) =>
|
|
({
|
|
matches: false,
|
|
media: query,
|
|
onchange: null,
|
|
addListener: vi.fn(),
|
|
removeListener: vi.fn(),
|
|
addEventListener: vi.fn(),
|
|
removeEventListener: vi.fn(),
|
|
dispatchEvent: vi.fn(),
|
|
}) as MediaQueryList;
|
|
}
|