overleaf/libraries/metrics/test/unit/js/event_loop.js

45 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-07-17 11:17:18 -04:00
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
2020-09-11 14:18:22 -04:00
const chai = require('chai')
const { expect } = chai
const path = require('path')
const modulePath = path.join(__dirname, '../../../event_loop.js')
const SandboxedModule = require('sandboxed-module')
const sinon = require('sinon')
2020-07-17 11:17:18 -04:00
describe('event_loop', function () {
before(function () {
2020-09-11 14:18:22 -04:00
this.metrics = {
timing: sinon.stub(),
registerDestructor: sinon.stub(),
2020-09-11 14:18:22 -04:00
}
this.logger = {
warn: sinon.stub(),
2020-09-11 14:18:22 -04:00
}
return (this.event_loop = SandboxedModule.require(modulePath, {
requires: {
'./index': this.metrics,
},
2020-09-11 14:18:22 -04:00
}))
})
2020-07-17 11:17:18 -04:00
describe('with a logger provided', function () {
before(function () {
2020-09-11 14:18:22 -04:00
return this.event_loop.monitor(this.logger)
})
2020-07-17 11:17:18 -04:00
return it('should register a destructor with metrics', function () {
2020-09-11 14:18:22 -04:00
return expect(this.metrics.registerDestructor.called).to.equal(true)
})
})
2020-07-17 11:17:18 -04:00
return describe('without a logger provided', function () {
return it('should throw an exception', function () {
2020-09-11 14:18:22 -04:00
return expect(this.event_loop.monitor).to.throw('logger is undefined')
})
})
})