bootstrap.js 3.4 KB

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