-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathglobals.js
51 lines (41 loc) · 1.2 KB
/
globals.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
/** @flow
* @format */
/**
* External dependencies
*/
import jsdom from 'jsdom-jscore';
import jsdomLevel1Core from 'jsdom-jscore/lib/jsdom/level1/core';
import { nativeLoggingHook } from 'react-native-gutenberg-bridge';
/**
* WordPress dependencies
*/
import { createElement } from '@wordpress/element';
/**
* Internal dependencies
*/
// Import for side-effects: Patches for jsdom-jscore, details commented in file.
import './jsdom-patches';
global.wp = {
element: {
createElement, // load the element creation function, needed by Gutenberg-web
},
};
const doc = jsdom.html( '', null, null );
// inject a simple version of the missing createHTMLDocument method that `hpq` depends on
doc.implementation.createHTMLDocument = function( html ) {
return jsdom.html( html, null, null );
};
// `hpq` depends on `document` be available globally
global.document = doc;
if ( ! global.window.Node ) {
global.window.Node = jsdomLevel1Core.dom.level1.core.Node;
}
if ( ! global.window.matchMedia ) {
global.window.matchMedia = () => ( {
matches: false,
addListener: () => {},
removeListener: () => {},
} );
}
// Leverages existing console polyfill from react-native
global.nativeLoggingHook = nativeLoggingHook;