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
|
2024-11-08 05:21:56 -05:00
|
|
|
const path = require('node:path')
|
2020-09-11 14:18:22 -04:00
|
|
|
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
|
|
|
|
2021-12-16 04:04:32 -05:00
|
|
|
describe('event_loop', function () {
|
|
|
|
before(function () {
|
2020-09-11 14:18:22 -04:00
|
|
|
this.metrics = {
|
|
|
|
timing: sinon.stub(),
|
2021-12-16 04:04:32 -05:00
|
|
|
registerDestructor: sinon.stub(),
|
2020-09-11 14:18:22 -04:00
|
|
|
}
|
|
|
|
this.logger = {
|
2021-12-16 04:04:32 -05:00
|
|
|
warn: sinon.stub(),
|
2020-09-11 14:18:22 -04:00
|
|
|
}
|
|
|
|
return (this.event_loop = SandboxedModule.require(modulePath, {
|
|
|
|
requires: {
|
2021-12-16 04:04:32 -05:00
|
|
|
'./index': this.metrics,
|
|
|
|
},
|
2020-09-11 14:18:22 -04:00
|
|
|
}))
|
|
|
|
})
|
2020-07-17 11:17:18 -04:00
|
|
|
|
2021-12-16 04:04:32 -05: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
|
|
|
|
2021-12-16 04:04:32 -05: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
|
|
|
|
2021-12-16 04:04:32 -05: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')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|