Last active
November 20, 2019 08:51
-
-
Save banyudu/3f11cc4e7c294b68766d80638ec75bf7 to your computer and use it in GitHub Desktop.
Browser polyfill in nodejs
This file contains hidden or 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
const { JSDOM } = require('jsdom') | |
const { window } = new JSDOM('', { | |
url: 'http://localhost/' | |
}) | |
global.window = window | |
for (let item of ['document', 'navigator', 'location', 'localStorage', 'sessionStorage']) { | |
global[item] = window[item] | |
} | |
// other custom properties, rename futureWindowProperties to what you need. | |
Object.defineProperty(window, 'futureWindowProperties', { | |
set: val => { global.futureWindowProperties = val }, | |
get: () => global.futureWindowProperties | |
}) | |
require('matchmedia-polyfill'); | |
require('matchmedia-polyfill/matchMedia.addListener'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment