setup.js 906 B

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