Skip to content

Commit 66f2097

Browse files
authored
Shallow renderer and test utils bundles (#9426)
Shallow renderer and test utils bundles Adds new bundles introduced with React 15.5 release to master (and 16 alpha) react-dom/test-utils: This new bundle contains what used to be react-addons-test-utils. This bundle shares things from react-dom rather than duplicates them. A temporary createRenderer method has been left behind as a way to access the new shallow renderer. This is for the ReactNative release cycle only and should be going away before the final release. react-test-renderer/shallow: This new shallow renderer is almost entirely stand-alone (in that it doesn't use the React reconciler or scheduler). The only touch points are ReactElement and prop/context validation. This renderer is stack and fiber compatible.
1 parent 53dbb19 commit 66f2097

File tree

24 files changed

+755
-341
lines changed

24 files changed

+755
-341
lines changed

packages/react-dom/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"README.md",
2828
"index.js",
2929
"server.js",
30+
"test-utils.js",
3031
"cjs/",
3132
"umd/"
3233
],

packages/react-dom/test-utils.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
if (process.env.NODE_ENV === 'production') {
4+
throw Error('test-utils is not available in production mode.');
5+
} else {
6+
module.exports = require('./cjs/react-dom-test-utils.development');
7+
}

packages/react-test-renderer/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
'use strict';
22

3-
module.exports = require('./cjs/react-test-renderer.development');
3+
if (process.env.NODE_ENV === 'production') {
4+
throw Error('test renderer is not available in production mode.');
5+
} else {
6+
module.exports = require('./cjs/react-test-renderer.development');
7+
}

packages/react-test-renderer/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"PATENTS",
2727
"README.md",
2828
"index.js",
29+
"shallow.js",
2930
"cjs/"
3031
]
3132
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
if (process.env.NODE_ENV === 'production') {
4+
throw Error('shallow renderer is not available in production mode.');
5+
} else {
6+
module.exports = require('./cjs/react-test-renderer-shallow.development');
7+
}

scripts/fiber/tests-passing.txt

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,6 +1562,41 @@ src/renderers/dom/shared/wrappers/__tests__/ReactDOMTextarea-test.js
15621562
* should warn if value is null
15631563
* should warn if value and defaultValue are specified
15641564

1565+
src/renderers/dom/test/__tests__/ReactTestUtils-test.js
1566+
* should call all of the lifecycle hooks
1567+
* should only render 1 level deep
1568+
* should have shallow rendering
1569+
* should enable shouldComponentUpdate to prevent a re-render
1570+
* should shallow render a functional component
1571+
* should throw for invalid elements
1572+
* should have shallow unmounting
1573+
* can shallow render to null
1574+
* can shallow render with a ref
1575+
* lets you update shallowly rendered components
1576+
* can access the mounted component instance
1577+
* can shallowly render components with contextTypes
1578+
* can shallowly render components with ref as function
1579+
* can setState in componentWillMount when shallow rendering
1580+
* can setState in componentWillReceiveProps when shallow rendering
1581+
* can setState with an updater function
1582+
* can pass context when shallowly rendering
1583+
* should track context across updates
1584+
* can fail context when shallowly rendering
1585+
* should warn about propTypes (but only once)
1586+
* can scryRenderedDOMComponentsWithClass with TextComponent
1587+
* can scryRenderedDOMComponentsWithClass with className contains \n
1588+
* can scryRenderedDOMComponentsWithClass with multiple classes
1589+
* traverses children in the correct order
1590+
* should support injected wrapper components as DOM components
1591+
* should change the value of an input field
1592+
* should change the value of an input field in a component
1593+
* should throw when attempting to use ReactTestUtils.Simulate with shallow rendering
1594+
* should not warn when simulating events with extra properties
1595+
* can scry with stateless components involved
1596+
* should enable rendering of cloned element
1597+
* should set the type of the event
1598+
* should work with renderIntoDocument
1599+
15651600
src/renderers/native/__tests__/ReactNativeAttributePayload-test.js
15661601
* should work with simple example
15671602
* should skip fields that are equal
@@ -1871,32 +1906,6 @@ src/shared/utils/__tests__/PooledClass-test.js
18711906
src/shared/utils/__tests__/reactProdInvariant-test.js
18721907
* should throw with the correct number of `%s`s in the URL
18731908

1874-
src/test/__tests__/ReactTestUtils-test.js
1875-
* should have shallow rendering
1876-
* should shallow render a functional component
1877-
* should throw for invalid elements
1878-
* should have shallow unmounting
1879-
* can shallow render to null
1880-
* can shallow render with a ref
1881-
* lets you update shallowly rendered components
1882-
* can access the mounted component instance
1883-
* can shallowly render components with contextTypes
1884-
* can shallowly render components with ref as function
1885-
* can setState in componentWillMount when shallow rendering
1886-
* can pass context when shallowly rendering
1887-
* can fail context when shallowly rendering
1888-
* can scryRenderedDOMComponentsWithClass with TextComponent
1889-
* can scryRenderedDOMComponentsWithClass with className contains \n
1890-
* can scryRenderedDOMComponentsWithClass with multiple classes
1891-
* traverses children in the correct order
1892-
* should support injected wrapper components as DOM components
1893-
* should change the value of an input field
1894-
* should change the value of an input field in a component
1895-
* should throw when attempting to use ReactTestUtils.Simulate with shallow rendering
1896-
* should not warn when simulating events with extra properties
1897-
* can scry with stateless components involved
1898-
* should set the type of the event
1899-
19001909
src/test/__tests__/reactComponentExpect-test.js
19011910
* should match composite components
19021911
* should match empty DOM components

scripts/rollup/bundles.js

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,7 @@ const bundles = [
8989
paths: [
9090
'src/renderers/dom/**/*.js',
9191
'src/renderers/shared/**/*.js',
92-
'src/test/**/*.js', // ReactTestUtils is currently very coupled to DOM.
9392

94-
'src/isomorphic/classic/types/checkPropTypes.js',
9593
'src/ReactVersion.js',
9694
'src/shared/**/*.js',
9795
],
@@ -118,9 +116,41 @@ const bundles = [
118116
paths: [
119117
'src/renderers/dom/**/*.js',
120118
'src/renderers/shared/**/*.js',
121-
'src/test/**/*.js', // ReactTestUtils is currently very coupled to DOM.
122119

123-
'src/isomorphic/classic/types/checkPropTypes.js',
120+
'src/ReactVersion.js',
121+
'src/shared/**/*.js',
122+
],
123+
},
124+
{
125+
babelOpts: babelOptsReact,
126+
bundleTypes: [FB_DEV, NODE_DEV],
127+
config: {
128+
destDir: 'build/',
129+
globals: {
130+
react: 'React',
131+
},
132+
moduleName: 'ReactTestUtils',
133+
sourceMap: false,
134+
},
135+
entry: 'src/renderers/dom/test/ReactTestUtils',
136+
externals: [
137+
'prop-types',
138+
'prop-types/checkPropTypes',
139+
'react',
140+
'react-dom',
141+
'react-test-renderer', // TODO (bvaughn) Remove this dependency before 16.0.0
142+
],
143+
fbEntry: 'src/renderers/dom/test/ReactTestUtils',
144+
hasteName: 'ReactTestUtils',
145+
isRenderer: true,
146+
label: 'test-utils',
147+
manglePropertiesOnProd: false,
148+
name: 'react-dom/test-utils',
149+
paths: [
150+
'src/renderers/dom/test/**/*.js',
151+
'src/renderers/shared/**/*.js',
152+
'src/renderers/testing/**/*.js', // TODO (bvaughn) Remove this dependency before 16.0.0
153+
124154
'src/ReactVersion.js',
125155
'src/shared/**/*.js',
126156
],
@@ -151,7 +181,6 @@ const bundles = [
151181
'src/renderers/dom/**/*.js',
152182
'src/renderers/shared/**/*.js',
153183

154-
'src/isomorphic/classic/types/checkPropTypes.js',
155184
'src/ReactVersion.js',
156185
'src/shared/**/*.js',
157186
],
@@ -190,7 +219,6 @@ const bundles = [
190219
'src/renderers/art/**/*.js',
191220
'src/renderers/shared/**/*.js',
192221

193-
'src/isomorphic/classic/types/checkPropTypes.js',
194222
'src/ReactVersion.js',
195223
'src/shared/**/*.js',
196224
],
@@ -226,7 +254,6 @@ const bundles = [
226254
'src/renderers/art/**/*.js',
227255
'src/renderers/shared/**/*.js',
228256

229-
'src/isomorphic/classic/types/checkPropTypes.js',
230257
'src/ReactVersion.js',
231258
'src/shared/**/*.js',
232259
],
@@ -328,12 +355,10 @@ const bundles = [
328355
'src/renderers/shared/**/*.js',
329356
'src/renderers/testing/**/*.js',
330357

331-
'src/isomorphic/classic/types/checkPropTypes.js',
332358
'src/ReactVersion.js',
333359
'src/shared/**/*.js',
334360
],
335361
},
336-
337362
{
338363
babelOpts: babelOptsReact,
339364
bundleTypes: [FB_DEV],
@@ -355,11 +380,32 @@ const bundles = [
355380
'src/renderers/shared/**/*.js',
356381
'src/renderers/testing/**/*.js',
357382

358-
'src/isomorphic/classic/types/checkPropTypes.js',
359383
'src/ReactVersion.js',
360384
'src/shared/**/*.js',
361385
],
362386
},
387+
{
388+
babelOpts: babelOptsReact,
389+
bundleTypes: [FB_DEV, NODE_DEV],
390+
config: {
391+
destDir: 'build/',
392+
moduleName: 'ReactShallowRenderer',
393+
sourceMap: false,
394+
},
395+
entry: 'src/renderers/testing/ReactShallowRenderer',
396+
externals: [
397+
'react-dom',
398+
'prop-types/checkPropTypes',
399+
'react-test-renderer',
400+
],
401+
fbEntry: 'src/renderers/testing/ReactShallowRenderer',
402+
hasteName: 'ReactShallowRenderer',
403+
isRenderer: true,
404+
label: 'shallow-renderer',
405+
manglePropertiesOnProd: false,
406+
name: 'react-test-renderer/shallow',
407+
paths: ['src/renderers/shared/**/*.js', 'src/renderers/testing/**/*.js'],
408+
},
363409

364410
/******* React Noop Renderer (used only for fixtures/fiber-debugger) *******/
365411
{
@@ -383,7 +429,6 @@ const bundles = [
383429
'src/renderers/noop/**/*.js',
384430
'src/renderers/shared/**/*.js',
385431

386-
'src/isomorphic/classic/types/checkPropTypes.js',
387432
'src/ReactVersion.js',
388433
'src/shared/**/*.js',
389434
],

scripts/rollup/shims/facebook-www/ReactTestUtils.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/fb/ReactDOMFBEntry.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ Object.assign(ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, {
4343

4444
if (__DEV__) {
4545
Object.assign(ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, {
46-
// ReactPerf and ReactTestUtils currently only work with the DOM renderer
47-
// so we expose them from here, but only in DEV mode.
46+
// ReactPerf currently only works with the DOM renderer
47+
// so we expose it here, but only in DEV mode.
4848
ReactPerf: require('ReactPerf'),
49-
ReactTestUtils: require('ReactTestUtils'),
5049
});
5150
}
5251

src/fb/ReactDOMFiberFBEntry.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,4 @@ Object.assign(
4545
},
4646
);
4747

48-
if (__DEV__) {
49-
Object.assign(
50-
ReactDOMFiber.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
51-
{
52-
// ReactPerf and ReactTestUtils currently only work with the DOM renderer
53-
// so we expose them from here, but only in DEV mode.
54-
ReactTestUtils: require('ReactTestUtils'),
55-
},
56-
);
57-
}
58-
5948
module.exports = ReactDOMFiber;

0 commit comments

Comments
 (0)