-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #198 from airbnb/ljharb/file_imports
Root-level file exports
- Loading branch information
Showing
9 changed files
with
57 additions
and
41 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 @@ | ||
module.exports = require('./build/ReactWrapper').default; |
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 @@ | ||
module.exports = require('./build/ShallowWrapper').default; |
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 @@ | ||
module.exports = require('./build/mount').default; |
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 @@ | ||
module.exports = require('./build/render').default; |
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 @@ | ||
module.exports = require('./build/shallow').default; |
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,44 +1,14 @@ | ||
import cheerio from 'cheerio'; | ||
import ReactWrapper from './ReactWrapper'; | ||
import ShallowWrapper from './ShallowWrapper'; | ||
import { renderToStaticMarkup } from './react-compat'; | ||
|
||
/** | ||
* Mounts and renders a react component into the document and provides a testing wrapper around it. | ||
* | ||
* @param node | ||
* @returns {ReactWrapper} | ||
*/ | ||
export function mount(node, options) { | ||
return new ReactWrapper(node, null, options); | ||
} | ||
|
||
/** | ||
* Shallow renders a react component and provides a testing wrapper around it. | ||
* | ||
* @param node | ||
* @returns {ShallowWrapper} | ||
*/ | ||
export function shallow(node, options) { | ||
return new ShallowWrapper(node, null, options); | ||
} | ||
|
||
/** | ||
* Renders a react component into static HTML and provides a cheerio wrapper around it. This is | ||
* somewhat asymmetric with `mount` and `shallow`, which don't use any external libraries, but | ||
* Cheerio's API is pretty close to what we actually want and has a significant amount of utility | ||
* that would be recreating the wheel if we didn't use it. | ||
* | ||
* I think there are a lot of good use cases to use `render` instead of `shallow` or `mount`, and | ||
* thus I'd like to keep this API in here even though it's not really "ours". | ||
* | ||
* @param node | ||
* @returns {Cheerio} | ||
*/ | ||
export function render(node) { | ||
const html = renderToStaticMarkup(node); | ||
return cheerio.load(html).root(); | ||
} | ||
|
||
export { ShallowWrapper as ShallowWrapper }; | ||
export { ReactWrapper as ReactWrapper }; | ||
import mount from './mount'; | ||
import shallow from './shallow'; | ||
import render from './render'; | ||
|
||
export { | ||
render, | ||
shallow, | ||
mount, | ||
ShallowWrapper, | ||
ReactWrapper, | ||
}; |
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,11 @@ | ||
import ReactWrapper from './ReactWrapper'; | ||
|
||
/** | ||
* Mounts and renders a react component into the document and provides a testing wrapper around it. | ||
* | ||
* @param node | ||
* @returns {ReactWrapper} | ||
*/ | ||
export default function mount(node, options) { | ||
return new ReactWrapper(node, null, options); | ||
} |
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,19 @@ | ||
import { renderToStaticMarkup } from './react-compat'; | ||
import cheerio from 'cheerio'; | ||
|
||
/** | ||
* Renders a react component into static HTML and provides a cheerio wrapper around it. This is | ||
* somewhat asymmetric with `mount` and `shallow`, which don't use any external libraries, but | ||
* Cheerio's API is pretty close to what we actually want and has a significant amount of utility | ||
* that would be recreating the wheel if we didn't use it. | ||
* | ||
* I think there are a lot of good use cases to use `render` instead of `shallow` or `mount`, and | ||
* thus I'd like to keep this API in here even though it's not really "ours". | ||
* | ||
* @param node | ||
* @returns {Cheerio} | ||
*/ | ||
export default function render(node) { | ||
const html = renderToStaticMarkup(node); | ||
return cheerio.load(html).root(); | ||
} |
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,11 @@ | ||
import ShallowWrapper from './ShallowWrapper'; | ||
|
||
/** | ||
* Shallow renders a react component and provides a testing wrapper around it. | ||
* | ||
* @param node | ||
* @returns {ShallowWrapper} | ||
*/ | ||
export default function shallow(node, options) { | ||
return new ShallowWrapper(node, null, options); | ||
} |