bootstrap.js 3.4 KB

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