Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/core/globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ global. This same interface is also exposed if requiring with CommonJS

## Requiring `AFRAME` in a Node.js Environment

It is possible to run A-Frame in [Node.js](https://nodejs.org/en/about) to get access to its globals. The only catch is we need to supply a browser `window` mock since Node.js lacks a `window` object. A-Frame is tested with [jsdom](https://github.com/tmpvar/jsdom), although any JavaScript-based browser implementation should work.
It is possible to run A-Frame in [Node.js](https://nodejs.org/en/about) to get access to its globals. The only catch is we need to supply a browser `window` mock since Node.js lacks a `window` object. A-Frame is tested with [jsdom](https://github.com/jsdom/jsdom), although any JavaScript-based browser implementation should work.

```js
global.window = require('jsdom').jsdom().defaultView;
const jsdom = require("jsdom");
global.window = new jsdom.JSDOM().window;
var aframe = require('aframe/src');
console.log(aframe.version);
```
Expand Down
33 changes: 16 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
"browserify": "^13.1.0",
"browserify-css": "^0.8.4",
"browserify-derequire": "^0.9.4",
"browserify-istanbul": "^2.0.0",
"browserify-istanbul": "^3.0.1",
"budo": "^9.2.0",
"chai": "^3.5.0",
"chai": "^4.3.6",
"chai-shallow-deep-equal": "^1.4.0",
"chalk": "^1.1.3",
"codecov": "^1.0.1",
Expand All @@ -66,35 +66,34 @@
"exorcist": "^0.4.0",
"ghpages": "0.0.8",
"git-rev": "^0.2.1",
"glob": "^7.1.1",
"glob": "^8.0.3",
"husky": "^0.11.7",
"istanbul": "^0.4.5",
"jsdom": "^9.11.0",
"karma": "1.4.1",
"karma-browserify": "^5.1.0",
"jsdom": "^20.0.0",
"karma": "^6.4.0",
"karma-browserify": "^8.1.0",
"karma-chai-shallow-deep-equal": "0.0.4",
"karma-chrome-launcher": "^2.0.0",
"karma-coverage": "^1.1.1",
"karma-chrome-launcher": "^3.1.1",
"karma-coverage": "^2.2.0",
"karma-env-preprocessor": "^0.1.1",
"karma-firefox-launcher": "^1.2.0",
"karma-mocha": "^1.1.1",
"karma-mocha-reporter": "^2.1.0",
"karma-sinon-chai": "1.2.4",
"lolex": "^1.5.1",
"karma-firefox-launcher": "^2.1.2",
"karma-mocha": "^2.0.1",
"karma-mocha-reporter": "^2.2.5",
"karma-sinon-chai": "^2.0.2",
"markserv": "github:sukima/markserv#feature/fix-broken-websoketio-link",
"minifyify": "^7.3.3",
"mocha": "^3.0.2",
"mocha": "^10.0.0",
"mozilla-download": "^1.1.1",
"replace-in-file": "^2.5.3",
"semistandard": "^9.0.0",
"shelljs": "^0.7.7",
"shx": "^0.2.2",
"sinon": "^1.17.5",
"sinon-chai": "2.8.0",
"sinon": "<12.0.0",
"sinon-chai": "^3.7.0",
"snazzy": "^5.0.0",
"too-wordy": "ngokevin/too-wordy",
"uglifyjs": "^2.4.10",
"write-good": "^0.9.1"
"write-good": "^1.0.8"
},
"link": true,
"browserify": {
Expand Down
2 changes: 1 addition & 1 deletion tests/__init.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var AScene = require('core/scene/a-scene').AScene;
AScene.prototype.setupRenderer = function () {};

setup(function () {
this.sinon = sinon.sandbox.create();
this.sinon = sinon.createSandbox();
// Stubs to not create a WebGL context since Travis CI runs headless.
this.sinon.stub(AScene.prototype, 'render');
this.sinon.stub(AScene.prototype, 'setupRenderer');
Expand Down
4 changes: 2 additions & 2 deletions tests/components/cursor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ suite('cursor', function () {
var nearerIntersectedEl = document.createElement('a-entity');
var furtherIntersectedEl = document.createElement('a-entity');

this.sinon.stub(el.components.raycaster, 'getIntersection', function (el) {
this.sinon.replace(el.components.raycaster, 'getIntersection', function (el) {
switch (el) {
case intersectedEl: return intersection1;
case nearerIntersectedEl: return intersection2;
Expand Down Expand Up @@ -279,7 +279,7 @@ suite('cursor', function () {
once(prevIntersectedEl, 'mouseleave', function (evt) {
done();
});
this.sinon.stub(el.components.raycaster, 'getIntersection', function (el) {
this.sinon.replace(el.components.raycaster, 'getIntersection', function (el) {
return el === intersectedEl ? intersection : prevIntersection;
});
el.emit('raycaster-intersection', {
Expand Down
2 changes: 1 addition & 1 deletion tests/components/gltf-model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ suite('gltf-model', function () {
animations: animations
};

this.sinon.stub(THREE, 'GLTFLoader', function MockGLTFLoader () {
this.sinon.replace(THREE, 'GLTFLoader', function MockGLTFLoader () {
this.load = function (url, onLoad) {
process.nextTick(onLoad.bind(null, gltfMock));
};
Expand Down
2 changes: 1 addition & 1 deletion tests/components/material.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ suite('material', function () {

setup(function (done) {
el = entityFactory();
this.sinon = sinon.sandbox.create();
this.sinon = sinon.createSandbox();
el.setAttribute('geometry', '');
el.setAttribute('material', 'shader: flat');
if (el.hasLoaded) { done(); }
Expand Down
6 changes: 3 additions & 3 deletions tests/components/oculus-go-controls.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ suite('oculus-go-controls', function () {
// Remove the controllers and verify that everything is cleaned up correctly. We do this
// by resetting the spy methods so we are certain only the remove is called.
controllerSystem.controllers = [];
injectTrackedControlsSpy.reset();
addEventListenersSpy.reset();
removeEventListenersSpy.reset();
injectTrackedControlsSpy.resetHistory();
addEventListenersSpy.resetHistory();
removeEventListenersSpy.resetHistory();

component.checkIfControllerPresent();

Expand Down
6 changes: 3 additions & 3 deletions tests/components/oculus-touch-controls.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ suite('oculus-touch-controls', function () {
// Remove the controllers and verify that everything is cleaned up correctly. We do this
// by resetting the spy methods so we are certain only the remove is called.
controllerSystem.controllers = [];
injectTrackedControlsSpy.reset();
addEventListenersSpy.reset();
removeEventListenersSpy.reset();
injectTrackedControlsSpy.resetHistory();
addEventListenersSpy.resetHistory();
removeEventListenersSpy.resetHistory();

component.checkIfControllerPresent();

Expand Down
2 changes: 1 addition & 1 deletion tests/components/text.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ suite('text', function () {
var el;

setup(function (done) {
this.sinon.stub(Component.prototype, 'lookupFont', function (key) {
this.sinon.replace(Component.prototype, 'lookupFont', function (key) {
return {
default: '/base/tests/assets/test.fnt?foo',
mozillavr: '/base/tests/assets/test.fnt?bar',
Expand Down
8 changes: 4 additions & 4 deletions tests/core/a-entity.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ suite('a-entity', function () {

test('does not initialized non-registered component', function () {
var nativeSetAttribute = HTMLElement.prototype.setAttribute;
this.sinon.stub(el, 'setAttribute', nativeSetAttribute);
this.sinon.replace(el, 'setAttribute', nativeSetAttribute);
el.setAttribute('fake-component', 'color: #F0F;');
el.initComponent('fake-component');
assert.notOk(el.components.fakeComponent);
Expand Down Expand Up @@ -1050,8 +1050,8 @@ suite('a-entity', function () {
var materialAttribute = 'color: #F0F; transparent: true';
var nativeSetAttribute = HTMLElement.prototype.setAttribute;
var nativeGetAttribute = HTMLElement.prototype.getAttribute;
this.sinon.stub(el, 'setAttribute', nativeSetAttribute);
this.sinon.stub(el, 'getAttribute', nativeGetAttribute);
this.sinon.replace(el, 'setAttribute', nativeSetAttribute);
this.sinon.replace(el, 'getAttribute', nativeGetAttribute);
el.setAttribute('material', materialAttribute);
el.initComponent('material', '', true);
assert.equal(el.getAttribute('material'), materialAttribute);
Expand Down Expand Up @@ -1138,7 +1138,7 @@ suite('a-entity', function () {

box.setAttribute('geometry', {primitive: 'box'});
component = box.components.geometry;
removeSpy = this.sinon.stub(component, 'remove', () => {});
removeSpy = this.sinon.replace(component, 'remove', () => {});

box.removeComponent('geometry');
assert.notOk(removeSpy.called);
Expand Down
2 changes: 1 addition & 1 deletion tests/node/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const jsdom = require('jsdom');

suite('node acceptance tests', function () {
setup(function () {
let _window = global.window = jsdom.jsdom().defaultView;
let _window = global.window = new jsdom.JSDOM().window;
global.navigator = _window.navigator;
global.document = _window.document;
global.screen = {};
Expand Down