setup.js 927 B

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