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

Convert the rest of react-dom and react-test-renderer to Named Exports #18145

Merged
merged 1 commit into from
Feb 27, 2020

Conversation

sebmarkbage
Copy link
Collaborator

Nothing interesting here except that ReactShallowRenderer currently exports a class with a static method instead of an object.

I think the public API is probably just meant to be createRenderer but currently the whole class is exposed. So this means that we have to keep it as default export. We could potentially also expose a named export for createRenderer but that's going to cause compatibility issues.

So I'm just going to make that export default.

Unfortunately Rollup and Babel (which powers Jest) disagree on how to import this. So to make it work I had to move the jest tests to imports.

This doesn't work with module resetting. Some tests weren't doing that anyway and the rest is just testing ReactShallowRenderer so meh.

Also see #18144

@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Feb 27, 2020
@codesandbox-ci
Copy link

codesandbox-ci bot commented Feb 27, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 5c75e3f:

Sandbox Source
dark-cloud-3mwwl Configuration

@sizebot
Copy link

sizebot commented Feb 27, 2020

Details of bundled changes.

Comparing: 60016c4...5c75e3f

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom-unstable-fizz.browser.development.js -7.0% -7.1% 3.61 KB 3.35 KB 1.37 KB 1.27 KB UMD_DEV
react-dom-unstable-fizz.browser.production.min.js -1.2% -1.3% 1.2 KB 1.19 KB 708 B 699 B UMD_PROD
react-dom-test-utils.development.js +0.2% -0.0% 53.69 KB 53.78 KB 14.01 KB 14.01 KB UMD_DEV
react-dom-server.browser.development.js -0.2% -0.3% 138.16 KB 137.89 KB 35.19 KB 35.08 KB UMD_DEV
react-dom-test-utils.production.min.js -2.3% 🔺+0.3% 11.22 KB 10.96 KB 4.16 KB 4.17 KB UMD_PROD
react-dom-server.browser.production.min.js -0.0% -0.1% 20.45 KB 20.44 KB 7.49 KB 7.49 KB UMD_PROD
react-dom-test-utils.development.js +0.1% -0.2% 49.52 KB 49.56 KB 13.55 KB 13.52 KB NODE_DEV
react-dom-server.browser.development.js -0.2% -0.4% 127.45 KB 127.17 KB 33.83 KB 33.71 KB NODE_DEV
react-dom-test-utils.production.min.js -1.5% 🔺+0.3% 10.97 KB 10.81 KB 4.09 KB 4.1 KB NODE_PROD
react-dom-server.browser.production.min.js 0.0% -0.1% 20.36 KB 20.36 KB 7.45 KB 7.44 KB NODE_PROD
react-dom-unstable-native-dependencies.development.js -0.3% -0.4% 59.08 KB 58.91 KB 14.75 KB 14.7 KB UMD_DEV
ReactTestUtils-dev.js -0.1% -0.3% 51.37 KB 51.31 KB 13.75 KB 13.7 KB FB_WWW_DEV
react-dom-unstable-native-dependencies.production.min.js -0.1% 🔺+0.1% 10.28 KB 10.27 KB 3.49 KB 3.5 KB UMD_PROD
ReactDOMServer-dev.js -0.2% -0.4% 134.46 KB 134.18 KB 34.28 KB 34.14 KB FB_WWW_DEV
ReactDOMServer-prod.js -3.0% -1.3% 48.1 KB 46.68 KB 10.99 KB 10.84 KB FB_WWW_PROD
react-dom-unstable-native-dependencies.development.js -0.3% -0.5% 56.05 KB 55.87 KB 14.54 KB 14.47 KB NODE_DEV
react-dom-unstable-fizz.node.development.js -6.3% -7.9% 3.94 KB 3.69 KB 1.46 KB 1.34 KB NODE_DEV
react-dom-unstable-native-dependencies.production.min.js -0.1% -0.3% 10 KB 10 KB 3.39 KB 3.38 KB NODE_PROD
react-dom-unstable-fizz.node.production.min.js -2.4% -3.2% 1.19 KB 1.16 KB 685 B 663 B NODE_PROD
ReactDOM-prod.js 0.0% -0.0% 370.74 KB 370.74 KB 67.45 KB 67.45 KB FB_WWW_PROD
ReactDOM-profiling.js 0.0% -0.0% 381.95 KB 381.95 KB 69.57 KB 69.57 KB FB_WWW_PROFILING
react-dom-unstable-fizz.browser.development.js -8.2% -9.5% 3.21 KB 2.95 KB 1.3 KB 1.18 KB NODE_DEV
react-dom-unstable-fizz.browser.production.min.js -2.7% -3.0% 1.03 KB 1 KB 629 B 610 B NODE_PROD
react-dom-testing.development.js 0.0% -0.0% 887.91 KB 887.91 KB 195.74 KB 195.74 KB UMD_DEV
react-dom-testing.production.min.js 0.0% -0.0% 117.41 KB 117.41 KB 37.72 KB 37.72 KB UMD_PROD
ReactDOMTesting-dev.js 0.0% -0.0% 869.57 KB 869.57 KB 194.5 KB 194.5 KB FB_WWW_DEV
react-dom-testing.profiling.min.js 0.0% -0.0% 120.94 KB 120.94 KB 38.9 KB 38.89 KB UMD_PROFILING
react-dom-testing.development.js 0.0% -0.0% 841.37 KB 841.37 KB 192.18 KB 192.18 KB NODE_DEV
react-dom-server.node.development.js -0.1% -0.2% 128.57 KB 128.38 KB 34.05 KB 33.97 KB NODE_DEV
react-dom-testing.production.min.js 0.0% 0.0% 117.57 KB 117.57 KB 37.05 KB 37.05 KB NODE_PROD
react-dom-server.node.production.min.js 0.0% -0.2% 20.77 KB 20.77 KB 7.6 KB 7.59 KB NODE_PROD

react-test-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-test-renderer.development.js -0.1% -0.1% 554.6 KB 554.14 KB 115.42 KB 115.34 KB UMD_DEV
react-test-renderer.production.min.js -0.0% -0.0% 71.14 KB 71.13 KB 21.62 KB 21.62 KB UMD_PROD
ReactShallowRenderer-dev.js -0.3% -0.6% 34.35 KB 34.25 KB 8.45 KB 8.4 KB FB_WWW_DEV
react-test-renderer.development.js -0.1% -0.1% 524.92 KB 524.45 KB 113.1 KB 113 KB NODE_DEV
react-test-renderer.production.min.js -0.0% -0.0% 70.95 KB 70.94 KB 21.3 KB 21.29 KB NODE_PROD
ReactTestRenderer-dev.js -0.1% -0.1% 551.81 KB 551.32 KB 116.23 KB 116.1 KB FB_WWW_DEV
react-test-renderer-shallow.development.js -0.3% -0.5% 39.27 KB 39.17 KB 9.86 KB 9.81 KB UMD_DEV
react-test-renderer-shallow.production.min.js -0.1% -0.2% 11.65 KB 11.63 KB 3.6 KB 3.59 KB UMD_PROD
react-test-renderer-shallow.development.js -0.3% -0.6% 32.13 KB 32.03 KB 8.41 KB 8.36 KB NODE_DEV
react-test-renderer-shallow.production.min.js -0.1% -0.2% 11.77 KB 11.76 KB 3.69 KB 3.68 KB NODE_PROD

ReactDOM: size: -1.2%, gzip: -1.3%

Size changes (experimental)

Generated by 🚫 dangerJS against 5c75e3f

@sizebot
Copy link

sizebot commented Feb 27, 2020

Details of bundled changes.

Comparing: 60016c4...5c75e3f

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom-testing.production.min.js 0.0% 0.0% 117.01 KB 117.01 KB 36.92 KB 36.92 KB NODE_PROD
react-dom-unstable-native-dependencies.development.js -0.3% -0.4% 59.07 KB 58.9 KB 14.75 KB 14.7 KB UMD_DEV
react-dom-unstable-fizz.browser.production.min.js -2.7% -3.1% 1.02 KB 1013 B 621 B 602 B NODE_PROD
react-dom-testing.profiling.min.js 0.0% -0.0% 120.7 KB 120.7 KB 37.97 KB 37.97 KB NODE_PROFILING
react-dom-unstable-native-dependencies.production.min.js -0.1% 🔺+0.1% 10.26 KB 10.26 KB 3.48 KB 3.49 KB UMD_PROD
ReactTestUtils-dev.js -0.1% -0.3% 51.38 KB 51.31 KB 13.75 KB 13.7 KB FB_WWW_DEV
react-dom-unstable-fizz.node.development.js -6.3% -8.0% 3.93 KB 3.68 KB 1.45 KB 1.33 KB NODE_DEV
react-dom.development.js 0.0% -0.0% 885.6 KB 885.6 KB 195.2 KB 195.2 KB UMD_DEV
react-dom-server.browser.development.js -0.2% -0.3% 136.57 KB 136.3 KB 34.98 KB 34.88 KB UMD_DEV
react-dom-unstable-fizz.node.production.min.js -2.4% -3.3% 1.17 KB 1.15 KB 676 B 654 B NODE_PROD
react-dom.production.min.js 0.0% -0.0% 115.85 KB 115.85 KB 37.08 KB 37.08 KB UMD_PROD
react-dom-server.browser.production.min.js -0.0% -0.1% 19.99 KB 19.99 KB 7.4 KB 7.39 KB UMD_PROD
react-dom.development.js 0.0% -0.0% 839.19 KB 839.19 KB 191.61 KB 191.61 KB NODE_DEV
react-dom-server.browser.development.js -0.2% -0.4% 125.94 KB 125.65 KB 33.61 KB 33.49 KB NODE_DEV
react-dom.production.min.js 0.0% -0.0% 115.93 KB 115.93 KB 36.45 KB 36.45 KB NODE_PROD
react-dom-testing.development.js 0.0% -0.0% 885.56 KB 885.56 KB 195.47 KB 195.47 KB UMD_DEV
react-dom-server.browser.production.min.js 0.0% -0.2% 19.9 KB 19.9 KB 7.37 KB 7.36 KB NODE_PROD
react-dom-unstable-fizz.browser.development.js -7.1% -7.3% 3.59 KB 3.34 KB 1.36 KB 1.26 KB UMD_DEV
react-dom.profiling.min.js 0.0% 0.0% 119.61 KB 119.61 KB 37.51 KB 37.51 KB NODE_PROFILING
react-dom-testing.production.min.js 0.0% -0.0% 116.89 KB 116.89 KB 37.59 KB 37.59 KB UMD_PROD
react-dom-unstable-fizz.browser.production.min.js -1.2% -1.1% 1.19 KB 1.17 KB 699 B 691 B UMD_PROD
ReactDOM-dev.js 0.0% -0.0% 936.45 KB 936.45 KB 208.25 KB 208.25 KB FB_WWW_DEV
ReactDOMServer-dev.js -0.2% -0.4% 135.38 KB 135.11 KB 34.44 KB 34.3 KB FB_WWW_DEV
react-dom-testing.development.js 0.0% -0.0% 839.13 KB 839.13 KB 191.92 KB 191.92 KB NODE_DEV
ReactDOMServer-prod.js -2.9% -1.0% 48.8 KB 47.39 KB 11.14 KB 11.03 KB FB_WWW_PROD
react-dom-unstable-fizz.browser.development.js -8.2% -9.5% 3.2 KB 2.94 KB 1.29 KB 1.17 KB NODE_DEV
react-dom-unstable-native-dependencies.development.js -0.3% -0.5% 56.04 KB 55.86 KB 14.53 KB 14.46 KB NODE_DEV
react-dom-test-utils.development.js +0.2% -0.0% 53.68 KB 53.77 KB 14 KB 14 KB UMD_DEV
react-dom-unstable-native-dependencies.production.min.js -0.1% -0.3% 9.99 KB 9.99 KB 3.38 KB 3.37 KB NODE_PROD
react-dom-test-utils.production.min.js -2.3% 🔺+0.3% 11.2 KB 10.94 KB 4.15 KB 4.16 KB UMD_PROD
react-dom-test-utils.development.js +0.1% -0.2% 49.51 KB 49.55 KB 13.54 KB 13.51 KB NODE_DEV
react-dom-server.node.development.js -0.1% -0.2% 127.06 KB 126.87 KB 33.83 KB 33.75 KB NODE_DEV
react-dom-test-utils.production.min.js -1.5% 🔺+0.3% 10.96 KB 10.79 KB 4.08 KB 4.09 KB NODE_PROD
react-dom-server.node.production.min.js 0.0% -0.2% 20.31 KB 20.31 KB 7.52 KB 7.51 KB NODE_PROD

react-test-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-test-renderer.production.min.js -0.0% -0.0% 70.92 KB 70.92 KB 21.28 KB 21.27 KB NODE_PROD
react-test-renderer-shallow.development.js -0.3% -0.6% 32.11 KB 32.01 KB 8.41 KB 8.36 KB NODE_DEV
react-test-renderer-shallow.production.min.js -0.1% -0.2% 11.75 KB 11.74 KB 3.68 KB 3.67 KB NODE_PROD
ReactShallowRenderer-dev.js -0.3% -0.6% 34.35 KB 34.25 KB 8.45 KB 8.4 KB FB_WWW_DEV
react-test-renderer.development.js -0.1% -0.1% 554.58 KB 554.12 KB 115.41 KB 115.33 KB UMD_DEV
react-test-renderer.production.min.js -0.0% -0.0% 71.11 KB 71.1 KB 21.61 KB 21.6 KB UMD_PROD
react-test-renderer.development.js -0.1% -0.1% 524.89 KB 524.42 KB 113.09 KB 112.99 KB NODE_DEV
ReactTestRenderer-dev.js -0.1% -0.1% 551.8 KB 551.31 KB 116.23 KB 116.1 KB FB_WWW_DEV
react-test-renderer-shallow.development.js -0.3% -0.5% 39.26 KB 39.16 KB 9.85 KB 9.8 KB UMD_DEV
react-test-renderer-shallow.production.min.js -0.1% -0.2% 11.63 KB 11.62 KB 3.59 KB 3.58 KB UMD_PROD

ReactDOM: size: -0.1%, gzip: 🔺+0.1%

Size changes (stable)

Generated by 🚫 dangerJS against 5c75e3f

let ReactDOM;
let ReactDOMServer;
let ReactTestUtils;
import ReactTestRenderer from 'react-test-renderer/shallow';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay this is what confused me. It should say ReactShallowRenderer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

potato, potato... fixed :)

@@ -856,4 +856,8 @@ function getMaskedContext(contextTypes, unmaskedContext) {
return context;
}

// This should probably be a default export and a named export.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand what this comment is saying. Which one should it be?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Both

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When we expose a proper ES module we can do:

export default ReactShallowRenderer;
export createRenderer;

It's just that if I do that, then Rollup doesn't do the magic thing to only use module.exports =

// TODO: decide on the top-level export form.
// This is hacky but makes it work with both Rollup and Jest.
module.exports = ReactShallowRenderer.default || ReactShallowRenderer;
export {default} from './src/ReactShallowRenderer';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't this gonna break const ShallowRenderer = require('react-test-renderer/shallow')? Is this not a breaking change?

Copy link
Collaborator Author

@sebmarkbage sebmarkbage Feb 27, 2020

Choose a reason for hiding this comment

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

No, Rollup makes this into module.exports = if you only export a default. (Babel doesn't which is what Jest is struggling with.)

Copy link
Collaborator

Choose a reason for hiding this comment

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

🤯 I had no idea

Nothing interesting here except that ReactShallowRenderer currently exports
a class with a static method instead of an object.

I think the public API is probably just meant to be createRenderer but
currently the whole class is exposed. So this means that we have to keep
it as default export. We could potentially also expose a named export for
createRenderer but that's going to cause compatibility issues.

So I'm just going to make that export default.

Unfortunately Rollup and Babel (which powers Jest) disagree on how to
import this. So to make it work I had to move the jest tests to imports.

This doesn't work with module resetting. Some tests weren't doing that
anyway and the rest is just testing ReactShallowRenderer so meh.
Copy link
Collaborator

@gaearon gaearon left a comment

Choose a reason for hiding this comment

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

ok

@sebmarkbage
Copy link
Collaborator Author

@sebmarkbage sebmarkbage merged commit f9c0a45 into facebook:master Feb 27, 2020
@gaearon
Copy link
Collaborator

gaearon commented Feb 27, 2020

beautiful

NMinhNguyen added a commit to enzymejs/react-shallow-renderer that referenced this pull request Feb 27, 2020
NMinhNguyen added a commit to enzymejs/react-shallow-renderer that referenced this pull request Feb 27, 2020
NMinhNguyen added a commit to enzymejs/react-shallow-renderer that referenced this pull request Feb 27, 2020
renawolford6 added a commit to renawolford6/react-shallow-renderer that referenced this pull request Nov 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants