event_loop.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * decaffeinate suggestions:
  3. * DS102: Remove unnecessary code created because of implicit returns
  4. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  5. */
  6. const chai = require('chai')
  7. const { expect } = chai
  8. const path = require('node:path')
  9. const modulePath = path.join(__dirname, '../../../event_loop.js')
  10. const SandboxedModule = require('sandboxed-module')
  11. const sinon = require('sinon')
  12. describe('event_loop', function () {
  13. before(function () {
  14. this.metrics = {
  15. timing: sinon.stub(),
  16. registerDestructor: sinon.stub(),
  17. }
  18. this.logger = {
  19. warn: sinon.stub(),
  20. }
  21. return (this.event_loop = SandboxedModule.require(modulePath, {
  22. requires: {
  23. './index': this.metrics,
  24. },
  25. }))
  26. })
  27. describe('with a logger provided', function () {
  28. before(function () {
  29. return this.event_loop.monitor(this.logger)
  30. })
  31. return it('should register a destructor with metrics', function () {
  32. return expect(this.metrics.registerDestructor.called).to.equal(true)
  33. })
  34. })
  35. return describe('without a logger provided', function () {
  36. return it('should throw an exception', function () {
  37. return expect(this.event_loop.monitor).to.throw('logger is undefined')
  38. })
  39. })
  40. })