-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathindex.ts
48 lines (39 loc) · 1.31 KB
/
index.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
declare global {
var phaserOnNodeFPS: number
}
import Canvas from 'canvas'
import jsdom from 'jsdom'
import FakeXMLHttpRequest from './fakeXMLHttpRequest'
import './fakeScreen'
const { JSDOM } = jsdom
const dom = new JSDOM(`<!DOCTYPE html><body></body>`)
const noop = () => {}
const document = dom.window.document
const window = dom.window
window.focus = () => {}
global.document = document as any
global.window = window as any
global.window.Element = undefined as any
global.navigator = { userAgent: 'node' } as any
global.Image = Canvas.Image as any
global.XMLHttpRequest = FakeXMLHttpRequest as any
global.HTMLCanvasElement = window.HTMLCanvasElement
global.HTMLVideoElement = window.HTMLVideoElement
// @ts-ignore
global.URL = URL || noop
global.URL.createObjectURL = (base64: any) => `data:image/png;base64,${base64}`
global.URL.revokeObjectURL = () => {}
// phaser on node variables
global.phaserOnNodeFPS = 60
const animationFrame = (cb: any) => {
const now = performance.now()
if (typeof cb !== 'function') return 0 // this line saves a lot of cpu
window.setTimeout(() => cb(now), 1000 / global.phaserOnNodeFPS)
return 0
}
export { animationFrame }
window.requestAnimationFrame = cb => {
return animationFrame(cb)
}
const requestAnimationFrame = window.requestAnimationFrame
export { requestAnimationFrame }