From 3db7d19815d24241bbe60c9afbb8b3f60d000550 Mon Sep 17 00:00:00 2001 From: Ben Beltran Date: Thu, 28 Jan 2016 21:50:30 -0600 Subject: Moves tests, recycles integration --- test/browser.html | 12 ++++ test/integration.js | 163 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100644 test/browser.html create mode 100644 test/integration.js (limited to 'test') diff --git a/test/browser.html b/test/browser.html new file mode 100644 index 0000000..7191160 --- /dev/null +++ b/test/browser.html @@ -0,0 +1,12 @@ + + + + Serpentity Browser Test + + + + +

404 Droids Not Found

+ Look in your console... + + diff --git a/test/integration.js b/test/integration.js new file mode 100644 index 0000000..0ca7e26 --- /dev/null +++ b/test/integration.js @@ -0,0 +1,163 @@ +'use strict'; + +let test = function test (Serpentity) { + + /* eslint no-console: 0 */ + + ///////////////// + // Load the stuff + ///////////////// + console.log('\n## Loading'); + console.log('Serpentity: ' + (typeof Serpentity !== 'undefined' ? 'LOAD OK' : 'FAIL')); + console.log('Serpentity.Entity: ' + (typeof Serpentity !== 'undefined' && Serpentity.Entity ? 'LOAD OK' : 'FAIL')); + console.log('Serpentity.Component: ' + (typeof Serpentity !== 'undefined' && Serpentity.Component ? 'LOAD OK' : 'FAIL')); + console.log('Serpentity.System: ' + (typeof Serpentity !== 'undefined' && Serpentity.System ? 'LOAD OK' : 'FAIL')); + console.log('Serpentity.Node: ' + (typeof Serpentity !== 'undefined' && Serpentity.Node ? 'LOAD OK' : 'FAIL')); + console.log('Serpentity.NodeCollection: ' + (typeof Serpentity !== 'undefined' && Serpentity.NodeCollection ? 'LOAD OK' : 'FAIL')); + + ////////////////////// + // Create test classes + ////////////////////// + console.log('\n## Creating Test Classes'); + let TestSystem = class TestSystem extends Serpentity.System { + added (engine) { + this.testNodes = engine.getNodes(TestNode); + console.log('Engine is serpentity: ' + (engine instanceof Serpentity ? 'OK' : 'FAIL')); + console.log('System added callback: EXEC OK'); + } + + removed (engine) { + this.testNodes = null; + console.log('Engine is serpentity: ' + (engine instanceof Serpentity ? 'OK' : 'FAIL')); + console.log('System removed callback: EXEC OK'); + } + + update (dt) { + this.testNodes.forEach(function (node) { + console.log('Running Node: ' + (node.test.testMessage === 'test' ? 'SYSTEM OK' : 'FAIL')); + }); + console.log('dt is number: ' + (typeof dt === 'number' ? 'OK' : 'FAIL')); + console.log('System update callback: EXEC OK'); + } + }; + let testSystem = new TestSystem(); + + let LowProTestSystem = class LowProTestSystem extends Serpentity.System { + added (engine) { + this.testNodes = engine.getNodes(TestNode); + console.log('Engine is serpentity: ' + (engine instanceof Serpentity ? 'OK' : 'FAIL')); + console.log('System added callback: EXEC OK'); + } + + removed (engine) { + this.testNodes = null; + console.log('Engine is serpentity: ' + (engine instanceof Serpentity ? 'OK' : 'FAIL')); + console.log('System removed callback: EXEC OK'); + } + + update (dt) { + this.testNodes.forEach(function (node) { + console.log('Running Low Priority Node: ' + (node.test.testMessage === 'test' ? 'SYSTEM OK' : 'FAIL')); + }); + console.log('dt is number: ' + (typeof dt === 'number' ? 'OK' : 'FAIL')); + console.log('System update callback: EXEC OK'); + } + }; + let lowProTestSystem = new LowProTestSystem(); + console.log('LowProTestSystem: CREATE OK'); + + let MidProTestSystem = class MidProTestSystem extends Serpentity.System { + added (engine) { + this.testNodes = engine.getNodes(TestNode); + console.log('Engine is serpentity: ' + (engine instanceof Serpentity ? 'OK' : 'FAIL')); + console.log('System added callback: EXEC OK'); + } + + removed (engine) { + this.testNodes = null; + console.log('Engine is serpentity: ' + (engine instanceof Serpentity ? 'OK' : 'FAIL')); + console.log('System removed callback: EXEC OK'); + } + + update (dt) { + this.testNodes.forEach(function (node) { + console.log('Running Mid Priority Node: ' + (node.test.testMessage === 'test' ? 'SYSTEM OK' : 'FAIL')); + }); + console.log('dt is number: ' + (typeof dt === 'number' ? 'OK' : 'FAIL')); + console.log('System update callback: EXEC OK'); + } + }; + var midProTestSystem = new MidProTestSystem(); + console.log('MidProTestSystem: CREATE OK'); + + + let TestComponent = class TestComponent extends Serpentity.Component { + constructor (config) { + super(config); + + this.testMessage = this.testMessage || 'test'; + } + }; + console.log('TestComponent: CREATE OK'); + + let TestNode = class TestNode extends Serpentity.Node {}; + TestNode.types = { + test : TestComponent + }; + console.log('TestNode: CREATE OK'); + + console.log('\n## Adding system to the engine'); + + let engine = new Serpentity(); + console.log('engine: CREATE OK'); + + engine.addSystem(testSystem, 0); + + console.log('\n## Running update without any entities'); + engine.update(10); + + console.log('\n## Adding system to the engine and updating'); + let entity = new Serpentity.Entity(); + entity.addComponent(new TestComponent()); + engine.addEntity(entity); + engine.update(10); + + console.log('\n## Adding Low Priority System'); + engine.addSystem(lowProTestSystem, 10); + engine.update(10); + + console.log('\n## Adding Mid Priority System'); + engine.addSystem(midProTestSystem, 5); + engine.update(10); + + console.log('\n## Removing the system and readding'); + engine.removeSystem(testSystem); + engine.update(10); + engine.addSystem(testSystem, 0); + engine.update(10); + + console.log('\n## Adding a second entity'); + entity = new Serpentity.Entity(); + entity.addComponent(new TestComponent()); + engine.addEntity(entity); + engine.update(10); + + console.log('\n## Removing entity'); + engine.removeEntity(entity); + engine.update(10); + + console.log('\n## Removing system'); + engine.removeSystem(testSystem); + engine.update(10); + +}; + +if (typeof require === 'function') { + let Serpentity = require('serpentity'); + test(Serpentity); +} else { + window.addEventListener('load', function () { + test(window.Serpentity); + }); +} + -- cgit From e936d6df77f8fe351fdde3fd9be829f9bc3aae97 Mon Sep 17 00:00:00 2001 From: Ben Beltran Date: Sun, 27 Mar 2016 23:25:14 -0600 Subject: Removes additional line-end --- test/integration.js | 1 - 1 file changed, 1 deletion(-) (limited to 'test') diff --git a/test/integration.js b/test/integration.js index 0ca7e26..7d88432 100644 --- a/test/integration.js +++ b/test/integration.js @@ -160,4 +160,3 @@ if (typeof require === 'function') { test(window.Serpentity); }); } - -- cgit