setup.js 825 B

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