setup.js 824 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. const sinon = require('sinon')
  2. const SandboxedModule = require('sandboxed-module')
  3. // ensure every ObjectId has the id string as a property for correct comparisons
  4. require('mongodb').ObjectId.cacheHexString = true
  5. const sandbox = sinon.createSandbox()
  6. const stubs = {
  7. logger: {
  8. debug: sandbox.stub(),
  9. log: sandbox.stub(),
  10. info: sandbox.stub(),
  11. warn: sandbox.stub(),
  12. err: sandbox.stub(),
  13. error: sandbox.stub(),
  14. fatal: sandbox.stub(),
  15. },
  16. }
  17. SandboxedModule.configure({
  18. requires: {
  19. '@overleaf/logger': stubs.logger,
  20. },
  21. sourceTransformers: {
  22. removeNodePrefix: function (source) {
  23. return source.replace(/require\(['"]node:/g, "require('")
  24. },
  25. },
  26. })
  27. exports.mochaHooks = {
  28. beforeEach() {
  29. this.logger = stubs.logger
  30. },
  31. afterEach() {
  32. sandbox.reset()
  33. },
  34. }