bootstrap.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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, { pretendToBeVisual: true })
  6. const path = require('path')
  7. process.env.SHARELATEX_CONFIG = path.resolve(
  8. __dirname,
  9. '../../config/settings.webpack.js'
  10. )
  11. // Load sinon-chai assertions so expect(stubFn).to.have.been.calledWith('abc')
  12. // has a nicer failure messages
  13. const chai = require('chai')
  14. chai.use(require('sinon-chai'))
  15. chai.use(require('chai-as-promised'))
  16. // Mock global settings
  17. window.ExposedSettings = {
  18. appName: 'Overleaf',
  19. maxEntitiesPerProject: 10,
  20. maxUploadSize: 5 * 1024 * 1024,
  21. siteUrl: 'https://www.dev-overleaf.com',
  22. textExtensions: [
  23. 'tex',
  24. 'latex',
  25. 'sty',
  26. 'cls',
  27. 'bst',
  28. 'bib',
  29. 'bibtex',
  30. 'txt',
  31. 'tikz',
  32. 'mtx',
  33. 'rtex',
  34. 'md',
  35. 'asy',
  36. 'latexmkrc',
  37. 'lbx',
  38. 'bbx',
  39. 'cbx',
  40. 'm',
  41. 'lco',
  42. 'dtx',
  43. 'ins',
  44. 'ist',
  45. 'def',
  46. 'clo',
  47. 'ldf',
  48. 'rmd',
  49. 'lua',
  50. 'gv',
  51. 'mf',
  52. ],
  53. }
  54. window.i18n = { currentLangCode: 'en' }
  55. require('../../frontend/js/i18n')
  56. const moment = require('moment')
  57. moment.updateLocale('en', {
  58. calendar: {
  59. lastDay: '[Yesterday]',
  60. sameDay: '[Today]',
  61. nextDay: '[Tomorrow]',
  62. lastWeek: 'ddd, Do MMM YY',
  63. nextWeek: 'ddd, Do MMM YY',
  64. sameElse: 'ddd, Do MMM YY',
  65. },
  66. })
  67. let inMemoryLocalStorage = {}
  68. Object.defineProperty(global, 'localStorage', {
  69. value: {
  70. // localStorage returns `null` when the item does not exist
  71. getItem: key =>
  72. inMemoryLocalStorage[key] !== undefined
  73. ? inMemoryLocalStorage[key]
  74. : null,
  75. setItem: (key, value) => (inMemoryLocalStorage[key] = value),
  76. clear: () => (inMemoryLocalStorage = {}),
  77. removeItem: key => delete inMemoryLocalStorage[key],
  78. },
  79. writable: true,
  80. })
  81. // node-fetch doesn't accept relative URL's: https://github.com/node-fetch/node-fetch/blob/master/docs/v2-LIMITS.md#known-differences
  82. const fetch = require('node-fetch')
  83. global.fetch = (url, ...options) => fetch('http://localhost' + url, ...options)
  84. // ignore CSS files
  85. const { addHook } = require('pirates')
  86. addHook(() => '', { exts: ['.css'], ignoreNodeModules: false })