setup.js 972 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. const chai = require('chai')
  2. const sinon = require('sinon')
  3. const sinonChai = require('sinon-chai')
  4. const chaiAsPromised = require('chai-as-promised')
  5. const SandboxedModule = require('sandboxed-module')
  6. const timersPromises = require('timers/promises')
  7. process.env.BACKEND = 'gcs'
  8. // Chai configuration
  9. chai.should()
  10. chai.use(sinonChai)
  11. chai.use(chaiAsPromised)
  12. // Global stubs
  13. const sandbox = sinon.createSandbox()
  14. const stubs = {
  15. logger: {
  16. debug: sandbox.stub(),
  17. log: sandbox.stub(),
  18. info: sandbox.stub(),
  19. warn: sandbox.stub(),
  20. err: sandbox.stub(),
  21. error: sandbox.stub(),
  22. fatal: sandbox.stub(),
  23. },
  24. }
  25. // SandboxedModule configuration
  26. SandboxedModule.configure({
  27. requires: {
  28. '@overleaf/logger': stubs.logger,
  29. 'timers/promises': timersPromises,
  30. },
  31. globals: { Buffer, JSON, Math, console, process },
  32. })
  33. exports.mochaHooks = {
  34. beforeEach() {
  35. this.logger = stubs.logger
  36. },
  37. afterEach() {
  38. sandbox.reset()
  39. },
  40. }