setup.js 877 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. process.env.BACKEND = 'gcs'
  7. // Chai configuration
  8. chai.should()
  9. chai.use(sinonChai)
  10. chai.use(chaiAsPromised)
  11. // Global stubs
  12. const sandbox = sinon.createSandbox()
  13. const stubs = {
  14. logger: {
  15. debug: sandbox.stub(),
  16. log: sandbox.stub(),
  17. info: sandbox.stub(),
  18. warn: sandbox.stub(),
  19. err: sandbox.stub(),
  20. error: sandbox.stub(),
  21. fatal: sandbox.stub(),
  22. },
  23. }
  24. // SandboxedModule configuration
  25. SandboxedModule.configure({
  26. requires: {
  27. '@overleaf/logger': stubs.logger,
  28. },
  29. globals: { Buffer, JSON, console, process },
  30. })
  31. exports.mochaHooks = {
  32. beforeEach() {
  33. this.logger = stubs.logger
  34. },
  35. afterEach() {
  36. sandbox.reset()
  37. },
  38. }