bootstrap.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Run babel on tests to allow support for import/export statements in Node
  2. require('@babel/register')
  3. // Load JSDOM to mock the DOM in Node
  4. // Set pretendToBeVisual to enable requestAnimationFrame
  5. require('jsdom-global')(undefined, {
  6. pretendToBeVisual: true,
  7. url: 'https://www.test-overleaf.com/',
  8. })
  9. // workaround for "keys.js in jsdom-global doesn't include AbortController"
  10. global.AbortController = window.AbortController
  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. textExtensions: [
  28. 'tex',
  29. 'latex',
  30. 'sty',
  31. 'cls',
  32. 'bst',
  33. 'bib',
  34. 'bibtex',
  35. 'txt',
  36. 'tikz',
  37. 'mtx',
  38. 'rtex',
  39. 'md',
  40. 'asy',
  41. 'latexmkrc',
  42. 'lbx',
  43. 'bbx',
  44. 'cbx',
  45. 'm',
  46. 'lco',
  47. 'dtx',
  48. 'ins',
  49. 'ist',
  50. 'def',
  51. 'clo',
  52. 'ldf',
  53. 'rmd',
  54. 'lua',
  55. 'gv',
  56. 'mf',
  57. ],
  58. }
  59. window.i18n = { currentLangCode: 'en' }
  60. require('../../frontend/js/i18n')
  61. const moment = require('moment')
  62. moment.updateLocale('en', {
  63. calendar: {
  64. lastDay: '[Yesterday]',
  65. sameDay: '[Today]',
  66. nextDay: '[Tomorrow]',
  67. lastWeek: 'ddd, Do MMM YY',
  68. nextWeek: 'ddd, Do MMM YY',
  69. sameElse: 'ddd, Do MMM YY',
  70. },
  71. })
  72. let inMemoryLocalStorage = {}
  73. Object.defineProperty(global, 'localStorage', {
  74. value: {
  75. // localStorage returns `null` when the item does not exist
  76. getItem: key =>
  77. inMemoryLocalStorage[key] !== undefined
  78. ? inMemoryLocalStorage[key]
  79. : null,
  80. setItem: (key, value) => (inMemoryLocalStorage[key] = value),
  81. clear: () => (inMemoryLocalStorage = {}),
  82. removeItem: key => delete inMemoryLocalStorage[key],
  83. },
  84. writable: true,
  85. })
  86. // node-fetch doesn't accept relative URL's: https://github.com/node-fetch/node-fetch/blob/master/docs/v2-LIMITS.md#known-differences
  87. const fetch = require('node-fetch')
  88. global.fetch = window.fetch = (url, ...options) =>
  89. fetch(new URL(url, 'http://localhost'), ...options)
  90. // ignore CSS files
  91. const { addHook } = require('pirates')
  92. addHook(() => '', { exts: ['.css'], ignoreNodeModules: false })