vitest_bootstrap.mjs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { chai, vi } from 'vitest'
  2. import './common_bootstrap.js'
  3. import sinon from 'sinon'
  4. import logger from '@overleaf/logger'
  5. import sinonChai from 'sinon-chai'
  6. import chaiAsPromised from 'chai-as-promised'
  7. /*
  8. * Chai configuration
  9. */
  10. // add chai.should()
  11. chai.should()
  12. // Load sinon-chai assertions so expect(stubFn).to.have.been.calledWith('abc')
  13. // has a nicer failure messages
  14. chai.use(sinonChai)
  15. // Load promise support for chai
  16. chai.use(chaiAsPromised)
  17. // Do not truncate assertion errors
  18. chai.config.truncateThreshold = 0
  19. vi.mock('@overleaf/logger', async () => {
  20. return {
  21. default: {
  22. debug: vi.fn(),
  23. info: vi.fn(),
  24. log: vi.fn(),
  25. warn: vi.fn(),
  26. err: vi.fn(),
  27. error: vi.fn(),
  28. fatal: vi.fn(),
  29. },
  30. }
  31. })
  32. beforeEach(ctx => {
  33. // This function is a utility to duplicate the behaviour of passing `done` in place of `next` in an express route handler.
  34. ctx.rejectOnError = reject => {
  35. return err => {
  36. if (err) {
  37. reject(err)
  38. }
  39. }
  40. }
  41. ctx.logger = logger
  42. })
  43. afterEach(() => {
  44. vi.restoreAllMocks()
  45. vi.resetModules()
  46. sinon.restore()
  47. })