bootstrap.js 3.2 KB

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