-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest.setup.ts
More file actions
62 lines (51 loc) · 1.81 KB
/
test.setup.ts
File metadata and controls
62 lines (51 loc) · 1.81 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// test/global-setup.ts
class MockOffscreenCanvas {
width: number;
height: number;
constructor (width: number, height: number)
{
this.width = width;
this.height = height;
}
getContext () {
// CanvasRenderingContext2D などをモック
return {
// 必要に応じてメソッドを追加
"fillRect": (x: number, y: number, w: number, h: number) => {},
"beginPath": () => {},
"moveTo": (x: number, y: number) => {},
"lineTo": (x: number, y: number) => {},
"quadraticCurveTo": (cpx: number, cpy: number, x: number, y: number) => {},
"closePath": () => {},
"isPointInPath": (x: number, y: number) => false
};
}
}
if (typeof globalThis.OffscreenCanvas === "undefined") {
(globalThis as any).OffscreenCanvas = MockOffscreenCanvas;
}
class MockWorker {
onmessage: ((event: MessageEvent) => void) | null = null;
onerror: ((event: ErrorEvent) => void) | null = null;
constructor(scriptURL: string | URL, options?: WorkerOptions) {
// Mock worker that does nothing
}
postMessage(message: any, transfer?: Transferable[]): void {
// Mock implementation
}
terminate(): void {
// Mock implementation
}
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void {
// Mock implementation
}
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void {
// Mock implementation
}
dispatchEvent(event: Event): boolean {
return true;
}
}
if (typeof globalThis.Worker === "undefined") {
(globalThis as any).Worker = MockWorker;
}