overleaf/libraries/metrics/test/unit/js/event_loop.js
Antoine Clausse 7f48c67512 Add prefer-node-protocol ESLint rule (#21532)
* Add `unicorn/prefer-node-protocol`

* Fix `unicorn/prefer-node-protocol` ESLint errors

* Run `npm run format:fix`

* Add sandboxed-module sourceTransformers in mocha setups

Fix `no such file or directory, open 'node:fs'` in `sandboxed-module`

* Remove `node:` in the SandboxedModule requires

* Fix new linting errors with `node:`

GitOrigin-RevId: 68f6e31e2191fcff4cb8058dd0a6914c14f59926
2024-11-11 09:04:51 +00:00

44 lines
1.3 KiB
JavaScript

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