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')({
|
2022-10-31 09:02:16 -04:00
|
|
|
extensions: ['.ts', '.tsx', '.js', '.jsx', '.mjs'],
|
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
|
|
|
|
2021-03-25 06:11:31 -04:00
|
|
|
// Mock global settings
|
|
|
|
window.ExposedSettings = {
|
|
|
|
appName: 'Overleaf',
|
|
|
|
maxEntitiesPerProject: 10,
|
2021-04-27 03:52:58 -04:00
|
|
|
maxUploadSize: 5 * 1024 * 1024,
|
2021-05-19 04:29:32 -04:00
|
|
|
siteUrl: 'https://www.dev-overleaf.com',
|
2021-07-30 04:57:41 -04:00
|
|
|
hasLinkUrlFeature: true,
|
|
|
|
hasLinkedProjectFileFeature: true,
|
|
|
|
hasLinkedProjectOutputFileFeature: true,
|
2021-05-21 07:32:42 -04:00
|
|
|
textExtensions: [
|
|
|
|
'tex',
|
|
|
|
'latex',
|
|
|
|
'sty',
|
|
|
|
'cls',
|
|
|
|
'bst',
|
|
|
|
'bib',
|
|
|
|
'bibtex',
|
|
|
|
'txt',
|
|
|
|
'tikz',
|
|
|
|
'mtx',
|
|
|
|
'rtex',
|
|
|
|
'md',
|
|
|
|
'asy',
|
|
|
|
'lbx',
|
|
|
|
'bbx',
|
|
|
|
'cbx',
|
|
|
|
'm',
|
|
|
|
'lco',
|
|
|
|
'dtx',
|
|
|
|
'ins',
|
|
|
|
'ist',
|
|
|
|
'def',
|
|
|
|
'clo',
|
|
|
|
'ldf',
|
|
|
|
'rmd',
|
|
|
|
'lua',
|
|
|
|
'gv',
|
|
|
|
'mf',
|
2023-10-04 13:12:09 -04:00
|
|
|
'lhs',
|
|
|
|
'mk',
|
2023-10-18 12:24:12 -04:00
|
|
|
'xmpdata',
|
2024-01-17 03:47:39 -05:00
|
|
|
'cfg',
|
|
|
|
'rnw',
|
|
|
|
'ltx',
|
|
|
|
'inc',
|
2021-05-21 07:32:42 -04:00
|
|
|
],
|
2023-10-04 13:12:09 -04:00
|
|
|
editableFilenames: ['latexmkrc', '.latexmkrc', 'makefile', 'gnumakefile'],
|
2021-03-25 06:11:31 -04:00
|
|
|
}
|
|
|
|
|
2020-09-15 08:48:08 -04:00
|
|
|
window.i18n = { currentLangCode: 'en' }
|
|
|
|
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
|
|
|
|
2021-03-18 05:52:36 -04:00
|
|
|
// ignore CSS files
|
|
|
|
const { addHook } = require('pirates')
|
|
|
|
addHook(() => '', { exts: ['.css'], 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
|