2020-07-09 09:56:33 -04:00
|
|
|
// Run babel on tests to allow support for import/export statements in Node
|
2022-03-15 09:17:43 -04:00
|
|
|
require('@babel/register')({
|
2024-06-17 06:34:09 -04:00
|
|
|
extensions: ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.svg'],
|
2023-09-11 05:52:14 -04:00
|
|
|
plugins: [['module-resolver', { alias: { '^@/(.+)': './frontend/js/\\1' } }]],
|
2022-03-15 09:17:43 -04:00
|
|
|
})
|
2020-07-09 09:56:33 -04:00
|
|
|
|
|
|
|
// Load JSDOM to mock the DOM in Node
|
2021-03-18 05:52:36 -04:00
|
|
|
// Set pretendToBeVisual to enable requestAnimationFrame
|
2021-06-21 06:01:29 -04:00
|
|
|
require('jsdom-global')(undefined, {
|
|
|
|
pretendToBeVisual: true,
|
|
|
|
url: 'https://www.test-overleaf.com/',
|
|
|
|
})
|
2021-03-18 05:52:36 -04:00
|
|
|
|
|
|
|
const path = require('path')
|
2024-02-06 04:34:15 -05:00
|
|
|
process.env.OVERLEAF_CONFIG = path.resolve(
|
2021-03-18 05:52:36 -04:00
|
|
|
__dirname,
|
2021-05-19 08:07:10 -04:00
|
|
|
'../../config/settings.webpack.js'
|
2021-03-18 05:52:36 -04:00
|
|
|
)
|
2020-07-09 09:56:33 -04:00
|
|
|
|
|
|
|
// 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'))
|
2021-02-05 09:01:37 -05:00
|
|
|
chai.use(require('chai-as-promised'))
|
2020-09-15 08:48:08 -04:00
|
|
|
|
2024-06-18 06:01:37 -04:00
|
|
|
// Populate meta for top-level access in modules on import
|
|
|
|
const { resetMeta } = require('./helpers/reset-meta')
|
|
|
|
resetMeta()
|
|
|
|
// i18n requires access to 'ol-i18n' as defined above
|
2020-09-15 08:48:08 -04:00
|
|
|
require('../../frontend/js/i18n')
|
2020-10-27 06:52:40 -04:00
|
|
|
|
|
|
|
const moment = require('moment')
|
|
|
|
moment.updateLocale('en', {
|
|
|
|
calendar: {
|
|
|
|
lastDay: '[Yesterday]',
|
|
|
|
sameDay: '[Today]',
|
|
|
|
nextDay: '[Tomorrow]',
|
|
|
|
lastWeek: 'ddd, Do MMM YY',
|
|
|
|
nextWeek: 'ddd, Do MMM YY',
|
2021-04-27 03:52:58 -04:00
|
|
|
sameElse: 'ddd, Do MMM YY',
|
|
|
|
},
|
2020-10-27 06:52:40 -04:00
|
|
|
})
|
2020-11-24 06:58:08 -05:00
|
|
|
|
2021-09-29 07:11:44 -04:00
|
|
|
// workaround for missing keys in jsdom-global's keys.js
|
2021-11-09 07:58:27 -05:00
|
|
|
globalThis.AbortController = global.AbortController = window.AbortController
|
|
|
|
globalThis.MutationObserver = global.MutationObserver = window.MutationObserver
|
|
|
|
globalThis.StorageEvent = global.StorageEvent = window.StorageEvent
|
|
|
|
globalThis.SVGElement = global.SVGElement = window.SVGElement
|
|
|
|
globalThis.localStorage = global.localStorage = window.localStorage
|
|
|
|
globalThis.performance = global.performance = window.performance
|
|
|
|
globalThis.cancelAnimationFrame = global.cancelAnimationFrame =
|
|
|
|
window.cancelAnimationFrame
|
|
|
|
globalThis.requestAnimationFrame = global.requestAnimationFrame =
|
|
|
|
window.requestAnimationFrame
|
|
|
|
globalThis.sessionStorage = global.sessionStorage = window.sessionStorage
|
2021-09-29 07:11:44 -04:00
|
|
|
|
|
|
|
// add polyfill for ResizeObserver
|
2022-01-10 05:23:05 -05:00
|
|
|
globalThis.ResizeObserver =
|
|
|
|
global.ResizeObserver =
|
|
|
|
window.ResizeObserver =
|
|
|
|
require('@juggle/resize-observer').ResizeObserver
|
2021-01-07 09:22:40 -05:00
|
|
|
|
2023-01-09 07:52:11 -05:00
|
|
|
// add stub for BroadcastChannel (unused in these tests)
|
|
|
|
globalThis.BroadcastChannel =
|
|
|
|
global.BroadcastChannel =
|
|
|
|
window.BroadcastChannel =
|
|
|
|
class BroadcastChannel {
|
|
|
|
addEventListener(type, listener) {}
|
|
|
|
removeEventListener(type, listener) {}
|
|
|
|
postMessage(message) {}
|
|
|
|
}
|
|
|
|
|
2023-11-03 06:02:32 -04:00
|
|
|
// add stub for WebSocket state enum
|
|
|
|
globalThis.WebSocket = class WebSocket {
|
|
|
|
static CONNECTING = 0
|
|
|
|
static OPEN = 1
|
|
|
|
static CLOSING = 2
|
|
|
|
static CLOSED = 3
|
|
|
|
}
|
|
|
|
|
2020-11-24 06:58:08 -05:00
|
|
|
// 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')
|
2022-01-10 05:23:05 -05:00
|
|
|
globalThis.fetch =
|
|
|
|
global.fetch =
|
|
|
|
window.fetch =
|
2024-04-25 08:56:00 -04:00
|
|
|
(url, ...options) => fetch(new URL(url, 'http://127.0.0.1'), ...options)
|
2020-12-03 08:58:46 -05:00
|
|
|
|
2024-09-03 08:22:06 -04:00
|
|
|
// ignore CSS/LESS files
|
2021-03-18 05:52:36 -04:00
|
|
|
const { addHook } = require('pirates')
|
2024-09-03 08:22:06 -04:00
|
|
|
addHook(() => '', { exts: ['.css', '.less'], ignoreNodeModules: false })
|
2024-01-23 09:45:47 -05:00
|
|
|
|
|
|
|
globalThis.HTMLElement.prototype.scrollIntoView = () => {}
|
2024-01-29 10:15:30 -05:00
|
|
|
|
|
|
|
globalThis.DOMParser = window.DOMParser
|
2024-08-21 07:28:21 -04:00
|
|
|
|
|
|
|
// Polyfill for IndexedDB
|
|
|
|
require('fake-indexeddb/auto')
|