bootstrap.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. }
  23. window.i18n = { currentLangCode: 'en' }
  24. require('../../frontend/js/i18n')
  25. const moment = require('moment')
  26. moment.updateLocale('en', {
  27. calendar: {
  28. lastDay: '[Yesterday]',
  29. sameDay: '[Today]',
  30. nextDay: '[Tomorrow]',
  31. lastWeek: 'ddd, Do MMM YY',
  32. nextWeek: 'ddd, Do MMM YY',
  33. sameElse: 'ddd, Do MMM YY',
  34. },
  35. })
  36. let inMemoryLocalStorage = {}
  37. Object.defineProperty(global, 'localStorage', {
  38. value: {
  39. // localStorage returns `null` when the item does not exist
  40. getItem: key =>
  41. inMemoryLocalStorage[key] !== undefined
  42. ? inMemoryLocalStorage[key]
  43. : null,
  44. setItem: (key, value) => (inMemoryLocalStorage[key] = value),
  45. clear: () => (inMemoryLocalStorage = {}),
  46. removeItem: key => delete inMemoryLocalStorage[key],
  47. },
  48. writable: true,
  49. })
  50. // node-fetch doesn't accept relative URL's: https://github.com/node-fetch/node-fetch/blob/master/docs/v2-LIMITS.md#known-differences
  51. const fetch = require('node-fetch')
  52. global.fetch = (url, ...options) => fetch('http://localhost' + url, ...options)
  53. // ignore CSS files
  54. const { addHook } = require('pirates')
  55. addHook(() => '', { exts: ['.css'], ignoreNodeModules: false })