bootstrap.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const chai = require('chai')
  2. const sinon = require('sinon')
  3. // add chai.should()
  4. chai.should()
  5. // Load sinon-chai assertions so expect(stubFn).to.have.been.calledWith('abc')
  6. // has a nicer failure messages
  7. chai.use(require('sinon-chai'))
  8. // Load promise support for chai
  9. chai.use(require('chai-as-promised'))
  10. // Do not truncate assertion errors
  11. chai.config.truncateThreshold = 0
  12. // add support for mongoose in sinon
  13. require('sinon-mongoose')
  14. afterEach(function() {
  15. sinon.restore()
  16. })
  17. const SandboxedModule = require('sandboxed-module')
  18. const PromisesUtils = require('../../app/src/util/promises')
  19. const Errors = require('../../app/src/Features/Errors/Errors')
  20. const GLOBAL_REQUIRE_CACHE_FOR_SANDBOXED_MODULES = {
  21. // cache p-limit for all expressify/promisifyAll users
  22. '../../util/promises': PromisesUtils,
  23. '../../../../app/src/util/promises': PromisesUtils,
  24. // Errors are widely used and instance checks need the exact same prototypes
  25. '../Errors/Errors': Errors,
  26. '../../../../app/src/Features/Errors/Errors': Errors,
  27. '../../../../../app/src/Features/Errors/Errors': Errors
  28. }
  29. const LIBRARIES = [
  30. '@overleaf/o-error',
  31. 'async',
  32. 'lodash',
  33. 'moment',
  34. 'underscore',
  35. 'xml2js',
  36. 'json2csv',
  37. 'sanitize-html',
  38. 'marked'
  39. ]
  40. LIBRARIES.forEach(lib => {
  41. GLOBAL_REQUIRE_CACHE_FOR_SANDBOXED_MODULES[lib] = require(lib)
  42. })
  43. SandboxedModule.configure({
  44. requires: GLOBAL_REQUIRE_CACHE_FOR_SANDBOXED_MODULES
  45. })