forked from quadratichq/quadratic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setupPixiTests.ts
60 lines (57 loc) · 1.84 KB
/
setupPixiTests.ts
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
import { ImageResource, settings } from 'pixi.js';
const getContext = () => {
return {
fillRect: () => {},
clearRect: () => {},
getImageData: (x: number, y: number, w: number, h: number) => {
return {
data: new Array(w * h * 4),
};
},
putImageData: () => {},
createImageData: () => {
return [];
},
setTransform: () => {},
drawImage: () => {},
save: () => {},
fillText: () => {},
restore: () => {},
beginPath: () => {},
moveTo: () => {},
lineTo: () => {},
closePath: () => {},
stroke: () => {},
translate: () => {},
scale: () => {},
rotate: () => {},
arc: () => {},
fill: () => {},
measureText: () => {
return {
width: 0,
};
},
transform: () => {},
rect: () => {},
clip: () => {},
};
};
// this does not work perfectly yet
export const setupPixiTests = (): void => {
settings.ADAPTER = {
/** Returns a canvas object that can be used to create a webgl context. */
createCanvas: (width?: number, height?: number) => {
return { getContext, test: () => { return {} as ImageResource } } as any as HTMLCanvasElement
},
/** Returns a webgl rendering context. */
getWebGLRenderingContext: () => { return {} as typeof WebGLRenderingContext },
/** Returns a partial implementation of the browsers window.navigator */
getNavigator: () => { return { userAgent: "" } },
/** Returns the current base URL For browser environments this is either the document.baseURI or window.location.href */
getBaseUrl: () => { return "" },
fetch: (url: RequestInfo, options?: RequestInit) => {
return {} as Promise<Response>
},
};
};