Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shallow renderer and test utils bundles #9426

Merged
merged 37 commits into from
Apr 19, 2017
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
02129cb
Added react-dom/test-utils target
Apr 13, 2017
a3e4d67
Removed level of indirection for checkPropTypes
Apr 13, 2017
85e338b
Updated Rollup bundle for test-utils
Apr 13, 2017
e9f542f
Cleaned up test-utils bundle slightly by removing unnecessary fb-spec…
Apr 13, 2017
b984bcf
Initial pass at building a shallow renderer on top of react-test-rend…
Apr 14, 2017
3dddc26
Fixed top-level test comparison by wrapping output in ReactElement
Apr 14, 2017
713ed38
Added context rendering support to shallow renderer
Apr 14, 2017
579e7c9
Wordsmithing, minor cleanup
Apr 14, 2017
b14307b
Don't run injections in stack ReactTestRenderer factory function
Apr 14, 2017
23a196d
Disabled shallow rendering tests for stack since there is no stack-fr…
Apr 14, 2017
bd205a9
Linting and prettier
Apr 14, 2017
b091278
Flow fixes
Apr 14, 2017
631352d
Tidying up the react-test-renderer/shallow bundle
Apr 14, 2017
39d3b1e
Fixed test-utils bundle not to include duplicate react-dom code
Apr 14, 2017
1ad9166
Shallow renderer no longer inlines ReactTestRenderer
Apr 14, 2017
45fded4
Added production mode error for shallow renderer
Apr 14, 2017
ec069f4
Added react-test-renderer stub for testing
Apr 14, 2017
037bda9
Tightened up check for ShallowRendererWrapper type
Apr 15, 2017
c65a6d0
Explicit error if test renderer is used in production mode
Apr 15, 2017
a6c8ed8
Reverted modifications to results.json
Apr 15, 2017
c76235b
Moved ReactTestUtils from src/test to src/renderers/dom/test
Apr 15, 2017
f4b4c36
Added test to verify shallow renderer is shallow to ReactTestUtils-test
Apr 16, 2017
e71493d
New ReactShallowRenderer implementation
Apr 17, 2017
e1d3ded
Properly handle context when setState() is called
Apr 17, 2017
7db69a5
Support for shouldComponentUpdate; added tests for lifecycle hooks
Apr 17, 2017
9537e94
Shallow renderer properly tracks new state for componentWill* and sho…
Apr 17, 2017
4012acb
Shallow renderer passes props+context to functional component
Apr 17, 2017
fe1ca9f
Trimmed some unnecessary paths from bundle
Apr 18, 2017
85213e9
Udpate instance.props when sCU returns false
Apr 18, 2017
ac0cc8e
Shallow renderer updates based on Dan's PR feedback:
Apr 18, 2017
35ae167
Explicitly set instance.updater after construction
Apr 18, 2017
4f15cba
Updated lifecycles tests and behavior to mirror 15.x shallow renderer
Apr 19, 2017
e8ef8fa
Shallow renderer setState() supports updater function. Also converted…
Apr 19, 2017
bf0583b
Better handle setState() calls from cWM or cWRP
Apr 19, 2017
fc1c6f9
Shallow renderer preserves state for cloned element
Apr 19, 2017
50793d4
TestUtils use batchedUpdates from ReactDOM instead of loading separately
Apr 19, 2017
5710088
Updated fiber passing tests
Apr 19, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/react-dom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"README.md",
"index.js",
"server.js",
"test-utils.js",
"cjs/",
"umd/"
],
Expand Down
7 changes: 7 additions & 0 deletions packages/react-dom/test-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
throw Error('test-utils is not available in production mode.');
} else {
module.exports = require('./cjs/react-dom-test-utils.development');
}
6 changes: 5 additions & 1 deletion packages/react-test-renderer/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
'use strict';

module.exports = require('./cjs/react-test-renderer.development');
if (process.env.NODE_ENV === 'production') {
throw Error('test renderer is not available in production mode.');
} else {
module.exports = require('./cjs/react-test-renderer.development');
}
1 change: 1 addition & 0 deletions packages/react-test-renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"PATENTS",
"README.md",
"index.js",
"shallow.js",
"cjs/"
]
}
7 changes: 7 additions & 0 deletions packages/react-test-renderer/shallow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
throw Error('shallow renderer is not available in production mode.');
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also throw for the main test renderer entry point then?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or should we create prod versions of all of them? I don't see benefit but somebody might come up with a use case. Maybe just worth keeping in mind.

Copy link
Contributor Author

@bvaughn bvaughn Apr 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or should we create prod versions of all of them?

I don't see the value of this, and it would cause problems with __DEV__ only things like the non-enumerable _owner attribute.

I'll throw in the main test renderer too, sure.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gaearon @bvaughn I'm having a problem with these lines: I'm using enzyme and it uses shallow rendering, for tests, while NODE_ENV is set to production. So my tests are failing because of this.

module.exports = require('./cjs/react-test-renderer-shallow.development');
}
54 changes: 28 additions & 26 deletions scripts/fiber/tests-passing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,34 @@ src/renderers/dom/shared/wrappers/__tests__/ReactDOMTextarea-test.js
* should warn if value is null
* should warn if value and defaultValue are specified

src/renderers/dom/test/__tests__/ReactTestUtils-test.js
* should only render 1 level deep
* should have shallow rendering
* should shallow render a functional component
* should throw for invalid elements
* should have shallow unmounting
* can shallow render to null
* can shallow render with a ref
* lets you update shallowly rendered components
* can access the mounted component instance
* can shallowly render components with contextTypes
* can shallowly render components with ref as function
* can setState in componentWillMount when shallow rendering
* can pass context when shallowly rendering
* can fail context when shallowly rendering
* should warn about propTypes (but only once)
* can scryRenderedDOMComponentsWithClass with TextComponent
* can scryRenderedDOMComponentsWithClass with className contains \n
* can scryRenderedDOMComponentsWithClass with multiple classes
* traverses children in the correct order
* should support injected wrapper components as DOM components
* should change the value of an input field
* should change the value of an input field in a component
* should throw when attempting to use ReactTestUtils.Simulate with shallow rendering
* should not warn when simulating events with extra properties
* can scry with stateless components involved
* should set the type of the event

src/renderers/native/__tests__/ReactNativeAttributePayload-test.js
* should work with simple example
* should skip fields that are equal
Expand Down Expand Up @@ -1868,32 +1896,6 @@ src/shared/utils/__tests__/PooledClass-test.js
src/shared/utils/__tests__/reactProdInvariant-test.js
* should throw with the correct number of `%s`s in the URL

src/test/__tests__/ReactTestUtils-test.js
* should have shallow rendering
* should shallow render a functional component
* should throw for invalid elements
* should have shallow unmounting
* can shallow render to null
* can shallow render with a ref
* lets you update shallowly rendered components
* can access the mounted component instance
* can shallowly render components with contextTypes
* can shallowly render components with ref as function
* can setState in componentWillMount when shallow rendering
* can pass context when shallowly rendering
* can fail context when shallowly rendering
* can scryRenderedDOMComponentsWithClass with TextComponent
* can scryRenderedDOMComponentsWithClass with className contains \n
* can scryRenderedDOMComponentsWithClass with multiple classes
* traverses children in the correct order
* should support injected wrapper components as DOM components
* should change the value of an input field
* should change the value of an input field in a component
* should throw when attempting to use ReactTestUtils.Simulate with shallow rendering
* should not warn when simulating events with extra properties
* can scry with stateless components involved
* should set the type of the event

src/test/__tests__/reactComponentExpect-test.js
* should match composite components
* should match empty DOM components
Expand Down
74 changes: 63 additions & 11 deletions scripts/rollup/bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ const bundles = [
paths: [
'src/renderers/dom/**/*.js',
'src/renderers/shared/**/*.js',
'src/test/**/*.js', // ReactTestUtils is currently very coupled to DOM.

'src/isomorphic/classic/types/checkPropTypes.js',
'src/ReactVersion.js',
'src/shared/**/*.js',
],
Expand All @@ -118,9 +116,41 @@ const bundles = [
paths: [
'src/renderers/dom/**/*.js',
'src/renderers/shared/**/*.js',
'src/test/**/*.js', // ReactTestUtils is currently very coupled to DOM.

'src/isomorphic/classic/types/checkPropTypes.js',
'src/ReactVersion.js',
'src/shared/**/*.js',
],
},
{
babelOpts: babelOptsReact,
bundleTypes: [FB_DEV, NODE_DEV],
config: {
destDir: 'build/',
globals: {
react: 'React',
},
moduleName: 'ReactTestUtils',
sourceMap: false,
},
entry: 'src/renderers/dom/test/ReactTestUtils',
externals: [
'prop-types',
'prop-types/checkPropTypes',
'react',
'react-dom',
'react-test-renderer', // TODO (bvaughn) Remove this dependency before 16.0.0
],
fbEntry: 'src/renderers/dom/test/ReactTestUtils',
hasteName: 'ReactTestUtils',
isRenderer: true,
label: 'test-utils',
manglePropertiesOnProd: false,
name: 'react-dom/test-utils',
paths: [
'src/renderers/dom/test/**/*.js',
'src/renderers/shared/**/*.js',
'src/renderers/testing/**/*.js', // TODO (bvaughn) Remove this dependency before 16.0.0

'src/ReactVersion.js',
'src/shared/**/*.js',
],
Expand Down Expand Up @@ -151,7 +181,6 @@ const bundles = [
'src/renderers/dom/**/*.js',
'src/renderers/shared/**/*.js',

'src/isomorphic/classic/types/checkPropTypes.js',
'src/ReactVersion.js',
'src/shared/**/*.js',
],
Expand Down Expand Up @@ -190,7 +219,6 @@ const bundles = [
'src/renderers/art/**/*.js',
'src/renderers/shared/**/*.js',

'src/isomorphic/classic/types/checkPropTypes.js',
'src/ReactVersion.js',
'src/shared/**/*.js',
],
Expand Down Expand Up @@ -226,7 +254,6 @@ const bundles = [
'src/renderers/art/**/*.js',
'src/renderers/shared/**/*.js',

'src/isomorphic/classic/types/checkPropTypes.js',
'src/ReactVersion.js',
'src/shared/**/*.js',
],
Expand Down Expand Up @@ -328,12 +355,10 @@ const bundles = [
'src/renderers/shared/**/*.js',
'src/renderers/testing/**/*.js',

'src/isomorphic/classic/types/checkPropTypes.js',
'src/ReactVersion.js',
'src/shared/**/*.js',
],
},

{
babelOpts: babelOptsReact,
bundleTypes: [FB_DEV],
Expand All @@ -355,7 +380,35 @@ const bundles = [
'src/renderers/shared/**/*.js',
'src/renderers/testing/**/*.js',

'src/isomorphic/classic/types/checkPropTypes.js',
'src/ReactVersion.js',
'src/shared/**/*.js',
],
},
{
babelOpts: babelOptsReact,
bundleTypes: [FB_DEV, NODE_DEV],
config: {
destDir: 'build/',
moduleName: 'ReactShallowRenderer',
sourceMap: false,
},
entry: 'src/renderers/testing/ReactShallowRenderer',
externals: [
'react-dom',
'prop-types/checkPropTypes',
'react-test-renderer',
],
fbEntry: 'src/renderers/testing/ReactShallowRenderer',
hasteName: 'ReactShallowRenderer',
isRenderer: true,
label: 'shallow-renderer',
manglePropertiesOnProd: false,
name: 'react-test-renderer/shallow',
paths: [
'src/renderers/native/**/*.js',
'src/renderers/shared/**/*.js',
'src/renderers/testing/**/*.js',

'src/ReactVersion.js',
'src/shared/**/*.js',
],
Expand Down Expand Up @@ -383,7 +436,6 @@ const bundles = [
'src/renderers/noop/**/*.js',
'src/renderers/shared/**/*.js',

'src/isomorphic/classic/types/checkPropTypes.js',
'src/ReactVersion.js',
'src/shared/**/*.js',
],
Expand Down
18 changes: 0 additions & 18 deletions scripts/rollup/shims/facebook-www/ReactTestUtils.js

This file was deleted.

5 changes: 2 additions & 3 deletions src/fb/ReactDOMFBEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ Object.assign(ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, {

if (__DEV__) {
Object.assign(ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, {
// ReactPerf and ReactTestUtils currently only work with the DOM renderer
// so we expose them from here, but only in DEV mode.
// ReactPerf currently only works with the DOM renderer
// so we expose it here, but only in DEV mode.
ReactPerf: require('ReactPerf'),
ReactTestUtils: require('ReactTestUtils'),
});
}

Expand Down
11 changes: 0 additions & 11 deletions src/fb/ReactDOMFiberFBEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,4 @@ Object.assign(
},
);

if (__DEV__) {
Object.assign(
ReactDOMFiber.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
{
// ReactPerf and ReactTestUtils currently only work with the DOM renderer
// so we expose them from here, but only in DEV mode.
ReactTestUtils: require('ReactTestUtils'),
},
);
}

module.exports = ReactDOMFiber;
6 changes: 3 additions & 3 deletions src/isomorphic/React.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var ReactPropTypes = require('ReactPropTypes');
var ReactVersion = require('ReactVersion');

var onlyChild = require('onlyChild');
var checkPropTypes = require('checkPropTypes');
var checkPropTypes = require('prop-types/checkPropTypes');
var createReactClass = require('createClass');

var createElement = ReactElement.createElement;
Expand Down Expand Up @@ -57,7 +57,7 @@ var React = {
cloneElement: cloneElement,
isValidElement: ReactElement.isValidElement,

// TODO (bvaughn) Remove these getters in 16.0.0-alpha.10
// TODO (bvaughn) Remove these getters before 16.0.0
PropTypes: ReactPropTypes,
checkPropTypes: checkPropTypes,
createClass: createReactClass,
Expand Down Expand Up @@ -100,7 +100,7 @@ if (__DEV__) {
return mixin;
};

// TODO (bvaughn) Remove both of these deprecation warnings in 16.0.0-alpha.10
// TODO (bvaughn) Remove both of these deprecation warnings before 16.0.0
if (canDefineProperty) {
Object.defineProperty(React, 'checkPropTypes', {
get() {
Expand Down
2 changes: 1 addition & 1 deletion src/isomorphic/classic/element/ReactElementValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var getComponentName = require('getComponentName');
var getIteratorFn = require('getIteratorFn');

if (__DEV__) {
var checkPropTypes = require('checkPropTypes');
var checkPropTypes = require('prop-types/checkPropTypes');
var warning = require('fbjs/lib/warning');
var ReactDebugCurrentFrame = require('ReactDebugCurrentFrame');
var {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var MyComponent;

function resetWarningCache() {
jest.resetModules();
checkPropTypes = require('checkPropTypes');
checkPropTypes = require('prop-types/checkPropTypes');
}

function getPropTypeWarningMessage(propTypes, object, componentName) {
Expand Down
14 changes: 0 additions & 14 deletions src/isomorphic/classic/types/checkPropTypes.js

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/renderers/dom/ReactDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ var ReactDOM = {
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: {
// For TapEventPlugin which is popular in open source
EventPluginHub: require('EventPluginHub'),
// Used by test-utils
EventPluginRegistry: require('EventPluginRegistry'),
EventPropagators: require('EventPropagators'),
ReactControlledComponent: require('ReactControlledComponent'),
ReactDOMComponentTree,
ReactBrowserEventEmitter: require('ReactBrowserEventEmitter'),
},
};

Expand Down
6 changes: 6 additions & 0 deletions src/renderers/dom/fiber/ReactDOMFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,12 @@ var ReactDOM = {
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: {
// For TapEventPlugin which is popular in open source
EventPluginHub: require('EventPluginHub'),
// Used by test-utils
EventPluginRegistry: require('EventPluginRegistry'),
EventPropagators: require('EventPropagators'),
ReactControlledComponent,
ReactDOMComponentTree,
ReactBrowserEventEmitter,
},
};

Expand Down
Loading