dist/bundle/clock.test.js
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { expect } from 'chai';
import * as sinon from 'sinon';
import { Clock } from './clock';
describe('Clock', () => {
let clock;
let timer;
beforeEach(() => {
const socket = {
once(ev, fn) {
expect(ev).to.equal('interactivePacket');
fn();
},
call(method) {
expect(method).to.equal('getTime');
// Simulate 20ms RTT with a clock 100ms ahead of the local.
timer.tick(10);
const result = Promise.resolve({ time: Date.now() + 100 });
timer.tick(10);
return result;
},
};
timer = sinon.useFakeTimers();
clock = new Clock(socket);
});
afterEach(() => {
timer.restore();
});
it('syncs time forwards', () => __awaiter(this, void 0, void 0, function* () {
expect(yield clock.localToRemote(0)).to.equal(100);
}));
it('syncs time backwards', () => __awaiter(this, void 0, void 0, function* () {
expect(yield clock.remoteToLocal(0)).to.equal(-100);
}));
});