-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetupFile.js
More file actions
50 lines (41 loc) · 1.42 KB
/
setupFile.js
File metadata and controls
50 lines (41 loc) · 1.42 KB
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
import { JSDOM } from 'jsdom'; // eslint-disable-line import/no-extraneous-dependencies
import { attributes } from './src/DetectAdblock';
process.env.IS_BROWSER = true;
const documentHTML = '<!doctype html><html><head></head><body><div id="page">Page</div></body></html>';
const dom = new JSDOM(documentHTML);
global.document = dom;
global.window = document.defaultView;
const checkHeight = (ctx) => {
const height = window.getComputedStyle(ctx).height;
return height === null || typeof height === 'undefined' || height !== '0px';
};
const checkWidth = (ctx) => {
const width = window.getComputedStyle(ctx).width;
return width === null || typeof width === 'undefined' || width !== '0px';
};
const checkDisplay = (ctx) => {
const display = window.getComputedStyle(ctx).display;
return display === null || typeof display === 'undefined' || display !== 'none';
};
const attributesMappings = {
clientHeight: checkHeight,
clientWidth: checkWidth,
offsetHeight: checkHeight,
offsetLeft: checkWidth,
offsetParent: checkDisplay,
offsetTop: checkHeight,
offsetWidth: checkWidth,
};
const properties = attributes.reduce((prev, cur) =>
({
...prev,
[cur]: {
get: function get() {
return attributesMappings[cur](this);
},
configurable: true,
}
})
, {});
Object.defineProperties(window.HTMLDivElement.prototype, properties);
Object.defineProperties(window.HTMLBodyElement.prototype, properties);