mirror of
https://github.com/flarum/framework.git
synced 2024-11-23 01:51:05 +08:00
61 lines
1.4 KiB
JavaScript
61 lines
1.4 KiB
JavaScript
import mixin from '@flarum/core/src/common/utils/mixin';
|
|
import ExportRegistry from '@flarum/core/src/common/ExportRegistry';
|
|
import jquery from 'jquery';
|
|
import m from 'mithril';
|
|
import dayjs from 'dayjs';
|
|
import './test-matchers';
|
|
|
|
import relativeTime from 'dayjs/plugin/relativeTime';
|
|
import localizedFormat from 'dayjs/plugin/localizedFormat';
|
|
import jsdom from 'jsdom';
|
|
|
|
dayjs.extend(relativeTime);
|
|
dayjs.extend(localizedFormat);
|
|
|
|
const dom = new jsdom.JSDOM('', {
|
|
pretendToBeVisual: false,
|
|
});
|
|
|
|
// Fill in the globals Mithril.js needs to operate. Also, the first two are often
|
|
// useful to have just in tests.
|
|
global.window = dom.window;
|
|
global.document = dom.window.document;
|
|
global.requestAnimationFrame = (callback) => callback();
|
|
|
|
// Some other needed pollyfills.
|
|
window.$ = jquery;
|
|
window.testing = true;
|
|
window.m = m;
|
|
window.$.fn.tooltip = () => {};
|
|
window.matchMedia = () => ({
|
|
addListener: () => {},
|
|
removeListener: () => {},
|
|
});
|
|
window.scrollTo = () => {};
|
|
|
|
// Flarum specific globals.
|
|
global.flarum = {
|
|
extensions: {},
|
|
reg: new (mixin(ExportRegistry, {
|
|
checkModule: () => true,
|
|
}))(),
|
|
};
|
|
|
|
// Prepare basic dom structure.
|
|
document.body.innerHTML = `
|
|
<div id="app">
|
|
<main class="App-content">
|
|
<div id="notices"></div>
|
|
<div id="content"></div>
|
|
</main>
|
|
</div>
|
|
`;
|
|
|
|
beforeEach(() => {
|
|
flarum.reg.clear();
|
|
});
|
|
|
|
afterAll(() => {
|
|
dom.window.close();
|
|
});
|