bootstrap.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. hasLinkUrlFeature: true,
  28. hasLinkedProjectFileFeature: true,
  29. hasLinkedProjectOutputFileFeature: true,
  30. textExtensions: [
  31. 'tex',
  32. 'latex',
  33. 'sty',
  34. 'cls',
  35. 'bst',
  36. 'bib',
  37. 'bibtex',
  38. 'txt',
  39. 'tikz',
  40. 'mtx',
  41. 'rtex',
  42. 'md',
  43. 'asy',
  44. 'latexmkrc',
  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. ],
  61. }
  62. window.i18n = { currentLangCode: 'en' }
  63. require('../../frontend/js/i18n')
  64. const moment = require('moment')
  65. moment.updateLocale('en', {
  66. calendar: {
  67. lastDay: '[Yesterday]',
  68. sameDay: '[Today]',
  69. nextDay: '[Tomorrow]',
  70. lastWeek: 'ddd, Do MMM YY',
  71. nextWeek: 'ddd, Do MMM YY',
  72. sameElse: 'ddd, Do MMM YY',
  73. },
  74. })
  75. let inMemoryLocalStorage = {}
  76. Object.defineProperty(global, 'localStorage', {
  77. value: {
  78. // localStorage returns `null` when the item does not exist
  79. getItem: key =>
  80. inMemoryLocalStorage[key] !== undefined
  81. ? inMemoryLocalStorage[key]
  82. : null,
  83. setItem: (key, value) => (inMemoryLocalStorage[key] = value),
  84. clear: () => (inMemoryLocalStorage = {}),
  85. removeItem: key => delete inMemoryLocalStorage[key],
  86. },
  87. writable: true,
  88. })
  89. // node-fetch doesn't accept relative URL's: https://github.com/node-fetch/node-fetch/blob/master/docs/v2-LIMITS.md#known-differences
  90. const fetch = require('node-fetch')
  91. global.fetch = window.fetch = (url, ...options) =>
  92. fetch(new URL(url, 'http://localhost'), ...options)
  93. // ignore CSS files
  94. const { addHook } = require('pirates')
  95. addHook(() => '', { exts: ['.css'], ignoreNodeModules: false })