-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] Upgrade
@mui/monorepo
(mui#4149)
- Loading branch information
1 parent
37766c8
commit 3a507bf
Showing
3 changed files
with
72 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
const { JSDOM } = require('jsdom'); | ||
|
||
// We can use jsdom-global at some point if maintaining these lists is a burden. | ||
const whitelist = [ | ||
// used by React's experimental cache API | ||
// Always including it to reduce churn when switching between React builds | ||
'AbortController', | ||
// required for fake getComputedStyle | ||
'CSSStyleDeclaration', | ||
'Element', | ||
'Event', | ||
'TouchEvent', | ||
'Image', | ||
'HTMLElement', | ||
'HTMLInputElement', | ||
'Node', | ||
'Performance', | ||
'document', | ||
]; | ||
const blacklist = ['sessionStorage', 'localStorage']; | ||
|
||
function createDOM() { | ||
const dom = new JSDOM('', { | ||
pretendToBeVisual: true, | ||
}); | ||
global.window = dom.window; | ||
// Not yet supported: https://github.com/jsdom/jsdom/issues/2152 | ||
class Touch { | ||
constructor(instance) { | ||
this.instance = instance; | ||
} | ||
|
||
get identifier() { | ||
return this.instance.identifier; | ||
} | ||
|
||
get pageX() { | ||
return this.instance.pageX; | ||
} | ||
|
||
get pageY() { | ||
return this.instance.pageY; | ||
} | ||
|
||
get clientX() { | ||
return this.instance.clientX; | ||
} | ||
|
||
get clientY() { | ||
return this.instance.clientY; | ||
} | ||
} | ||
global.window.Touch = Touch; | ||
|
||
global.navigator = { | ||
userAgent: 'node.js', | ||
}; | ||
|
||
Object.keys(dom.window) | ||
.filter((key) => !blacklist.includes(key)) | ||
.concat(whitelist) | ||
.forEach((key) => { | ||
if (typeof global[key] === 'undefined') { | ||
global[key] = dom.window[key]; | ||
} | ||
}); | ||
} | ||
|
||
module.exports = createDOM; |
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