describe("onEvent", () => { it("should call update for each gauge", () => { const memory = new MemoryGaugeView(options); expect(memory).to.have.property("heapGauge").that.is.an.instanceof(contrib.gauge); expect(memory).to.have.property("rssGauge").that.is.an.instanceof(contrib.gauge); sandbox.stub(memory, "update"); const mem = { heapUsed: 23, heapTotal: 39, rss: 290, systemTotal: 80010 }; memory.onEvent({ mem }); expect(memory.update).to.have.been.calledTwice .and.to.have.been.calledWithExactly(memory.heapGauge, mem.heapUsed, mem.heapTotal) .and.to.have.been.calledWithExactly(memory.rssGauge, mem.rss, mem.systemTotal); }); });
expect(gotoTimeView.screen.render).to.have.been.calledTwice;
expect(cpu.update).to.have.been.calledTwice.and.calledWithExactly({ cpu: "9.0" }); }); });
it("Sets the net.learningRate 'set' function to the cwrap-ed WASM setLearningRate function", () => { sinon.spy(fakeModule, "cwrap") sinon.spy(fakeModule, "cwrapReturnFunction") const net = new Network({Module: fakeModule}) net.learningRate = 1 expect(fakeModule.cwrap).to.be.calledWith("setLearningRate") expect(fakeModule.cwrapReturnFunction).to.be.calledWith(0, 1) expect(fakeModule.cwrap).to.be.calledTwice fakeModule.cwrapReturnFunction.restore() fakeModule.cwrap.restore() })
it("Calls the joinLayer function with each layer when state is constructed", () => { const layer1 = new Layer(1) const layer2 = new Layer(2) const netThis = {state: "constructed", layers: [layer1, layer2], joinLayer: net.joinLayer, activation: NetMath.sigmoid} net.initLayers.bind(netThis)() expect(netThis.state).to.equal("initialised") expect(net.joinLayer).to.have.been.calledTwice expect(net.joinLayer).to.have.been.calledWith(layer1) expect(net.joinLayer).to.have.been.calledWith(layer2) })
it('should be stoppable with end', function () { var task = this.sandbox.spy() var timer = new Timer() var clock = this.sandbox.useFakeTimers() timer.task = task timer.start(1) clock.tick(1) clock.tick(1) timer.end() clock.tick(1) clock.restore() expect(task).to.have.been.calledTwice })
it('should wrap mysql.createConnection and mysql.createPool', function () { var shimmerWrapStub = this.sandbox.stub(Shimmer, 'wrap') var fakeMySql = { createConnection: function () {}, createPool: function () {} } wrapper(fakeMySql, null) expect(shimmerWrapStub).to.have.been.calledTwice expect(shimmerWrapStub.getCall(0)).to.have.been.calledWith( fakeMySql, 'createConnection' ) expect(shimmerWrapStub.getCall(1)).to.have.been.calledWith( fakeMySql, 'createPool' ) })
it('should create instance of Order and calculate total + shipping', () => { expect(o).to.be.instanceOf(Order); expect(dateSpy).to.have.been.calledTwice; expect(o).to.have.property('ref').to.equal(123); expect(o).to.have.property('user').to.deep.equal(user); expect(o).to.have.property('items').to.deep.equal(items); expect(o).to.have.property('status').to.equal('Pending'); expect(o).to.have.property('createdAt').to.be.a('Number'); expect(o).to.have.property('updatedAt').to.be.a('Number'); expect(o).to.have.property('subtotal').to.be.equal(15); expect(o).to.have.property('shipping').to.be.equal(5); expect(o).to.have.property('total').to.be.equal(20); expect(o.save).to.be.a('function'); expect(o.cancel).to.be.a('function'); expect(o.ship).to.be.a('function'); });
describe('startRegistryFetches()', () => { let config; let client; let fetchRegistrySpy; let clock; before(() => { config = makeConfig(); client = new Eureka(config); fetchRegistrySpy = sinon.stub(client, 'fetchRegistry'); clock = sinon.useFakeTimers(); }); after(() => { fetchRegistrySpy.restore(); clock.restore(); }); it('should call renew on interval', () => { client.startRegistryFetches(); clock.tick(30000); expect(fetchRegistrySpy).to.have.been.calledOnce; clock.tick(30000); expect(fetchRegistrySpy).to.have.been.calledTwice; }); });
it('emits "SessionInfo" when update available', function () { var opts = { telemetryUpdateInterval: 10, sessionInfoUpdateInterval: 10 } var mock = Object.create(IrSdkWrapper) var updateSessionInfo = sinon.stub(mock, 'updateSessionInfo') updateSessionInfo.returns(true) var getSessionInfo = sinon.stub(mock, 'getSessionInfo') var data = '---\ntype: race\n' getSessionInfo.returns(data) var isConnected = sinon.stub(mock, 'isConnected') isConnected.returns(true) irsdk = new JsIrSdk(mock, opts) var spy = sinon.spy() irsdk.on('SessionInfo', spy) this.clock.tick(12) spy.should.have.been.calledOnce // spy.should.have.been.calledWith(data); updateSessionInfo.returns(false) this.clock.tick(12) spy.should.have.been.calledOnce updateSessionInfo.returns(true) this.clock.tick(12) spy.should.have.been.calledTwice })
describe('Connection', function () { it('should wrap var connection = mysql.createConnection and var connection = mysql.createPool', function () { var shimmerWrapStub = this.sandbox.stub(Shimmer, 'wrap') var mysql = require('mysql') wrapper(mysql, null) expect(shimmerWrapStub).to.have.been.calledTwice expect(shimmerWrapStub.getCall(0)).to.have.been.calledWith( mysql, 'createConnection' ) expect(shimmerWrapStub.getCall(1)).to.have.been.calledWith( mysql, 'createPool' ) }) })
it('should be restartable with restart', function () { var task = this.sandbox.spy() var anotherTask = this.sandbox.spy() var timer = new Timer() var clock = this.sandbox.useFakeTimers() timer.task = task timer.start(1) clock.tick(1) timer.task = anotherTask timer.restart() clock.tick(1) clock.tick(1) timer.end() clock.restore() expect(task).to.have.been.calledOnce expect(anotherTask).to.have.been.calledTwice })
it('emits "Connected" again after reconnect', function () { var opts = { telemetryUpdateInterval: 2000, sessionInfoUpdateInterval: 20000 } var mock = Object.create(IrSdkWrapper) var start = sinon.stub(mock, 'start') start.returns(true) var isConnected = sinon.stub(mock, 'isConnected') isConnected.returns(true) irsdk = new JsIrSdk(mock, opts) start.should.have.been.calledOnce this.clock.tick(2500) isConnected.returns(false) var isInitialized = sinon.stub(mock, 'isInitialized') isInitialized.returns(false) this.clock.tick(11000) start.should.have.been.calledTwice isConnected.returns(true) isInitialized.returns(true) var restartSpy = sinon.spy() irsdk.on('Connected', restartSpy) this.clock.tick(2500) restartSpy.should.have.been.called })
it('emits "Telemetry" when update available', function () { var opts = { telemetryUpdateInterval: 10, sessionInfoUpdateInterval: 20000 } var mock = Object.create(IrSdkWrapper) var updateTelemetry = sinon.stub(mock, 'updateTelemetry') updateTelemetry.returns(true) var getTelemetry = sinon.stub(mock, 'getTelemetry') var data = {values: {'RPM': 1100}} getTelemetry.returns(data) var isConnected = sinon.stub(mock, 'isConnected') isConnected.returns(true) irsdk = new JsIrSdk(mock, opts) var spy = sinon.spy() irsdk.on('Telemetry', spy) this.clock.tick(12) spy.should.have.been.calledOnce spy.should.have.been.calledWith(data) updateTelemetry.returns(false) this.clock.tick(12) spy.should.have.been.calledOnce updateTelemetry.returns(true) this.clock.tick(12) spy.should.have.been.calledTwice })
describe('startHeartbeats()', () => { let config; let client; let renewSpy; let clock; before(() => { config = makeConfig(); client = new Eureka(config); renewSpy = sinon.stub(client, 'renew'); clock = sinon.useFakeTimers(); }); after(() => { renewSpy.restore(); clock.restore(); }); it('should call renew on interval', () => { client.startHeartbeats(); clock.tick(30000); expect(renewSpy).to.have.been.calledOnce; clock.tick(30000); expect(renewSpy).to.have.been.calledTwice; }); });