]>
git.r.bdr.sh - rbdr/serpentity/blob - test/integration.js
7d88432bb73859c460fb2be51474cd23eee3af09
3 let test
= function test (Serpentity
) {
5 /* eslint no-console: 0 */
10 console
.log('\n## Loading');
11 console
.log('Serpentity: ' + (typeof Serpentity
!== 'undefined' ? 'LOAD OK' : 'FAIL'));
12 console
.log('Serpentity.Entity: ' + (typeof Serpentity
!== 'undefined' && Serpentity
.Entity
? 'LOAD OK' : 'FAIL'));
13 console
.log('Serpentity.Component: ' + (typeof Serpentity
!== 'undefined' && Serpentity
.Component
? 'LOAD OK' : 'FAIL'));
14 console
.log('Serpentity.System: ' + (typeof Serpentity
!== 'undefined' && Serpentity
.System
? 'LOAD OK' : 'FAIL'));
15 console
.log('Serpentity.Node: ' + (typeof Serpentity
!== 'undefined' && Serpentity
.Node
? 'LOAD OK' : 'FAIL'));
16 console
.log('Serpentity.NodeCollection: ' + (typeof Serpentity
!== 'undefined' && Serpentity
.NodeCollection
? 'LOAD OK' : 'FAIL'));
18 //////////////////////
19 // Create test classes
20 //////////////////////
21 console
.log('\n## Creating Test Classes');
22 let TestSystem
= class TestSystem
extends Serpentity
.System
{
24 this.testNodes
= engine
.getNodes(TestNode
);
25 console
.log('Engine is serpentity: ' + (engine
instanceof Serpentity
? 'OK' : 'FAIL'));
26 console
.log('System added callback: EXEC OK');
30 this.testNodes
= null;
31 console
.log('Engine is serpentity: ' + (engine
instanceof Serpentity
? 'OK' : 'FAIL'));
32 console
.log('System removed callback: EXEC OK');
36 this.testNodes
.forEach(function (node
) {
37 console
.log('Running Node: ' + (node
.test
.testMessage
=== 'test' ? 'SYSTEM OK' : 'FAIL'));
39 console
.log('dt is number: ' + (typeof dt
=== 'number' ? 'OK' : 'FAIL'));
40 console
.log('System update callback: EXEC OK');
43 let testSystem
= new TestSystem();
45 let LowProTestSystem
= class LowProTestSystem
extends Serpentity
.System
{
47 this.testNodes
= engine
.getNodes(TestNode
);
48 console
.log('Engine is serpentity: ' + (engine
instanceof Serpentity
? 'OK' : 'FAIL'));
49 console
.log('System added callback: EXEC OK');
53 this.testNodes
= null;
54 console
.log('Engine is serpentity: ' + (engine
instanceof Serpentity
? 'OK' : 'FAIL'));
55 console
.log('System removed callback: EXEC OK');
59 this.testNodes
.forEach(function (node
) {
60 console
.log('Running Low Priority Node: ' + (node
.test
.testMessage
=== 'test' ? 'SYSTEM OK' : 'FAIL'));
62 console
.log('dt is number: ' + (typeof dt
=== 'number' ? 'OK' : 'FAIL'));
63 console
.log('System update callback: EXEC OK');
66 let lowProTestSystem
= new LowProTestSystem();
67 console
.log('LowProTestSystem: CREATE OK');
69 let MidProTestSystem
= class MidProTestSystem
extends Serpentity
.System
{
71 this.testNodes
= engine
.getNodes(TestNode
);
72 console
.log('Engine is serpentity: ' + (engine
instanceof Serpentity
? 'OK' : 'FAIL'));
73 console
.log('System added callback: EXEC OK');
77 this.testNodes
= null;
78 console
.log('Engine is serpentity: ' + (engine
instanceof Serpentity
? 'OK' : 'FAIL'));
79 console
.log('System removed callback: EXEC OK');
83 this.testNodes
.forEach(function (node
) {
84 console
.log('Running Mid Priority Node: ' + (node
.test
.testMessage
=== 'test' ? 'SYSTEM OK' : 'FAIL'));
86 console
.log('dt is number: ' + (typeof dt
=== 'number' ? 'OK' : 'FAIL'));
87 console
.log('System update callback: EXEC OK');
90 var midProTestSystem
= new MidProTestSystem();
91 console
.log('MidProTestSystem: CREATE OK');
94 let TestComponent
= class TestComponent
extends Serpentity
.Component
{
95 constructor (config
) {
98 this.testMessage
= this.testMessage
|| 'test';
101 console
.log('TestComponent: CREATE OK');
103 let TestNode
= class TestNode
extends Serpentity
.Node
{};
107 console
.log('TestNode: CREATE OK');
109 console
.log('\n## Adding system to the engine');
111 let engine
= new Serpentity();
112 console
.log('engine: CREATE OK');
114 engine
.addSystem(testSystem
, 0);
116 console
.log('\n## Running update without any entities');
119 console
.log('\n## Adding system to the engine and updating');
120 let entity
= new Serpentity
.Entity();
121 entity
.addComponent(new TestComponent());
122 engine
.addEntity(entity
);
125 console
.log('\n## Adding Low Priority System');
126 engine
.addSystem(lowProTestSystem
, 10);
129 console
.log('\n## Adding Mid Priority System');
130 engine
.addSystem(midProTestSystem
, 5);
133 console
.log('\n## Removing the system and readding');
134 engine
.removeSystem(testSystem
);
136 engine
.addSystem(testSystem
, 0);
139 console
.log('\n## Adding a second entity');
140 entity
= new Serpentity
.Entity();
141 entity
.addComponent(new TestComponent());
142 engine
.addEntity(entity
);
145 console
.log('\n## Removing entity');
146 engine
.removeEntity(entity
);
149 console
.log('\n## Removing system');
150 engine
.removeSystem(testSystem
);
155 if (typeof require
=== 'function') {
156 let Serpentity
= require('serpentity');
159 window
.addEventListener('load', function () {
160 test(window
.Serpentity
);