bootstrap.js 2.3 KB

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