setup.js 823 B

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