-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli): Expose whole JSDOM API to global scope (#147)
* fix(cli): Expose whole JSDOM API to global scope * Add missing package.json update * Remove outdated assertion from test
- Loading branch information
Showing
6 changed files
with
29 additions
and
123 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
10 changes: 4 additions & 6 deletions
10
packages/cli/src/steps/analyze/setupFakeBrowserEnvironment.ts
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 |
---|---|---|
@@ -1,21 +1,19 @@ | ||
import * as React from 'react'; | ||
import * as ReactDOM from 'react-dom'; | ||
import { JSDOM } from 'jsdom'; | ||
|
||
const jsDomGlobal = require('jsdom-global'); | ||
|
||
export function setupFakeBrowserEnvironment(internalGlobal: any) { | ||
const componentModules = new Map<string, Record<string, any>>(); | ||
|
||
const { window } = new JSDOM('<body></body>'); | ||
const cleanup = jsDomGlobal(); | ||
// We need to extend global here, so we disable no-param-reassign rule here | ||
/* eslint-disable no-param-reassign */ | ||
internalGlobal.window = window; | ||
internalGlobal.react = React; | ||
internalGlobal.reactDom = ReactDOM; | ||
internalGlobal.document = window.document; | ||
internalGlobal.registerComponent = (moduleName: string, moduleContent) => { | ||
componentModules.set(moduleName, moduleContent); | ||
}; | ||
/* eslint-enable no-param-reassign */ | ||
|
||
return componentModules; | ||
return { componentModules, cleanup }; | ||
} |
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
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