setup.js 825 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { beforeEach, afterEach, chai, vi } from 'vitest'
  2. import sinon from 'sinon'
  3. import mongodb from 'mongodb'
  4. import sinonChai from 'sinon-chai'
  5. import chaiAsPromised from 'chai-as-promised'
  6. chai.use(sinonChai)
  7. chai.use(chaiAsPromised)
  8. // ensure every ObjectId has the id string as a property for correct comparisons
  9. mongodb.ObjectId.cacheHexString = true
  10. const sandbox = sinon.createSandbox()
  11. const stubs = {
  12. logger: {
  13. debug: sandbox.stub(),
  14. log: sandbox.stub(),
  15. info: sandbox.stub(),
  16. warn: sandbox.stub(),
  17. err: sandbox.stub(),
  18. error: sandbox.stub(),
  19. fatal: sandbox.stub(),
  20. },
  21. }
  22. beforeEach(ctx => {
  23. ctx.logger = stubs.logger
  24. vi.doMock('@overleaf/logger', () => ({
  25. default: ctx.logger,
  26. }))
  27. })
  28. afterEach(() => {
  29. sandbox.reset()
  30. vi.restoreAllMocks()
  31. vi.resetModules()
  32. })