UNPKG

open-epsilon

Version:

empty-epsilon / open-sound-control bidirectional proxy

70 lines 3.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const game_monitor_1 = require("../src/game-monitor"); const rxjs_1 = require("rxjs"); const sinon_1 = require("sinon"); const chai_1 = require("chai"); const kissfs_1 = require("kissfs"); function delay(timeout) { return new Promise(r => setTimeout(r, timeout)); } describe('getMonitoredAddresses', () => { const INITIAL_VALUE = ['/foo/bar']; const OTHER_VALUE = ['/foo', '/foo/bar', 'foo2/bar']; let fs; beforeEach(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () { fs = new kissfs_1.MemoryFileSystem(); yield fs.saveFile('game-monitor.json', JSON.stringify(INITIAL_VALUE)); })); it('reads file correctly', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const monitored = yield game_monitor_1.getMonitoredAddresses(fs); chai_1.expect(monitored).to.eql(INITIAL_VALUE); })); it('tracks changes', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const monitored = yield game_monitor_1.getMonitoredAddresses(fs); yield fs.saveFile('game-monitor.json', JSON.stringify(OTHER_VALUE)); chai_1.expect(monitored).to.eql(OTHER_VALUE); })); it('ignores invalid changes', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const monitored = yield game_monitor_1.getMonitoredAddresses(fs); yield fs.saveFile('game-monitor.json', 'fooooo'); chai_1.expect(monitored).to.eql(INITIAL_VALUE); })); }); describe('monitorByAddress', () => { const pollRequests = new rxjs_1.Subject(); const fakeDriver = { query: sinon_1.stub(), }; const output = sinon_1.spy(); const translator = sinon_1.stub(); it('basically works', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const address = '/ee/player-ship/-1/rotation'; const expr = `getPlayerShip(-1):getRotation()`; const driverResult = '6'; game_monitor_1.monitorByAddress(pollRequests, fakeDriver, translator) .subscribe(output, console.error.bind(console), console.log.bind(console, 'completed')); chai_1.expect(translator).to.have.callCount(0); chai_1.expect(fakeDriver.query).to.have.callCount(0); translator.returns({ address, expr, type: 'f' }); fakeDriver.query.resolves([driverResult]); pollRequests.next(address); chai_1.expect(translator).to.have.callCount(1); chai_1.expect(translator).to.have.been.calledWith(address); chai_1.expect(fakeDriver.query).to.have.callCount(1); chai_1.expect(fakeDriver.query).to.have.been.calledWith(expr); // "wait" for the driver's result yield delay(1); chai_1.expect(output).to.have.callCount(1); chai_1.expect(output).to.have.been.calledWith({ address, args: [{ type: 'f', value: driverResult }] }); })); }); //# sourceMappingURL=game-monitor.spec.js.map