setup.js 791 B

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