Skip to content

Commit

Permalink
Stub local and session storage in JSDOM (#7516)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanhamley authored and Asheem Mamoowala committed Oct 31, 2018
1 parent 782d705 commit f86b13f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"gl": "^4.0.1",
"glob": "^7.0.3",
"is-builtin-module": "^1.0.0",
"jsdom": "11.11.0",
"jsdom": "^11.11.0",
"json-stringify-pretty-compact": "^1.0.4",
"jsonwebtoken": "^8.3.0",
"mock-geolocation": "^1.0.11",
Expand Down
7 changes: 7 additions & 0 deletions src/util/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ function restore(): Window {
virtualConsole: new jsdom.VirtualConsole().sendTo(console)
});

// Delete local and session storage from JSDOM and stub them out with a warning log
// Accessing these properties during extend() produces an error in Node environments
// See https://github.com/mapbox/mapbox-gl-js/pull/7455 for discussion
delete window.localStorage;
delete window.sessionStorage;
window.localStorage = window.sessionStorage = () => console.log('Local and session storage not available in Node. Use a stub implementation if needed for testing.');

window.devicePixelRatio = 1;

window.requestAnimationFrame = function(callback) {
Expand Down

0 comments on commit f86b13f

Please sign in to comment.