setup.js 836 B

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