Skip to content

Commit

Permalink
Updated Rollup bundle for test-utils
Browse files Browse the repository at this point in the history
* Moved test-utils into react-dom package
* Added ReactTestUtilsFBEntry module (though it doesn't really do anything at the moment)
* Replaced ReactDOM references with react-dom to avoid duplicating code
  • Loading branch information
Brian Vaughn committed Apr 13, 2017
1 parent aa88a15 commit ab65d2b
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 47 deletions.
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
5 changes: 5 additions & 0 deletions packages/react-dom/test-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

if (process.env.NODE_ENV !== 'production') {
module.exports = require('./cjs/test-utils.development.js');
}
16 changes: 11 additions & 5 deletions scripts/rollup/bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const bundles = [
},
{
babelOpts: babelOptsReact,
bundleTypes: [NODE_DEV],
bundleTypes: [FB_DEV, NODE_DEV],
config: {
destDir: 'build/',
globals: {
Expand All @@ -135,14 +135,20 @@ const bundles = [
sourceMap: false,
},
entry: 'src/test/ReactTestUtils.js',
externals: ['prop-types', 'prop-types/checkPropTypes', 'react'],
externals: [
'prop-types',
'prop-types/checkPropTypes',
'react',
'react-dom',
'react-dom/test-utils',
],
fbEntry: 'src/fb/ReactTestUtilsFBEntry.js',
hasteName: 'ReactTestUtils',
isRenderer: false,
label: 'react-test-utils',
label: 'test-utils',
manglePropertiesOnProd: false,
name: 'react-test-utils',
name: 'react-dom/test-utils',
paths: [
'src/renderers/dom/**/*.js',
'src/renderers/shared/**/*.js',
'src/test/**/*.js', // ReactTestUtils is currently very coupled to DOM.

Expand Down
40 changes: 24 additions & 16 deletions scripts/rollup/results.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
"gzip": 5761
},
"react-dom.development.js (UMD_DEV)": {
"size": 583148,
"gzip": 134526
"size": 583284,
"gzip": 134555
},
"react-dom.production.min.js (UMD_PROD)": {
"size": 120740,
"gzip": 38094
"size": 120793,
"gzip": 38119
},
"react-dom-server.development.js (UMD_DEV)": {
"size": 495516,
Expand Down Expand Up @@ -50,28 +50,28 @@
"gzip": 9248
},
"ReactDOMStack-dev.js (FB_DEV)": {
"size": 522721,
"gzip": 124723
"size": 492312,
"gzip": 117399
},
"ReactDOMStack-prod.js (FB_PROD)": {
"size": 352776,
"gzip": 84675
"size": 352924,
"gzip": 84697
},
"react-dom.development.js (NODE_DEV)": {
"size": 542144,
"gzip": 125150
"size": 542280,
"gzip": 125179
},
"react-dom.production.min.js (NODE_PROD)": {
"size": 116925,
"gzip": 36732
"size": 116978,
"gzip": 36758
},
"ReactDOMFiber-dev.js (FB_DEV)": {
"size": 797189,
"gzip": 184111
"size": 543121,
"gzip": 125573
},
"ReactDOMFiber-prod.js (FB_PROD)": {
"size": 407613,
"gzip": 93586
"size": 407761,
"gzip": 93608
},
"react-dom-server.development.js (NODE_DEV)": {
"size": 445547,
Expand Down Expand Up @@ -140,6 +140,14 @@
"react-test-utils.development.js (NODE_DEV)": {
"size": 510240,
"gzip": 122093
},
"react-dom-test-utils.development.js (NODE_DEV)": {
"size": 78532,
"gzip": 19766
},
"ReactTestUtils-dev.js (FB_DEV)": {
"size": 528,
"gzip": 328
}
}
}
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;
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule ReactTestUtils
*/

'use strict';

const {
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
} = require('ReactDOM-fb');
var ReactTestUtils = require('react-dom/test-utils');

module.exports = __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactTestUtils;
module.exports = ReactTestUtils;
3 changes: 3 additions & 0 deletions src/renderers/dom/ReactDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ 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
ReactDOMComponentTree,
ReactBrowserEventEmitter: require('ReactBrowserEventEmitter'),
},
};

Expand Down
3 changes: 3 additions & 0 deletions src/renderers/dom/fiber/ReactDOMFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,9 @@ 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
ReactDOMComponentTree,
ReactBrowserEventEmitter,
},
};

Expand Down
16 changes: 10 additions & 6 deletions src/test/ReactTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@ var EventPluginRegistry = require('EventPluginRegistry');
var EventPropagators = require('EventPropagators');
var React = require('react');
var ReactControlledComponent = require('ReactControlledComponent');
var ReactDOM = require('ReactDOM');
var ReactDOMComponentTree = require('ReactDOMComponentTree');
var ReactBrowserEventEmitter = require('ReactBrowserEventEmitter');
var ReactDOM = require('react-dom');
var ReactFiberTreeReflection = require('ReactFiberTreeReflection');
var ReactInstanceMap = require('ReactInstanceMap');
var ReactTypeOfWork = require('ReactTypeOfWork');
var ReactGenericBatching = require('ReactGenericBatching');
var SyntheticEvent = require('SyntheticEvent');
var ReactShallowRenderer = require('ReactShallowRenderer');

var findDOMNode = require('findDOMNode');
var invariant = require('fbjs/lib/invariant');

var {findDOMNode} = ReactDOM;
var {
ReactDOMComponentTree,
ReactBrowserEventEmitter,
} = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;

var topLevelTypes = EventConstants.topLevelTypes;
var {
ClassComponent,
Expand Down Expand Up @@ -403,9 +405,11 @@ var ReactTestUtils = {
};
},

/**
* TODO (bvaughn) Re-add with an export to react-test-renderer/shallow and a message
createRenderer: function() {
return new ReactShallowRenderer();
},
*/

Simulate: null,
SimulateNative: {},
Expand Down

0 comments on commit ab65d2b

Please sign in to comment.