-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathindex.spec.js
74 lines (55 loc) · 2.35 KB
/
index.spec.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
describe("GIVEN pixi-shim", () => {
function createImage() {
const bunny =
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAlCAYAAABcZvm2AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAWNJREFUeNrsV8sNwjAMbUqBBWACxB2pQ8AKcGALTsAJuDEFB1gBhuDAuWICmICPQh01pXWdJqEFcaglRGRbfonjPLuMc+5QwhjLGEJfZusjxZOL9akZKye9G98vPMfvsAx4qBfKwfzBL9s6uUHpI6U/u7+BKGkNb/H6umtk7MczF0HyfKS4zo/k/4AgTV8DOizrqX8oECgC+MGa8lGJp9sJDiAB8nyqYoglvJOPbP97IqoATGxWVZeXJlMQwYHA3piF8wJIblOVNBBxe3TPMLoHIKtxrbS7AAbBrA4Y5NaPAXf8LjN6wKZ0RaZOnlAFZnuXInVR4FTE6eYp0olPhhshtXsAwY3PquoAJNkIY33U7HTs7hYBwV24ItUKqDwgKF3VzAZ6k8HF+B1BMF8xRJbeJoqMXHZAAQ1kwoluURCdzepEugGEImBrIADB7I4lyfbJLlw92FKE6b5hVd+ktv4vAQYASMWxvlAAvcsAAAAASUVORK5CYII=";
const image = document.createElement("img");
image.src = bunny;
return image;
}
it("THEN requiring it doesnt throw error", () => {
const req = () => require(".");
expect(req).not.toThrow();
});
it("THEN new PIXI.Application doesnt throw error", () => {
const PIXI = require(".");
const app = () => new PIXI.Application({ preserveDrawingBuffer: true });
expect(app).not.toThrow();
});
it("THEN new PIXI.Sprite from base64 image does *not* work", () => {
const PIXI = require(".");
const image = createImage();
const sprite = PIXI.Sprite.from(image.src);
const { width, height } = sprite;
expect(image).toBeTruthy();
expect(sprite).toBeTruthy();
expect(width).toBe(0);
expect(height).toBe(0);
});
it("THEN toDataURL does *not* yet work", () => {
const PIXI = require(".");
const app = new PIXI.Application({ preserveDrawingBuffer: true });
const image = createImage();
const sprite = PIXI.Sprite.from(image.src);
app.stage.addChild(sprite);
app.render();
const base64 = app.view.toDataURL("image/png", 1);
expect(base64).toBeFalsy();
});
it("THEN normal PIXI gameLoop works", (done) => {
const PIXI = require(".");
const app = new PIXI.Application({ preserveDrawingBuffer: true });
const image = createImage();
const sprite = PIXI.Sprite.from(image.src);
app.stage.addChild(sprite);
app.render();
requestAnimationFrame(gameLoop);
function gameLoop() {
sprite.x += 1000 / 60;
requestAnimationFrame(gameLoop);
}
setTimeout(() => {
expect(sprite.x).toBeGreaterThan(0);
done();
}, 1000);
});
});