Skip to content

Commit

Permalink
Fix: Update jsdom to v12.1.0
Browse files Browse the repository at this point in the history
* Update to latest `jsdom` version.
* Remove `@types/jsdom` to avoid TypeScript problems.
* Enable `includeNodeLocations` to jsdom.
* Add polyfills to increase compatibility.

- - - - - - - - - - - - - - - - - - - - - - - - - - -

Fix #163
Fix #1289
Fix #1223
  • Loading branch information
sarvaje authored and molant committed Oct 2, 2018
1 parent 8b11b89 commit bd6f502
Show file tree
Hide file tree
Showing 10 changed files with 441 additions and 340 deletions.
6 changes: 4 additions & 2 deletions packages/connector-jsdom/package.json
Expand Up @@ -9,8 +9,10 @@
"dependencies": {
"@hint/utils-connector-tools": "^1.0.5",
"canvas-prebuilt": "^1.6.11",
"jsdom": "^11.12.0",
"node-pre-gyp": "^0.11.0"
"jsdom": "^12.1.0",
"mutationobserver-shim": "^0.3.2",
"node-pre-gyp": "^0.11.0",
"whatwg-fetch": "^2.0.4"
},
"description": "hint connector for JSDOM",
"devDependencies": {
Expand Down
34 changes: 34 additions & 0 deletions packages/connector-jsdom/src/before-parse.ts
@@ -0,0 +1,34 @@
/**
* @fileoverview polyfills for jsdom.
*
*/
import { URL } from 'url';
import * as vm from 'vm';
import * as path from 'path';

import * as jsdomutils from 'jsdom/lib/jsdom/living/generated/utils';

import readFile from 'hint/dist/src/lib/utils/fs/read-file';

export const beforeParse = (finalHref) => {
return (window) => {
const mutationObserverPolyfill = readFile(require.resolve('mutationobserver-shim'));
const customElementsPolyfill = readFile(path.join(__dirname, 'polyfills', 'custom-elements.min.js'));

const mutationScript: vm.Script = new vm.Script(mutationObserverPolyfill);
const customElementsScript: vm.Script = new vm.Script(customElementsPolyfill);

mutationScript.runInContext(jsdomutils.implForWrapper(window.document)._global);
customElementsScript.runInContext(jsdomutils.implForWrapper(window.document)._global);

window.document.domain = new URL(finalHref).host;

/* istanbul ignore next */
window.matchMedia = () => {
return { addListener() { } };
};

Object.defineProperty(window.HTMLHtmlElement.prototype, 'clientWidth', { value: 1024 });
Object.defineProperty(window.HTMLHtmlElement.prototype, 'clientHeight', { value: 768 });
};
};

0 comments on commit bd6f502

Please sign in to comment.