fix: tests

This commit is contained in:
cha0s 2022-03-21 22:07:54 -05:00
parent d31096853b
commit c4e9cc9cd2
7 changed files with 534 additions and 512 deletions

View File

@ -1,142 +1,134 @@
// import { import {Flecks} from '@flecks/core/server';
// buildCondition, import {normalize} from '@flecks/socket';
// buildExpression, import {expect} from 'chai';
// buildInvoke,
// } from '@avocado/behavior';
// import {Flecks} from '@flecks/core';
// import {normalize} from '@flecks/socket';
// import {expect} from 'chai';
// let flecks; let flecks;
// let Entity; let Entity;
// beforeEach(async () => { beforeEach(async () => {
// flecks = Flecks.mock({ flecks = Flecks.bootstrap({
// '@avocado/behavior': require('@avocado/behavior'), config: {
// '@avocado/entity': require('../src'), '@avocado/behavior': {},
// '@avocado/resource': require('@avocado/resource'), '@avocado/entity:./src': {},
// '@avocado/traits': require('@avocado/traits'), '@avocado/graphics': {},
// '@flecks/socket': require('@flecks/socket'), '@avocado/resource': {},
// }); '@avocado/traits': {},
// await Promise.all(flecks.invokeFlat('@flecks/core/starting')); '@flecks/core': {},
// ({Entity} = flecks.get('$avocado/resource.resources')); '@flecks/react': {},
// }); '@flecks/socket': {},
// describe('Alive', () => { },
// let entity; });
// beforeEach(async () => { await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
// entity = await Entity.load({ ({Entity} = flecks.get('$avocado/resource.resources'));
// traits: { });
// Alive: {}, describe('Alive', () => {
// }, let entity;
// }); beforeEach(async () => {
// }); entity = await Entity.load({
// it('exists', async () => { traits: {
// expect(entity.is('Alive')).to.be.true; Alive: {},
// }); },
// if ('http' !== process.env.FLECKS_CORE_BUILD_TARGET) { });
// it('can die', async () => { });
// let isDying = false; it('exists', async () => {
// entity.once('startedDying', () => { expect(entity.is('Alive')).to.be.true;
// isDying = true; });
// }); if ('http' !== process.env.FLECKS_CORE_BUILD_TARGET) {
// entity.life = 0; it('can die', async () => {
// entity.tick(0); let isDying = false;
// expect(isDying).to.be.true; entity.once('startedDying', () => {
// }); isDying = true;
// } });
// it('clamps life', async () => { entity.life = 0;
// entity.life = 120; entity.tick(0);
// expect(entity.life).to.equal(100); expect(isDying).to.be.true;
// entity.maxLife = 50; });
// expect(entity.life).to.equal(50); }
// }); it('clamps life', async () => {
// if ('http' !== process.env.FLECKS_CORE_BUILD_TARGET) { entity.life = 120;
// it('can have a custom death condition', async () => { expect(entity.life).to.equal(100);
// const entity = await Entity.load({ entity.maxLife = 50;
// traits: { expect(entity.life).to.equal(50);
// Alive: { });
// params: { if ('http' !== process.env.FLECKS_CORE_BUILD_TARGET) {
// deathCondition: buildCondition('<=', [ it('can have a custom death condition', async () => {
// buildExpression(['entity', 'life']), const entity = await Entity.load({
// 10, traits: {
// ]), Alive: {
// }, params: {
// }, deathCheck: 'return entity.life <= 10',
// }, },
// }); },
// let isDying = false; },
// entity.on('startedDying', () => { });
// isDying = true; let isDying = false;
// }); entity.on('startedDying', () => {
// entity.tick(0); isDying = true;
// expect(isDying).to.be.false; });
// entity.life = 10; entity.tick(0);
// entity.tick(0); expect(isDying).to.be.false;
// expect(isDying).to.be.true; entity.life = 10;
// }); entity.tick(0);
// } expect(isDying).to.be.true;
// it('runs actions on death', async () => { });
// let didActions; }
// const entity = await Entity.load({ it('runs actions on death', async () => {
// traits: { let didActions;
// Alive: { const entity = await Entity.load({
// params: { traits: {
// deathActions: { Alive: {
// type: 'expressions', params: {
// expressions: [ deathScript: 'entity.ded();',
// buildInvoke(['entity', 'ded']), },
// ], },
// }, },
// }, });
// }, entity.ded = () => {
// }, didActions = true;
// }); };
// entity.ded = () => { const handle = setInterval(() => {
// didActions = true; entity.tick();
// }; }, 16.66);
// const handle = setInterval(() => { await entity.die();
// entity.tick(); clearInterval(handle);
// }, 16.66); expect(didActions).to.be.true;
// await entity.die(); });
// clearInterval(handle); describe('Packets', () => {
// expect(didActions).to.be.true; let entity2;
// }); beforeEach(async () => {
// describe('Packets', () => { entity2 = await Entity.load({
// let entity2; traits: {
// beforeEach(async () => { Alive: {},
// entity2 = await Entity.load({ },
// traits: { });
// Alive: {}, });
// }, it('generates and accepts life packets', async () => {
// }); entity.life = 80;
// }); entity.maxLife = 90;
// it('generates and accepts life packets', async () => { const packets = entity.trait('Alive').packetsFor();
// entity.life = 80; expect(packets).to.have.lengthOf(1);
// entity.maxLife = 90; expect(packets[0][0]).to.equal('TraitUpdateAlive');
// const packets = entity.trait('Alive').packetsFor(); expect(packets[0][1]).to.deep.equal({life: 80, maxLife: 90});
// expect(packets).to.have.lengthOf(1); entity2.trait('Alive').acceptPacket(normalize(flecks, packets[0]));
// expect(packets[0][0]).to.equal('TraitUpdateAlive'); expect(entity2.life).to.equal(80);
// expect(packets[0][1]).to.deep.equal({life: 80, maxLife: 90}); expect(entity2.maxLife).to.equal(90);
// entity2.trait('Alive').acceptPacket(normalize(flecks, packets[0])); });
// expect(entity2.life).to.equal(80); if ('http' !== process.env.FLECKS_CORE_BUILD_TARGET) {
// expect(entity2.maxLife).to.equal(90); it('generates and accepts death packets', async () => {
// }); entity.life = 0;
// if ('http' !== process.env.FLECKS_CORE_BUILD_TARGET) { entity.tick();
// it('generates and accepts death packets', async () => { const packets = entity.trait('Alive').packetsFor();
// entity.life = 0; expect(packets).to.have.lengthOf(2);
// entity.tick(); expect(packets[0][0]).to.equal('Died');
// const packets = entity.trait('Alive').packetsFor(); expect(packets[1][0]).to.equal('TraitUpdateAlive');
// expect(packets).to.have.lengthOf(2); expect(packets[1][1]).to.deep.equal({life: 0, maxLife: 100});
// expect(packets[0][0]).to.equal('Died'); const promise = new Promise((resolve) => {
// expect(packets[1][0]).to.equal('TraitUpdateAlive'); entity2.once('startedDying', resolve);
// expect(packets[1][1]).to.deep.equal({life: 0, maxLife: 100}); });
// const promise = new Promise((resolve) => { entity2.trait('Alive').acceptPacket(normalize(flecks, packets[0]));
// entity2.once('startedDying', resolve); entity2.trait('Alive').acceptPacket(normalize(flecks, packets[1]));
// }); expect(entity2.life).to.equal(0);
// entity2.trait('Alive').acceptPacket(normalize(flecks, packets[0])); return promise;
// entity2.trait('Alive').acceptPacket(normalize(flecks, packets[1])); });
// expect(entity2.life).to.equal(0); }
// return promise; });
// }); });
// }
// });
// });

View File

@ -1,58 +1,63 @@
// import {Flecks} from '@flecks/core'; import {Flecks} from '@flecks/core/server';
// import {normalize} from '@flecks/socket'; import {normalize} from '@flecks/socket';
// import {expect} from 'chai'; import {expect} from 'chai';
// let flecks; let flecks;
// let Entity; let Entity;
// beforeEach(async () => { beforeEach(async () => {
// flecks = Flecks.mock({ flecks = Flecks.bootstrap({
// '@avocado/entity': require('../src'), config: {
// '@avocado/resource': require('@avocado/resource'), '@avocado/entity:./src': {},
// '@avocado/traits': require('@avocado/traits'), '@avocado/graphics': {},
// '@flecks/socket': require('@flecks/socket'), '@avocado/resource': {},
// }); '@avocado/traits': {},
// await Promise.all(flecks.invokeFlat('@flecks/core/starting')); '@flecks/core': {},
// ({Entity} = flecks.get('$avocado/resource.resources')); '@flecks/react': {},
// }); '@flecks/socket': {},
// describe('Directional', () => { },
// let entity; });
// beforeEach(async () => { await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
// entity = await Entity.load({ ({Entity} = flecks.get('$avocado/resource.resources'));
// traits: { });
// Directional: { describe('Directional', () => {
// params: { let entity;
// directionCount: 4, beforeEach(async () => {
// }, entity = await Entity.load({
// }, traits: {
// }, Directional: {
// }); params: {
// }); directionCount: 4,
// it('exists', async () => { },
// expect(entity.is('Directional')).to.be.true; },
// }); },
// it('tracks movement', async () => { });
// entity.emit('movementRequest', [1, 0]); });
// expect(entity.direction).to.equal(1); it('exists', async () => {
// entity.emit('movementRequest', [0, 1]); expect(entity.is('Directional')).to.be.true;
// expect(entity.direction).to.equal(2); });
// entity.emit('movementRequest', [-1, 0]); it('tracks movement', async () => {
// expect(entity.direction).to.equal(3); entity.emit('movementRequest', [1, 0]);
// entity.emit('movementRequest', [0, -1]); expect(entity.direction).to.equal(1);
// expect(entity.direction).to.equal(0); entity.emit('movementRequest', [0, 1]);
// }); expect(entity.direction).to.equal(2);
// it('generates and accepts direction packets', async () => { entity.emit('movementRequest', [-1, 0]);
// entity.direction = 2; expect(entity.direction).to.equal(3);
// const packets = entity.trait('Directional').packetsFor(); entity.emit('movementRequest', [0, -1]);
// expect(packets).to.have.lengthOf(1); expect(entity.direction).to.equal(0);
// expect(packets[0][0]).to.equal('TraitUpdateDirectionalDirection'); });
// expect(packets[0][1]).to.equal(2); it('generates and accepts direction packets', async () => {
// const entity2 = await Entity.load({ entity.direction = 2;
// traits: { const packets = entity.trait('Directional').packetsFor();
// Directional: {}, expect(packets).to.have.lengthOf(1);
// }, expect(packets[0][0]).to.equal('TraitUpdateDirectionalDirection');
// }); expect(packets[0][1]).to.equal(2);
// expect(entity2.direction).to.equal(0); const entity2 = await Entity.load({
// entity2.trait('Directional').acceptPacket(normalize(flecks, packets[0])); traits: {
// expect(entity2.direction).to.equal(2); Directional: {},
// }); },
// }); });
expect(entity2.direction).to.equal(0);
entity2.trait('Directional').acceptPacket(normalize(flecks, packets[0]));
expect(entity2.direction).to.equal(2);
});
});

View File

@ -1,93 +1,98 @@
// import {Trait, traits} from '@avocado/traits'; import {Trait} from '@avocado/traits';
// import {Flecks} from '@flecks/core'; import {Flecks} from '@flecks/core/server';
// import {expect} from 'chai'; import {expect} from 'chai';
// let flecks; let flecks;
// let Entity; let Entity;
// beforeEach(async () => { beforeEach(async () => {
// flecks = Flecks.mock({ flecks = Flecks.bootstrap({
// '@avocado/entity': require('../src'), config: {
// '@avocado/resource': require('@avocado/resource'), '@avocado/entity:./src': {},
// '@avocado/traits': require('@avocado/traits'), '@avocado/graphics': {},
// }); '@avocado/resource': {},
// await Promise.all(flecks.invokeFlat('@flecks/core/starting')); '@avocado/traits': {},
// ({Entity} = flecks.get('$avocado/resource.resources')); '@flecks/core': {},
// }); '@flecks/react': {},
// it('has sane defaults', () => { },
// const entity = new Entity(); });
// expect(entity.traits).to.deep.equal({}); await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
// expect(entity.traitTypes()).to.deep.equal([]); ({Entity} = flecks.get('$avocado/resource.resources'));
// }); });
// it('can add and remove traits', async () => { it('has sane defaults', () => {
// const entity = new Entity(); const entity = new Entity();
// const TestTrait = class extends Trait { expect(entity.traits).to.deep.equal({});
expect(entity.traitTypes()).to.deep.equal([]);
});
it('can add and remove traits', async () => {
const entity = new Entity();
const TestTrait = class extends Trait {
// static get type() { static get type() {
// return 'TestTrait'; return 'TestTrait';
// } }
// }; };
// flecks.set('$avocado/traits.traits.TestTrait', TestTrait); flecks.set('$avocado/traits.traits.TestTrait', TestTrait);
// await entity.addTrait('TestTrait'); await entity.addTrait('TestTrait');
// expect(entity.is('TestTrait')).to.be.true; expect(entity.is('TestTrait')).to.be.true;
// entity.removeTrait('TestTrait'); entity.removeTrait('TestTrait');
// expect(entity.is('TestTrait')).to.be.false; expect(entity.is('TestTrait')).to.be.false;
// }); });
// it('can add traits asynchronously', async () => { it('can add traits asynchronously', async () => {
// const DELAY = 30; const DELAY = 30;
// class AsyncTrait extends Trait { class AsyncTrait extends Trait {
// static async extendJson(json) { static async extendJson(json) {
// const extended = await super.extendJson(json); const extended = await super.extendJson(json);
// await new Promise((resolve) => setTimeout(resolve, DELAY)); await new Promise((resolve) => setTimeout(resolve, DELAY));
// return extended; return extended;
// } }
// } }
// flecks.set('$avocado/traits.traits.Async', AsyncTrait); flecks.set('$avocado/traits.traits.Async', AsyncTrait);
// let start = Date.now(); const start = Date.now();
// const entity = await Entity.load({ await Entity.load({
// traits: { traits: {
// Async: {}, Async: {},
// }, },
// }); });
// expect(Date.now() - start).to.be.at.least(DELAY * 0.9); expect(Date.now() - start).to.be.at.least(DELAY * 0.9);
// }); });
// it('can invoke hooks', async () => { it('can invoke hooks', async () => {
// class AnotherTrait extends Trait { class AnotherTrait extends Trait {
// hooks() { hooks() {
// return { return {
// testHook: () => 69, testHook: () => 69,
// }; };
// } }
// static get type() { static get type() {
// return 'AnotherTrait'; return 'AnotherTrait';
// } }
// } }
// class YetAnotherTrait extends Trait { class YetAnotherTrait extends Trait {
// hooks() { hooks() {
// return { return {
// testHook: () => 420, testHook: () => 420,
// }; };
// } }
// static get type() { static get type() {
// return 'YetAnotherTrait'; return 'YetAnotherTrait';
// } }
// } }
// flecks.set('$avocado/traits.traits.AnotherTrait', AnotherTrait); flecks.set('$avocado/traits.traits.AnotherTrait', AnotherTrait);
// flecks.set('$avocado/traits.traits.YetAnotherTrait', YetAnotherTrait); flecks.set('$avocado/traits.traits.YetAnotherTrait', YetAnotherTrait);
// const entity = new Entity(); const entity = new Entity();
// await entity.addTrait('AnotherTrait'); await entity.addTrait('AnotherTrait');
// await entity.addTrait('YetAnotherTrait'); await entity.addTrait('YetAnotherTrait');
// expect(entity.invokeHook('testHook')).to.deep.equal({AnotherTrait: 69, YetAnotherTrait: 420}); expect(entity.invokeHook('testHook')).to.deep.equal({AnotherTrait: 69, YetAnotherTrait: 420});
// }); });

View File

@ -1,59 +1,64 @@
// import {Flecks} from '@flecks/core'; import {Flecks} from '@flecks/core/server';
// import {expect} from 'chai'; import {expect} from 'chai';
// let flecks; let flecks;
// let Entity; let Entity;
// let EntityList; beforeEach(async () => {
// beforeEach(async () => { flecks = Flecks.bootstrap({
// flecks = Flecks.mock({ config: {
// '@avocado/entity': require('../src'), '@avocado/entity:./src': {},
// '@avocado/resource': require('@avocado/resource'), '@avocado/graphics': {},
// '@avocado/traits': require('@avocado/traits'), '@avocado/resource': {},
// }); '@avocado/traits': {},
// await Promise.all(flecks.invokeFlat('@flecks/core/starting')); '@flecks/core': {},
// ({Entity, EntityList} = flecks.get('$avocado/resource.resources')); '@flecks/react': {},
// }); '@flecks/socket': {},
// describe('Mobile', () => { },
// let entity; });
// beforeEach(async () => { await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
// entity = await Entity.load({ ({Entity} = flecks.get('$avocado/resource.resources'));
// traits: { });
// Mobile: {}, describe('Mobile', () => {
// Positioned: {}, let entity;
// }, beforeEach(async () => {
// }); entity = await Entity.load({
// }); traits: {
// it('exists', async () => { Mobile: {},
// expect(entity.is('Mobile')).to.be.true; Positioned: {},
// }); },
// it('can request movement', async () => { });
// entity.speed = 100; });
// entity.requestMovement([1, 0]); it('exists', async () => {
// entity.tick(1); expect(entity.is('Mobile')).to.be.true;
// expect(entity.position).to.deep.equal([100, 0]); });
// entity.tick(1); it('can request movement', async () => {
// expect(entity.position).to.deep.equal([100, 0]); entity.speed = 100;
// entity.isMobile = false; entity.requestMovement([1, 0]);
// entity.requestMovement([1, 0]); entity.tick(1);
// entity.tick(1); expect(entity.position).to.deep.equal([100, 0]);
// expect(entity.position).to.deep.equal([100, 0]); entity.tick(1);
// }); expect(entity.position).to.deep.equal([100, 0]);
// it('can force movement', async () => { entity.isMobile = false;
// expect(entity.speed).to.equal(0); entity.requestMovement([1, 0]);
// entity.forceMovement([10, 0]); entity.tick(1);
// expect(entity.position).to.deep.equal([10, 0]); expect(entity.position).to.deep.equal([100, 0]);
// }); });
// it('can move for a time', async () => { it('can force movement', async () => {
// entity.speed = 10; expect(entity.speed).to.equal(0);
// const tickingPromise = entity.moveFor([1, 0], 1); entity.forceMovement([10, 0]);
// entity.addTickingPromise(tickingPromise); expect(entity.position).to.deep.equal([10, 0]);
// expect(entity.position).to.deep.equal([0, 0]); });
// entity.tick(0.25); it('can move for a time', async () => {
// expect(entity.position).to.deep.equal([2.5, 0]); entity.speed = 10;
// entity.tick(0.25); const tickingPromise = entity.moveFor([1, 0], 1);
// expect(entity.position).to.deep.equal([5, 0]); entity.addTickingPromise(tickingPromise);
// entity.tick(0.5); expect(entity.position).to.deep.equal([0, 0]);
// expect(entity.position).to.deep.equal([10, 0]); entity.tick(0.25);
// return tickingPromise; expect(entity.position).to.deep.equal([2.5, 0]);
// }); entity.tick(0.25);
// }); expect(entity.position).to.deep.equal([5, 0]);
entity.tick(0.5);
expect(entity.position).to.deep.equal([10, 0]);
return tickingPromise;
});
});

View File

@ -1,44 +1,49 @@
// import {Flecks} from '@flecks/core'; import {Flecks} from '@flecks/core/server';
// import {expect} from 'chai'; import {expect} from 'chai';
// let flecks; let flecks;
// let Entity; let Entity;
// let EntityList; beforeEach(async () => {
// beforeEach(async () => { flecks = Flecks.bootstrap({
// flecks = Flecks.mock({ config: {
// '@avocado/entity': require('../src'), '@avocado/entity:./src': {},
// '@avocado/resource': require('@avocado/resource'), '@avocado/graphics': {},
// '@avocado/traits': require('@avocado/traits'), '@avocado/resource': {},
// }); '@avocado/traits': {},
// await Promise.all(flecks.invokeFlat('@flecks/core/starting')); '@flecks/core': {},
// ({Entity, EntityList} = flecks.get('$avocado/resource.resources')); '@flecks/react': {},
// }); '@flecks/socket': {},
// describe('Perishable', () => { },
// let entity; });
// beforeEach(async () => { await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
// entity = await Entity.load({ ({Entity} = flecks.get('$avocado/resource.resources'));
// traits: { });
// Perishable: { describe('Perishable', () => {
// params: { let entity;
// ttl: 10, beforeEach(async () => {
// }, entity = await Entity.load({
// }, traits: {
// }, Perishable: {
// }); params: {
// }); ttl: 10,
// it('exists', async () => { },
// expect(entity.is('Perishable')).to.be.true; },
// }); },
// it('expires', async () => { });
// const promise = Promise.all([ });
// new Promise((resolve) => { it('exists', async () => {
// entity.on('destroying', resolve); expect(entity.is('Perishable')).to.be.true;
// }), });
// new Promise((resolve) => { it('expires', async () => {
// entity.on('destroyed', resolve); const promise = Promise.all([
// }), new Promise((resolve) => {
// ]); entity.on('destroying', resolve);
// entity.tick(10); }),
// return promise; new Promise((resolve) => {
// }); entity.on('destroyed', resolve);
// }); }),
]);
entity.tick(10);
return promise;
});
});

View File

@ -1,48 +1,52 @@
// import {Flecks} from '@flecks/core'; import {Flecks} from '@flecks/core/server';
// import {normalize} from '@flecks/socket'; import {normalize} from '@flecks/socket';
// import {expect} from 'chai'; import {expect} from 'chai';
// let flecks; let flecks;
// let Entity; let Entity;
// let EntityList; beforeEach(async () => {
// beforeEach(async () => { flecks = Flecks.bootstrap({
// flecks = Flecks.mock({ config: {
// '@avocado/entity': require('../src'), '@avocado/entity:./src': {},
// '@avocado/resource': require('@avocado/resource'), '@avocado/graphics': {},
// '@avocado/traits': require('@avocado/traits'), '@avocado/resource': {},
// '@flecks/socket': require('@flecks/socket'), '@avocado/traits': {},
// }); '@flecks/core': {},
// await Promise.all(flecks.invokeFlat('@flecks/core/starting')); '@flecks/react': {},
// ({Entity, EntityList} = flecks.get('$avocado/resource.resources')); '@flecks/socket': {},
// }); },
// describe('Positioned', () => { });
// let entity; await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
// beforeEach(async () => { ({Entity} = flecks.get('$avocado/resource.resources'));
// entity = await Entity.load({ });
// traits: { describe('Positioned', () => {
// Positioned: {}, let entity;
// }, beforeEach(async () => {
// }); entity = await Entity.load({
// }); traits: {
// it('exists', async () => { Positioned: {},
// expect(entity.is('Positioned')).to.be.true; },
// }); });
// if ('http' !== process.env.FLECKS_CORE_BUILD_TARGET) { });
// it('generates and accepts movement packets', async () => { it('exists', async () => {
// entity.setPosition([1, 1]); expect(entity.is('Positioned')).to.be.true;
// const packets = entity.trait('Positioned').packetsFor(); });
// expect(packets).to.have.lengthOf(1); if ('http' !== process.env.FLECKS_CORE_BUILD_TARGET) {
// expect(packets[0][0]).to.equal('TraitUpdatePositionedPosition'); it('generates and accepts movement packets', async () => {
// expect(packets[0][1]).to.deep.equal([1, 1]); entity.setPosition([1, 1]);
// const entity2 = await Entity.load({ const packets = entity.trait('Positioned').packetsFor();
// traits: { expect(packets).to.have.lengthOf(1);
// Positioned: {}, expect(packets[0][0]).to.equal('TraitUpdatePositionedPosition');
// }, expect(packets[0][1]).to.deep.equal([1, 1]);
// }); const entity2 = await Entity.load({
// expect(entity2.position).to.deep.equal([0, 0]); traits: {
// const trait = entity2.trait('Positioned'); Positioned: {},
// trait.acceptPacket(normalize(flecks, packets[0])); },
// expect(trait.serverPosition).to.deep.equal([1, 1]); });
// }); expect(entity2.position).to.deep.equal([0, 0]);
// } const trait = entity2.trait('Positioned');
// }); trait.acceptPacket(normalize(flecks, packets[0]));
expect(trait.serverPosition).to.deep.equal([1, 1]);
});
}
});

View File

@ -1,89 +1,95 @@
// import {Flecks} from '@flecks/core'; import {Flecks} from '@flecks/core/server';
// import {expect} from 'chai'; import {expect} from 'chai';
// let flecks; let flecks;
// let Entity; let Entity;
// let EntityList; let EntityList;
// beforeEach(async () => { beforeEach(async () => {
// flecks = Flecks.mock({ flecks = Flecks.bootstrap({
// '@avocado/behavior': require('@avocado/behavior'), config: {
// '@avocado/entity': require('../src'), '@avocado/behavior': {},
// '@avocado/resource': require('@avocado/resource'), '@avocado/entity:./src': {},
// '@avocado/traits': require('@avocado/traits'), '@avocado/graphics': {},
// }); '@avocado/resource': {},
// await Promise.all(flecks.invokeFlat('@flecks/core/starting')); '@avocado/traits': {},
// ({Entity, EntityList} = flecks.get('$avocado/resource.resources')); '@flecks/core': {},
// }); '@flecks/react': {},
// describe('Spawner', () => { '@flecks/socket': {},
// let entity; },
// let list; });
// beforeEach(async () => { await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
// entity = await Entity.load({ ({Entity, EntityList} = flecks.get('$avocado/resource.resources'));
// traits: { });
// Spawner: { describe('Spawner', () => {
// params: { let entity;
// spawns: { let list;
// testy: { beforeEach(async () => {
// traits: { entity = await Entity.load({
// Alive: {}, traits: {
// Positioned: {}, Spawner: {
// }, params: {
// }, spawns: {
// }, testy: {
// }, traits: {
// }, Alive: {},
// }, Positioned: {},
// }); },
// list = new EntityList(); },
// list.addEntity(entity); },
// }); },
// it('exists', async () => { },
// expect(entity.is('Spawner')).to.be.true; },
// }); });
// it('can spawn from key', async () => { list = new EntityList();
// const spawned = await entity.spawn('testy'); list.addEntity(entity);
// expect(spawned.is('Alive')).to.be.true; });
// const spawned2 = await entity.spawn('testy', { it('exists', async () => {
// traits: { expect(entity.is('Spawner')).to.be.true;
// Alive: { });
// state: { it('can spawn from key', async () => {
// life: 50, const spawned = await entity.spawn('testy');
// }, expect(spawned.is('Alive')).to.be.true;
// }, const spawned2 = await entity.spawn('testy', {
// }, traits: {
// }); Alive: {
// expect(spawned2.life).to.equal(50); state: {
// const spawned3 = await entity.spawnAt('testy', [69, 420]); life: 50,
// expect(spawned3.position).to.deep.equal([69, 420]); },
// }); },
// it('can spawn from arbitrary JSON', async () => { },
// const spawned = await entity.spawnRaw({ });
// traits: { expect(spawned2.life).to.equal(50);
// Mobile: {}, const spawned3 = await entity.spawnAt('testy', [69, 420]);
// }, expect(spawned3.position).to.deep.equal([69, 420]);
// }); });
// expect(spawned.is('Mobile')).to.be.true; it('can spawn from arbitrary JSON', async () => {
// const spawned2 = await entity.spawnRawAt( const spawned = await entity.spawnRaw({
// { traits: {
// traits: { Mobile: {},
// Mobile: {}, },
// }, });
// }, expect(spawned.is('Mobile')).to.be.true;
// [311, 200], const spawned2 = await entity.spawnRawAt(
// ); {
// expect(spawned2.position).to.deep.equal([311, 200]); traits: {
// }); Mobile: {},
// it('can kill all children', async () => { },
// const COUNT = 15; },
// for (let i = 0; i < COUNT; ++i) { [311, 200],
// await entity.spawnRaw({ );
// traits: { expect(spawned2.position).to.deep.equal([311, 200]);
// Mobile: {}, });
// }, it('can kill all children', async () => {
// }); const COUNT = 15;
// } await Promise.all(Array(COUNT).fill(0).map(() => (
// expect(Object.keys(list.entities)).to.have.lengthOf(COUNT + 1); entity.spawnRaw({
// await entity.killAllChildren(); traits: {
// expect(Object.keys(list.entities)).to.have.lengthOf(1); Mobile: {},
// }); },
// }); })
)));
expect(Object.keys(list.entities)).to.have.lengthOf(COUNT + 1);
await entity.killAllChildren();
expect(Object.keys(list.entities)).to.have.lengthOf(1);
});
});