-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-setup.ts
More file actions
26 lines (23 loc) · 926 Bytes
/
test-setup.ts
File metadata and controls
26 lines (23 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { createCanvas, createImageData } from "canvas";
import "fake-indexeddb/auto";
const origCreateElem = window.document.createElement;
const interceptCreateElem = (
name: Parameters<typeof origCreateElem>[0],
options: Parameters<typeof origCreateElem>[1],
): ReturnType<typeof origCreateElem> => {
if (name === "canvas") {
return createCanvas(0, 0) as unknown as ReturnType<typeof origCreateElem>;
}
window.document.createElement = origCreateElem;
const rv = window.document.createElement(name, options);
window.document.createElement = interceptCreateElem;
return rv;
};
window.document.createElement = interceptCreateElem;
class ImageData {
constructor(data: Uint8ClampedArray, width: number, height: number) {
return createImageData(data, width, height);
}
}
// @ts-ignore - TS2339: Property 'ImageData' does not exist on type 'Window & typeof globalThis'.
window.ImageData = ImageData;