Pinafore-Web-Client-Frontend/src/routes/_utils/forceOnline.js

21 lines
545 B
JavaScript
Raw Normal View History

2019-07-22 00:31:26 +02:00
import { store } from '../_store/store'
import { emit } from './eventBus'
// Force online/offline state. Needed for integration tests.
// It would be nice not to actually ship this in production, but *shrug*
if (process.browser) {
const globalFetch = window.fetch
window.__forceOnline = online => {
store.set({ online })
if (online) {
window.fetch = globalFetch
emit('forcedOnline', true)
} else {
window.fetch = () => Promise.reject(new Error('force offline'))
emit('forcedOnline', false)
}
}
}