forked from gesinn-it-pub/ConfIDentSkin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.js
68 lines (59 loc) · 1.93 KB
/
setup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const fs = require('fs');
const path = require('path');
const resetDom = createDom();
const sinon = require('sinon');
// Define paths for both versions
const oojsJqueryPath = path.resolve(__dirname, '../../../../resources/lib/oojs/oojs.jquery.js');
const oojsPath = path.resolve(__dirname, '../../../../resources/lib/oojs/oojs.js');
QUnit.hooks.beforeEach(assert => {
sinon.assert.pass = message =>
assert.pushResult({ result: true, expected: true, actual: true, message });
sinon.assert.fail = message =>
assert.pushResult({ result: false, expected: true, actual: false, message });
});
prepareMediaWiki();
QUnit.hooks.afterEach(() => {
resetDom();
sinon.restore();
});
/**
* first attempt to provide a clean environment for each test
*
* @return {(function(): void)|*} a function to reset the DOM between tests
*/
function createDom() {
// required by jsdom
const { TextEncoder, TextDecoder } = require('util');
global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;
const { JSDOM } = require('jsdom');
const dom = new JSDOM();
global.window = dom.window;
global.document = window.document;
global.Node = window.Node;
global.$ = global.jQuery = require('../../../../resources/lib/jquery/jquery.js');
return () => {
global.document.body.innerHTML = '';
};
}
/**
* setup MediaWiki globals: OO, mw, ...
*/
function prepareMediaWiki() {
// Check if oojs.js exists (for MW 1.39+), otherwise use oojs.jquery.js (for MW 1.35)
if (fs.existsSync(oojsPath)) {
global.OO = require(oojsPath);
} else if (fs.existsSync(oojsJqueryPath)) {
global.OO = require(oojsJqueryPath);
} else {
throw new Error('Neither oojs.js nor oojs.jquery.js could be found.');
}
require('../../../../resources/lib/ooui/oojs-ui-core.js');
require('../../../../resources/lib/ooui/oojs-ui-widgets.js');
require('../../../../resources/lib/ooui/oojs-ui-wikimediaui');
global.mw = global.mediaWiki = {
message: () => ({
text: () => {}
})
};
}