mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-26 08:15:00 +00:00
b35114b81a
Use Object.defineProperty to set global.localStorage for tests GitOrigin-RevId: 541a253a6d19fcc93b40c74942ae8ecffb85fa60
48 lines
1.5 KiB
JavaScript
48 lines
1.5 KiB
JavaScript
// Run babel on tests to allow support for import/export statements in Node
|
|
require('@babel/register')
|
|
|
|
// Load JSDOM to mock the DOM in Node
|
|
require('jsdom-global/register')
|
|
|
|
// Load sinon-chai assertions so expect(stubFn).to.have.been.calledWith('abc')
|
|
// has a nicer failure messages
|
|
const chai = require('chai')
|
|
chai.use(require('sinon-chai'))
|
|
chai.use(require('chai-as-promised'))
|
|
|
|
window.i18n = { currentLangCode: 'en' }
|
|
require('../../frontend/js/i18n')
|
|
|
|
const moment = require('moment')
|
|
moment.updateLocale('en', {
|
|
calendar: {
|
|
lastDay: '[Yesterday]',
|
|
sameDay: '[Today]',
|
|
nextDay: '[Tomorrow]',
|
|
lastWeek: 'ddd, Do MMM YY',
|
|
nextWeek: 'ddd, Do MMM YY',
|
|
sameElse: 'ddd, Do MMM YY'
|
|
}
|
|
})
|
|
|
|
let inMemoryLocalStorage = {}
|
|
Object.defineProperty(global, 'localStorage', {
|
|
value: {
|
|
// localStorage returns `null` when the item does not exist
|
|
getItem: key =>
|
|
inMemoryLocalStorage[key] !== undefined
|
|
? inMemoryLocalStorage[key]
|
|
: null,
|
|
setItem: (key, value) => (inMemoryLocalStorage[key] = value),
|
|
clear: () => (inMemoryLocalStorage = {}),
|
|
removeItem: key => delete inMemoryLocalStorage[key]
|
|
},
|
|
writable: true
|
|
})
|
|
|
|
// node-fetch doesn't accept relative URL's: https://github.com/node-fetch/node-fetch/blob/master/docs/v2-LIMITS.md#known-differences
|
|
const fetch = require('node-fetch')
|
|
global.fetch = (url, ...options) => fetch('http://localhost' + url, ...options)
|
|
|
|
// Mock global settings
|
|
window.ExposedSettings = {}
|