bootstrap.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. 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.SHARELATEX_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. 'latexmkrc',
  46. 'lbx',
  47. 'bbx',
  48. 'cbx',
  49. 'm',
  50. 'lco',
  51. 'dtx',
  52. 'ins',
  53. 'ist',
  54. 'def',
  55. 'clo',
  56. 'ldf',
  57. 'rmd',
  58. 'lua',
  59. 'gv',
  60. 'mf',
  61. ],
  62. }
  63. window.i18n = { currentLangCode: 'en' }
  64. require('../../frontend/js/i18n')
  65. const moment = require('moment')
  66. moment.updateLocale('en', {
  67. calendar: {
  68. lastDay: '[Yesterday]',
  69. sameDay: '[Today]',
  70. nextDay: '[Tomorrow]',
  71. lastWeek: 'ddd, Do MMM YY',
  72. nextWeek: 'ddd, Do MMM YY',
  73. sameElse: 'ddd, Do MMM YY',
  74. },
  75. })
  76. // workaround for missing keys in jsdom-global's keys.js
  77. globalThis.AbortController = global.AbortController = window.AbortController
  78. globalThis.MutationObserver = global.MutationObserver = window.MutationObserver
  79. globalThis.StorageEvent = global.StorageEvent = window.StorageEvent
  80. globalThis.SVGElement = global.SVGElement = window.SVGElement
  81. globalThis.localStorage = global.localStorage = window.localStorage
  82. globalThis.performance = global.performance = window.performance
  83. globalThis.cancelAnimationFrame = global.cancelAnimationFrame =
  84. window.cancelAnimationFrame
  85. globalThis.requestAnimationFrame = global.requestAnimationFrame =
  86. window.requestAnimationFrame
  87. globalThis.sessionStorage = global.sessionStorage = window.sessionStorage
  88. // add polyfill for ResizeObserver
  89. globalThis.ResizeObserver =
  90. global.ResizeObserver =
  91. window.ResizeObserver =
  92. require('@juggle/resize-observer').ResizeObserver
  93. // add stub for BroadcastChannel (unused in these tests)
  94. globalThis.BroadcastChannel =
  95. global.BroadcastChannel =
  96. window.BroadcastChannel =
  97. class BroadcastChannel {
  98. addEventListener(type, listener) {}
  99. removeEventListener(type, listener) {}
  100. postMessage(message) {}
  101. }
  102. // node-fetch doesn't accept relative URL's: https://github.com/node-fetch/node-fetch/blob/master/docs/v2-LIMITS.md#known-differences
  103. const fetch = require('node-fetch')
  104. globalThis.fetch =
  105. global.fetch =
  106. window.fetch =
  107. (url, ...options) => fetch(new URL(url, 'http://localhost'), ...options)
  108. // ignore CSS files
  109. const { addHook } = require('pirates')
  110. addHook(() => '', { exts: ['.css'], ignoreNodeModules: false })