Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
10 changed files
with
441 additions
and
340 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }); | ||
}; | ||
}; |
Oops, something went wrong.