bootstrap.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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', '.svg'],
  4. plugins: [['module-resolver', { alias: { '^@/(.+)': './frontend/js/\\1' } }]],
  5. })
  6. // Load JSDOM to mock the DOM in Node
  7. // Set pretendToBeVisual to enable requestAnimationFrame
  8. require('jsdom-global')(undefined, {
  9. pretendToBeVisual: true,
  10. url: 'https://www.test-overleaf.com/',
  11. })
  12. const path = require('path')
  13. process.env.OVERLEAF_CONFIG = path.resolve(
  14. __dirname,
  15. '../../config/settings.webpack.js'
  16. )
  17. // Load sinon-chai assertions so expect(stubFn).to.have.been.calledWith('abc')
  18. // has a nicer failure messages
  19. const chai = require('chai')
  20. chai.use(require('sinon-chai'))
  21. chai.use(require('chai-as-promised'))
  22. // Mock global settings
  23. window.ExposedSettings = {
  24. appName: 'Overleaf',
  25. maxEntitiesPerProject: 10,
  26. maxUploadSize: 5 * 1024 * 1024,
  27. siteUrl: 'https://www.dev-overleaf.com',
  28. hasLinkUrlFeature: true,
  29. hasLinkedProjectFileFeature: true,
  30. hasLinkedProjectOutputFileFeature: true,
  31. textExtensions: [
  32. 'tex',
  33. 'latex',
  34. 'sty',
  35. 'cls',
  36. 'bst',
  37. 'bib',
  38. 'bibtex',
  39. 'txt',
  40. 'tikz',
  41. 'mtx',
  42. 'rtex',
  43. 'md',
  44. 'asy',
  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. 'lhs',
  61. 'mk',
  62. 'xmpdata',
  63. 'cfg',
  64. 'rnw',
  65. 'ltx',
  66. 'inc',
  67. ],
  68. editableFilenames: ['latexmkrc', '.latexmkrc', 'makefile', 'gnumakefile'],
  69. }
  70. window.i18n = { currentLangCode: 'en' }
  71. require('../../frontend/js/i18n')
  72. const moment = require('moment')
  73. moment.updateLocale('en', {
  74. calendar: {
  75. lastDay: '[Yesterday]',
  76. sameDay: '[Today]',
  77. nextDay: '[Tomorrow]',
  78. lastWeek: 'ddd, Do MMM YY',
  79. nextWeek: 'ddd, Do MMM YY',
  80. sameElse: 'ddd, Do MMM YY',
  81. },
  82. })
  83. // workaround for missing keys in jsdom-global's keys.js
  84. globalThis.AbortController = global.AbortController = window.AbortController
  85. globalThis.MutationObserver = global.MutationObserver = window.MutationObserver
  86. globalThis.StorageEvent = global.StorageEvent = window.StorageEvent
  87. globalThis.SVGElement = global.SVGElement = window.SVGElement
  88. globalThis.localStorage = global.localStorage = window.localStorage
  89. globalThis.performance = global.performance = window.performance
  90. globalThis.cancelAnimationFrame = global.cancelAnimationFrame =
  91. window.cancelAnimationFrame
  92. globalThis.requestAnimationFrame = global.requestAnimationFrame =
  93. window.requestAnimationFrame
  94. globalThis.sessionStorage = global.sessionStorage = window.sessionStorage
  95. // add polyfill for ResizeObserver
  96. globalThis.ResizeObserver =
  97. global.ResizeObserver =
  98. window.ResizeObserver =
  99. require('@juggle/resize-observer').ResizeObserver
  100. // add stub for BroadcastChannel (unused in these tests)
  101. globalThis.BroadcastChannel =
  102. global.BroadcastChannel =
  103. window.BroadcastChannel =
  104. class BroadcastChannel {
  105. addEventListener(type, listener) {}
  106. removeEventListener(type, listener) {}
  107. postMessage(message) {}
  108. }
  109. // add stub for WebSocket state enum
  110. globalThis.WebSocket = class WebSocket {
  111. static CONNECTING = 0
  112. static OPEN = 1
  113. static CLOSING = 2
  114. static CLOSED = 3
  115. }
  116. // node-fetch doesn't accept relative URL's: https://github.com/node-fetch/node-fetch/blob/master/docs/v2-LIMITS.md#known-differences
  117. const fetch = require('node-fetch')
  118. globalThis.fetch =
  119. global.fetch =
  120. window.fetch =
  121. (url, ...options) => fetch(new URL(url, 'http://127.0.0.1'), ...options)
  122. // ignore CSS files
  123. const { addHook } = require('pirates')
  124. addHook(() => '', { exts: ['.css'], ignoreNodeModules: false })
  125. globalThis.HTMLElement.prototype.scrollIntoView = () => {}
  126. globalThis.DOMParser = window.DOMParser