-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-jsdom.js
79 lines (77 loc) · 1.83 KB
/
setup-jsdom.js
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* eslint-disable @typescript-eslint/no-unused-vars */
// -----------------
// JSDom
// -----------------
import jsdom from 'jsdom';
const { JSDOM } = jsdom;
const { document } = new JSDOM(`
<!DOCTYPE html>
<html>
<body>
<canvas id="gameCanvas" width="650" height="650"></canvas>
</body>
</html>
`).window;
global.document = document;
global.window = document.defaultView;
// -----------------
// Mocks
// -----------------
global.Audio = class {};
global.Image = class {};
window.requestAnimationFrame = callback => {
setTimeout(callback, 0);
};
window.HTMLCanvasElement.prototype.getContext = () => {
return {
fillRect: () => {},
clearRect: () => {},
getImageData: (x = 0, y = 0, w = 0, h = 0) => ({
data: new Array(w * h * 4),
}),
setLineDash: () => {},
getLineDash: () => [],
measureText: (text = '') => ({
width: 12 * (text.length || 0),
height: 14,
}),
putImageData: () => {},
createImageData: () => [],
setTransform: () => {},
resetTransform: () => {},
drawImage: () => {},
save: () => {},
fillText: () => {},
restore: () => {},
beginPath: () => {},
moveTo: () => {},
lineTo: () => {},
closePath: () => {},
stroke: () => {},
strokeRect: () => {},
strokeText: () => {},
t2: () => {},
transform: () => {},
translate: () => {},
scale: () => {},
rotate: () => {},
arc: () => {},
arcTo: () => {},
fill: () => {},
rect: () => {},
quadraticCurveTo: () => {},
createLinearGradient: () => ({
addColorStop: () => {},
}),
createPattern: () => ({}),
createRadialGradient: () => ({
addColorStop: () => {},
}),
bezierCurveTo: () => {},
drawFocusIfNeeded: () => {},
clip: () => {},
ellipse: () => {},
isPointInPath: () => true,
isPointInStroke: () => true,
};
};