forked from aframevr/aframe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init.test.js
More file actions
67 lines (61 loc) · 2.08 KB
/
__init.test.js
File metadata and controls
67 lines (61 loc) · 2.08 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
63
64
65
66
67
/* global AFRAME, sinon, setup, teardown */
/**
* __init.test.js is run before every test case.
*/
window.debug = true;
navigator.getVRDisplays = function () {
var resolvePromise = Promise.resolve();
var mockVRDisplay = {
cancelAnimationFrame: function (h) { return window.cancelAnimationFrame(1); },
capabilities: {},
exitPresent: resolvePromise,
getPose: function () { return { orientation: null, position: null }; },
requestAnimationFrame: function () { return 1; },
requestPresent: resolvePromise,
submitFrame: function () { return; }
};
return Promise.resolve([mockVRDisplay]);
};
require('index');
var AScene = require('core/scene/a-scene').AScene;
// Make sure WebGL context is not created since Travix CT runs headless.
// Stubs below failed once in a while due to asynchronous tesst setup / teardown.
AScene.prototype.setupRenderer = function () {};
setup(function () {
this.sinon = sinon.sandbox.create();
// Stubs to not create a WebGL context since Travis CI runs headless.
this.sinon.stub(AScene.prototype, 'render');
this.sinon.stub(AScene.prototype, 'setupRenderer');
// Mock renderer.
AScene.prototype.renderer = {
xr: {
getDevice: function () { return {requestPresent: function () {}}; },
isPresenting: function () { return true; },
setDevice: function () {},
setPoseTarget: function () {},
dispose: function () {},
enabled: false
},
getContext: function () { return undefined; },
setAnimationLoop: function () {},
setSize: function () {},
setPixelRatio: function () {},
render: function () {},
shadowMap: {enabled: false}
};
});
teardown(function (done) {
// Clean up any attached elements.
var attachedEls = ['canvas', 'a-assets', 'a-scene'];
var els = document.querySelectorAll(attachedEls.join(','));
for (var i = 0; i < els.length; i++) {
els[i].parentNode.removeChild(els[i]);
}
this.sinon.restore();
delete AFRAME.components.test;
delete AFRAME.systems.test;
// Allow detachedCallbacks to clean themselves up.
setTimeout(function () {
done();
});
});