bootstrap.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. require('jsdom-global/register')
  5. // Load sinon-chai assertions so expect(stubFn).to.have.been.calledWith('abc')
  6. // has a nicer failure messages
  7. const chai = require('chai')
  8. chai.use(require('sinon-chai'))
  9. window.i18n = { currentLangCode: 'en' }
  10. require('../../frontend/js/i18n')
  11. const moment = require('moment')
  12. moment.updateLocale('en', {
  13. calendar: {
  14. lastDay: '[Yesterday]',
  15. sameDay: '[Today]',
  16. nextDay: '[Tomorrow]',
  17. lastWeek: 'ddd, Do MMM YY',
  18. nextWeek: 'ddd, Do MMM YY',
  19. sameElse: 'ddd, Do MMM YY'
  20. }
  21. })
  22. let inMemoryLocalStorage = {}
  23. global.localStorage = {
  24. // localStorage returns `null` when the item does not exist
  25. getItem: key =>
  26. inMemoryLocalStorage[key] !== undefined ? inMemoryLocalStorage[key] : null,
  27. setItem: (key, value) => (inMemoryLocalStorage[key] = value),
  28. clear: () => (inMemoryLocalStorage = {}),
  29. removeItem: key => delete inMemoryLocalStorage[key]
  30. }
  31. // node-fetch doesn't accept relative URL's: https://github.com/node-fetch/node-fetch/blob/master/docs/v2-LIMITS.md#known-differences
  32. const fetch = require('node-fetch')
  33. global.fetch = (url, ...options) => fetch('http://localhost' + url, ...options)
  34. // Mock global settings
  35. window.ExposedSettings = {}