Skip to content

Commit

Permalink
Merge pull request #198 from airbnb/ljharb/file_imports
Browse files Browse the repository at this point in the history
Root-level file exports
  • Loading branch information
lelandrichardson committed Feb 18, 2016
2 parents d8e4262 + f28aa61 commit 4746bc9
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 41 deletions.
1 change: 1 addition & 0 deletions ReactWrapper.js
@@ -0,0 +1 @@
module.exports = require('./build/ReactWrapper').default;
1 change: 1 addition & 0 deletions ShallowWrapper.js
@@ -0,0 +1 @@
module.exports = require('./build/ShallowWrapper').default;
1 change: 1 addition & 0 deletions mount.js
@@ -0,0 +1 @@
module.exports = require('./build/mount').default;
1 change: 1 addition & 0 deletions render.js
@@ -0,0 +1 @@
module.exports = require('./build/render').default;
1 change: 1 addition & 0 deletions shallow.js
@@ -0,0 +1 @@
module.exports = require('./build/shallow').default;
52 changes: 11 additions & 41 deletions src/index.js
@@ -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,
};
11 changes: 11 additions & 0 deletions src/mount.js
@@ -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);
}
19 changes: 19 additions & 0 deletions src/render.js
@@ -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();
}
11 changes: 11 additions & 0 deletions src/shallow.js
@@ -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);
}

0 comments on commit 4746bc9

Please sign in to comment.