bootstrap.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Run babel on tests to allow support for import/export statements in Node
  2. require('@babel/register')
  3. // Load JSDOM to mock the DOM in Node
  4. // Set pretendToBeVisual to enable requestAnimationFrame
  5. require('jsdom-global')(undefined, {
  6. pretendToBeVisual: true,
  7. url: 'https://www.test-overleaf.com/',
  8. })
  9. const path = require('path')
  10. process.env.SHARELATEX_CONFIG = path.resolve(
  11. __dirname,
  12. '../../config/settings.webpack.js'
  13. )
  14. // Load sinon-chai assertions so expect(stubFn).to.have.been.calledWith('abc')
  15. // has a nicer failure messages
  16. const chai = require('chai')
  17. chai.use(require('sinon-chai'))
  18. chai.use(require('chai-as-promised'))
  19. // Mock global settings
  20. window.ExposedSettings = {
  21. appName: 'Overleaf',
  22. maxEntitiesPerProject: 10,
  23. maxUploadSize: 5 * 1024 * 1024,
  24. siteUrl: 'https://www.dev-overleaf.com',
  25. hasLinkUrlFeature: true,
  26. hasLinkedProjectFileFeature: true,
  27. hasLinkedProjectOutputFileFeature: true,
  28. textExtensions: [
  29. 'tex',
  30. 'latex',
  31. 'sty',
  32. 'cls',
  33. 'bst',
  34. 'bib',
  35. 'bibtex',
  36. 'txt',
  37. 'tikz',
  38. 'mtx',
  39. 'rtex',
  40. 'md',
  41. 'asy',
  42. 'latexmkrc',
  43. 'lbx',
  44. 'bbx',
  45. 'cbx',
  46. 'm',
  47. 'lco',
  48. 'dtx',
  49. 'ins',
  50. 'ist',
  51. 'def',
  52. 'clo',
  53. 'ldf',
  54. 'rmd',
  55. 'lua',
  56. 'gv',
  57. 'mf',
  58. ],
  59. }
  60. window.i18n = { currentLangCode: 'en' }
  61. require('../../frontend/js/i18n')
  62. const moment = require('moment')
  63. moment.updateLocale('en', {
  64. calendar: {
  65. lastDay: '[Yesterday]',
  66. sameDay: '[Today]',
  67. nextDay: '[Tomorrow]',
  68. lastWeek: 'ddd, Do MMM YY',
  69. nextWeek: 'ddd, Do MMM YY',
  70. sameElse: 'ddd, Do MMM YY',
  71. },
  72. })
  73. // workaround for missing keys in jsdom-global's keys.js
  74. globalThis.AbortController = global.AbortController = window.AbortController
  75. globalThis.MutationObserver = global.MutationObserver = window.MutationObserver
  76. globalThis.StorageEvent = global.StorageEvent = window.StorageEvent
  77. globalThis.SVGElement = global.SVGElement = window.SVGElement
  78. globalThis.localStorage = global.localStorage = window.localStorage
  79. globalThis.performance = global.performance = window.performance
  80. globalThis.cancelAnimationFrame = global.cancelAnimationFrame =
  81. window.cancelAnimationFrame
  82. globalThis.requestAnimationFrame = global.requestAnimationFrame =
  83. window.requestAnimationFrame
  84. globalThis.sessionStorage = global.sessionStorage = window.sessionStorage
  85. // add polyfill for ResizeObserver
  86. globalThis.ResizeObserver =
  87. global.ResizeObserver =
  88. window.ResizeObserver =
  89. require('@juggle/resize-observer').ResizeObserver
  90. // node-fetch doesn't accept relative URL's: https://github.com/node-fetch/node-fetch/blob/master/docs/v2-LIMITS.md#known-differences
  91. const fetch = require('node-fetch')
  92. globalThis.fetch =
  93. global.fetch =
  94. window.fetch =
  95. (url, ...options) => fetch(new URL(url, 'http://localhost'), ...options)
  96. // ignore CSS files
  97. const { addHook } = require('pirates')
  98. addHook(() => '', { exts: ['.css'], ignoreNodeModules: false })