setup.js 740 B

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