Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a507cfa
really run all tests and fix broken tests
vincentfretin Sep 24, 2022
c5dfd55
fix sinon spy
vincentfretin Sep 26, 2022
993ad4a
fix some asynchronous tests
vincentfretin Sep 26, 2022
9ff44b8
fix camera mock
vincentfretin Sep 26, 2022
ca2df2a
use elFactory instead of deprecated entityFactory
vincentfretin Sep 26, 2022
93467da
fail test if there is an error between tests
vincentfretin Sep 26, 2022
2e78b49
properly call done() if el.hasLoaded
vincentfretin Sep 26, 2022
df45581
fix mobile test that calls screen.orientation.lock
vincentfretin Sep 26, 2022
da99fa2
fix error with requestFullscreen
vincentfretin Sep 26, 2022
8cfe27a
fix camera test
vincentfretin Sep 26, 2022
87e6936
skip one raycaster test and all a-assets test suite for now
vincentfretin Sep 26, 2022
73f05c6
skip only a-assets test related to error and timeout
vincentfretin Sep 26, 2022
35172d6
fix 4 a-assets tests by using Promise.allSettled
vincentfretin Sep 26, 2022
3875098
add a comment about the global pattern
vincentfretin Sep 26, 2022
28fdfd7
use a glob to find the folders instead of hard coding the list
vincentfretin Sep 27, 2022
94efb79
increase mocha timeout from 2s to 3s
vincentfretin Sep 27, 2022
2c6984f
avoid some TypeError setting image on null during tests
vincentfretin Sep 27, 2022
fe149ab
don't make assumption of init order in those two tests, they were pas…
vincentfretin Sep 27, 2022
8fba06f
be sure we don't have a second raycaster-intersected fired in test te…
vincentfretin Sep 27, 2022
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/components/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ module.exports.Component = registerComponent('text', {
}).then(function (image) {
// Make mesh visible and apply font image as texture.
var texture = self.texture;
// The component may have been removed at this point and texture will
// be null. This happens mainly while executing the tests,
// in this case we just return.
if (!texture) return;
texture.image = image;
texture.needsUpdate = true;
textures[data.font] = texture;
Expand Down
2 changes: 1 addition & 1 deletion src/core/a-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module.exports = registerElement('a-assets', {
}

// Trigger loaded for scene to start rendering.
Promise.all(loaded).then(bind(this.load, this));
Promise.allSettled(loaded).then(bind(this.load, this));

// Timeout to start loading anyways.
timeout = parseInt(this.getAttribute('timeout'), 10) || 3000;
Expand Down
20 changes: 20 additions & 0 deletions tests/__init.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ setup(function () {
};
});

// Ensure that uncaught exceptions between tests result in the tests failing.
// This works around an issue with mocha / karma-mocha, see
// https://github.com/karma-runner/karma-mocha/issues/227
var pendingError = null;
var pendingErrorNotice = null;

window.addEventListener('error', event => {
pendingError = event.error;
pendingErrorNotice = 'An uncaught exception was thrown between tests';
});
window.addEventListener('unhandledrejection', event => {
pendingError = event.reason;
pendingErrorNotice = 'An uncaught promise rejection occurred between tests';
});

teardown(function (done) {
// Clean up any attached elements.
var attachedEls = ['canvas', 'a-assets', 'a-scene'];
Expand All @@ -67,4 +82,9 @@ teardown(function (done) {
setTimeout(function () {
done();
});

if (pendingError) {
console.error(pendingErrorNotice);
throw pendingError;
}
});
6 changes: 4 additions & 2 deletions tests/components/daydream-controls.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ suite('daydream-controls', function () {
setup(function (done) {
var el = this.el = entityFactory();
el.setAttribute('daydream-controls', 'hand: right'); // to ensure index = 0
el.addEventListener('loaded', function () {
var callback = function () {
var component = el.components['daydream-controls'];
component.controllersWhenPresent = [{
id: 'Daydream Controller',
Expand All @@ -17,7 +17,9 @@ suite('daydream-controls', function () {
}];
el.parentEl.renderer.xr.getStandingMatrix = function () {};
done();
});
};
if (el.hasLoaded) { callback(); }
el.addEventListener('loaded', callback);
});

suite('checkIfControllerPresent', function () {
Expand Down
6 changes: 4 additions & 2 deletions tests/components/gearvr-controls.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ suite('gearvr-controls', function () {
setup(function (done) {
var el = this.el = entityFactory();
el.setAttribute('gearvr-controls', 'hand: right'); // To ensure index is 0.
el.addEventListener('loaded', function () {
var callback = function () {
var component = el.components['gearvr-controls'];
component.controllersWhenPresent = [{
id: 'Gear VR Controller',
Expand All @@ -20,7 +20,9 @@ suite('gearvr-controls', function () {
}];
el.parentEl.renderer.xr.getStandingMatrix = function () {};
done();
});
};
if (el.hasLoaded) { callback(); }
el.addEventListener('loaded', callback);
});

suite('checkIfControllerPresent', function () {
Expand Down
1 change: 1 addition & 0 deletions tests/components/geometry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ suite('geometry', function () {
setup(function (done) {
el = helpers.entityFactory();
el.setAttribute('geometry', 'buffer: false; primitive: box;');
if (el.hasLoaded) { done(); }
el.addEventListener('loaded', function () {
done();
});
Expand Down
4 changes: 3 additions & 1 deletion tests/components/gltf-model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ suite('gltf-model', function () {
asset.setAttribute('src', SRC);
el = this.el = entityFactory({assets: [asset]});
if (el.hasLoaded) { done(); }
el.addEventListener('loaded', function () { done(); });
el.addEventListener('loaded', function () {
done();
});
});

test('can load', function (done) {
Expand Down
1 change: 1 addition & 0 deletions tests/components/light.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ suite('light', function () {
setup(function (done) {
var el = this.el = entityFactory();
el.setAttribute('light', '');
if (el.hasLoaded) { done(); }
el.addEventListener('loaded', function () {
done();
});
Expand Down
4 changes: 3 additions & 1 deletion tests/components/obj-model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ suite('obj-model', function () {
objAsset.setAttribute('src', OBJ);
el = this.el = entityFactory({assets: [mtlAsset, objAsset]});
if (el.hasLoaded) { done(); }
el.addEventListener('loaded', function () { done(); });
el.addEventListener('loaded', function () {
done();
});
});

test('can load .OBJ only', function (done) {
Expand Down
6 changes: 4 additions & 2 deletions tests/components/oculus-go-controls.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ suite('oculus-go-controls', function () {
setup(function (done) {
var el = this.el = entityFactory();
el.setAttribute('oculus-go-controls', 'hand: right'); // To ensure index is 0.
el.addEventListener('loaded', function () {
var callback = function () {
var component = el.components['oculus-go-controls'];
// Initially no controllers are present
component.controllers = [];
Expand All @@ -23,7 +23,9 @@ suite('oculus-go-controls', function () {
}];
el.parentEl.renderer.xr.getStandingMatrix = function () {};
done();
});
};
if (el.hasLoaded) { callback(); }
el.addEventListener('loaded', callback);
});

suite('checkIfControllerPresent', function () {
Expand Down
6 changes: 4 additions & 2 deletions tests/components/oculus-touch-controls.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ suite('oculus-touch-controls', function () {
setup(function (done) {
el = this.el = entityFactory();
el.setAttribute('oculus-touch-controls', '');
el.addEventListener('loaded', function () {
var callback = function () {
component = el.components['oculus-touch-controls'];
// Initially no controllers are present
component.controllers = [];
Expand All @@ -20,7 +20,9 @@ suite('oculus-touch-controls', function () {
pose: {}
}];
done();
});
};
if (el.hasLoaded) { callback(); }
el.addEventListener('loaded', callback);
});

suite('checkIfControllerPresent', function () {
Expand Down
1 change: 1 addition & 0 deletions tests/components/position.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ suite('position', function () {
setup(function (done) {
var el = this.el = entityFactory();
el.setAttribute('position', '');
if (el.hasLoaded) { done(); }
el.addEventListener('loaded', function () {
done();
});
Expand Down
10 changes: 5 additions & 5 deletions tests/components/raycaster.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ suite('raycaster', function () {
assert.notEqual(component.clearedIntersectedEls.indexOf(targetEl), -1);
raycasterEl.removeEventListener('raycaster-intersection-cleared', cb);
done();
});
}, {once: true});
component.tock();
});
component.tock();
Expand All @@ -324,7 +324,7 @@ suite('raycaster', function () {
targetEl.addEventListener('raycaster-intersected-cleared', function (evt) {
assert.equal(evt.detail.el, raycasterEl);
done();
});
}, {once: true});
component.tock();
});
component.tock();
Expand All @@ -334,22 +334,22 @@ suite('raycaster', function () {
targetEl.addEventListener('raycaster-intersected', function () {
targetEl.addEventListener('raycaster-intersected-cleared', function () {
done();
});
}, {once: true});
assert.equal(component.intersectedEls.length, 2);
assert.equal(component.clearedIntersectedEls.length, 0);
el.setAttribute('raycaster', 'enabled', false);
assert.equal(component.intersectedEls.length, 0);
assert.equal(component.intersections.length, 0);
assert.equal(component.clearedIntersectedEls.length, 2);
});
}, {once: true});
component.tock();
});

test('emits intersectioncleared when disabled', function (done) {
targetEl.addEventListener('raycaster-intersected', function () {
el.addEventListener('raycaster-intersection-cleared', function () {
done();
});
}, {once: true});
el.setAttribute('raycaster', 'enabled', false);
});
component.tock();
Expand Down
1 change: 1 addition & 0 deletions tests/components/rotation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ suite('rotation', function () {
setup(function (done) {
var el = this.el = entityFactory();
el.setAttribute('rotation', '');
if (el.hasLoaded) { done(); }
el.addEventListener('loaded', function () {
done();
});
Expand Down
1 change: 1 addition & 0 deletions tests/components/scale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ suite('scale', function () {
setup(function (done) {
var el = this.el = entityFactory();
el.setAttribute('scale', '');
if (el.hasLoaded) { done(); }
el.addEventListener('loaded', function () {
done();
});
Expand Down
5 changes: 4 additions & 1 deletion tests/components/scene/vr-mode-ui.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ suite('vr-mode-ui', function () {
test('hides on enter VR', function () {
var scene = this.el;
// mock camera
scene.camera = {el: {object3D: {}}};
scene.camera = {
el: {object3D: {}},
updateProjectionMatrix: function () {}
};
scene.enterVR();
UI_CLASSES.forEach(function (uiClass) {
assert.ok(scene.querySelector(uiClass).className.indexOf('a-hidden'));
Expand Down
4 changes: 2 additions & 2 deletions tests/components/shadow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ suite('shadow component', function () {
});
el.setAttribute('shadow', {});
mesh = new THREE.Mesh(
new THREE.Sphere(2),
new THREE.SphereGeometry(2),
new THREE.MeshBasicMaterial({color: 0xffff00})
);
meshWithMaterialArray = new THREE.Mesh(
new THREE.Sphere(2),
new THREE.SphereGeometry(2),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THREE.Sphere exists but the arguments are center vec3 and radius number in latest threejs... I spend really too much time to find that the cryptic error was because of this lol. THREE.SphereGeometry first arg is radius number.

[new THREE.MeshBasicMaterial({color: 0xffff00}),
new THREE.MeshBasicMaterial({color: 0xffff00})]
);
Expand Down
8 changes: 4 additions & 4 deletions tests/components/tracked-controls.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* global assert, process, setup, suite, test */
const entityFactory = require('../helpers').entityFactory;
var elFactory = require('../helpers').elFactory;

suite('tracked-controls', function () {
var el;

setup(function (done) {
el = entityFactory();
setTimeout(() => {
el.sceneEl.addEventListener('loaded', function () { done(); });
elFactory().then(_el => {
el = _el;
done();
});
});

Expand Down
13 changes: 6 additions & 7 deletions tests/components/visible.test.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
/* global assert, process, setup, suite, test */
var entityFactory = require('../helpers').entityFactory;
var elFactory = require('../helpers').elFactory;

suite('visible', function () {
var el;

setup(function (done) {
var el = this.el = entityFactory();
el.setAttribute('visible', '');
el.addEventListener('loaded', function () {
elFactory().then(_el => {
el = _el;
el.setAttribute('visible', '');
done();
});
});

suite('update', function () {
test('treats empty as true', function () {
var el = this.el;
el.setAttribute('visible', '');
assert.ok(el.object3D.visible);
});

test('can set to visible', function () {
var el = this.el;
el.setAttribute('visible', true);
assert.ok(el.object3D.visible);
});

test('can set to not visible', function () {
var el = this.el;
el.setAttribute('visible', false);
assert.notOk(el.object3D.visible);
});
Expand Down
6 changes: 4 additions & 2 deletions tests/components/windows-motion-controls.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ suite('windows-motion-controls', function () {
setup(function (done) {
el = this.el = entityFactory();
el.setAttribute('windows-motion-controls', '');
el.addEventListener('loaded', function () {
var callback = function () {
component = el.components['windows-motion-controls'];
// Stub so we don't actually make calls to load the meshes from the remote CDN in every test.
component.loadModel = function () { };
done();
});
};
if (el.hasLoaded) { callback(); }
el.addEventListener('loaded', callback);
});

suite('checkIfControllerPresent', function () {
Expand Down
14 changes: 12 additions & 2 deletions tests/core/a-assets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,22 @@ suite('a-assets', function () {
document.body.appendChild(scene);
});

test('calls load when timing out', function (done) {
test.skip('calls load when timing out', function (done) {
// We can't really test a timeout now since we changed from
// Promise.all to Promise.allSettled in a-assets.js
// The cdnIsDown.png file that doesn't exist will just give an error
// but still loads the scene.
// We need a way to simulate a hanging request for this test...
var el = this.el;
var scene = this.scene;
var img = document.createElement('img');

el.setAttribute('timeout', 50);
img.setAttribute('src', '');
img.setAttribute('src', 'cdnIsDown.png');
el.appendChild(img);

el.addEventListener('timeout', function () {
// This timeout listener is now never executed.
el.addEventListener('loaded', function () {
assert.ok(el.hasLoaded);
done();
Expand Down Expand Up @@ -246,6 +252,10 @@ suite('a-asset-item', function () {
assetItem.setAttribute('src', 'doesntexist');
assetItem.addEventListener('error', function (evt) {
assert.ok(evt.detail.xhr !== undefined);
// ATTENTION! This evt.stopPropagation() is very important. Without it
// the test will pass but will silently reduces the number of
// tests run from 1121 to 559!
evt.stopPropagation();
done();
});
this.assetsEl.appendChild(assetItem);
Expand Down
Loading