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

Use testing builds for our own tests #17985

Closed

Conversation

threepointone
Copy link
Contributor

@threepointone threepointone commented Feb 6, 2020

Following up from #17915 where we generated testing builds for react-dom, this PR uses those builds for our own tests.

  • fixes for fb builds:
    • adds a ReactFeatureFlags fork where isTestEnvironment:true
    • adds a .fb fork for the testing.js entrypoint
  • adds isTestEnvironment: true to ReactFeatureFlags.readonly
  • with jest, mocks react-dom with the testing version, both for source and builds
  • uses ReactDOM.act in one of these tests to verify it actually works

This also meant I had to add testing.js to react-dom's package.json (so we can still run yarn test-build). If you feel strongly about not exposing this yet, maybe I could rename it to testing_DO_NOT_USE.js?

I'll write a post before I land this, but this setup has an annoyance. If you add a new feature flag, and run your tests, your test will probably fail, since it's likely you've not added it to the .testing forks. There's nothing to warn this except for flow. which might not be running. Open to ideas for syncing these forks.

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

codesandbox-ci bot commented Feb 6, 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 fe0c945:

Sandbox Source
youthful-einstein-hs29p Configuration

@sizebot
Copy link

sizebot commented Feb 6, 2020

Details of bundled changes.

Comparing: 256d78d...fe0c945

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom-test-utils.development.js +0.2% +0.4% 53.65 KB 53.74 KB 15.27 KB 15.32 KB NODE_DEV
react-dom.production.min.js 0.0% 0.0% 116.03 KB 116.03 KB 37.29 KB 37.29 KB UMD_PROD
react-dom-testing.development.js +0.3% +0.5% 956.61 KB 959.27 KB 214.39 KB 215.42 KB NODE_DEV
react-dom.profiling.min.js 0.0% 0.0% 119.55 KB 119.55 KB 38.45 KB 38.45 KB UMD_PROFILING
react-dom.development.js 0.0% 0.0% 959.19 KB 959.28 KB 215.39 KB 215.43 KB NODE_DEV
react-dom-testing.profiling.min.js 0.0% -0.0% 120.84 KB 120.84 KB 38.21 KB 38.21 KB NODE_PROFILING
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 3.87 KB 3.87 KB 1.54 KB 1.54 KB UMD_DEV
react-dom.profiling.min.js 0.0% -0.0% 119.76 KB 119.76 KB 37.74 KB 37.74 KB NODE_PROFILING
react-dom-server.browser.development.js +0.1% +0.2% 139.3 KB 139.38 KB 36.94 KB 36.99 KB UMD_DEV
react-dom-server.browser.production.min.js 0.0% -0.0% 20 KB 20 KB 7.4 KB 7.4 KB UMD_PROD
react-dom-unstable-fizz.browser.production.min.js 0.0% -0.2% 1.04 KB 1.04 KB 635 B 634 B NODE_PROD
react-dom-server.browser.development.js +0.1% +0.2% 135.23 KB 135.32 KB 35.91 KB 35.97 KB NODE_DEV
react-dom-test-utils.development.js +0.2% +0.4% 55.38 KB 55.46 KB 15.59 KB 15.65 KB UMD_DEV
react-dom-server.browser.production.min.js 0.0% -0.0% 19.93 KB 19.93 KB 7.39 KB 7.39 KB NODE_PROD
react-dom-test-utils.production.min.js 0.0% 🔺+0.1% 10.97 KB 10.97 KB 4.09 KB 4.1 KB NODE_PROD
react-dom-unstable-fizz.node.development.js 0.0% -0.1% 4.4 KB 4.4 KB 1.64 KB 1.64 KB NODE_DEV
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 60.92 KB 60.92 KB 16.07 KB 16.07 KB UMD_DEV
react-dom-unstable-fizz.node.production.min.js 0.0% -0.1% 1.2 KB 1.2 KB 690 B 689 B NODE_PROD
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.0% 10.24 KB 10.24 KB 3.46 KB 3.46 KB UMD_PROD
react-dom-server.node.development.js +0.1% +0.2% 136.34 KB 136.43 KB 36.14 KB 36.2 KB NODE_DEV
react-dom-testing.development.js +0.3% +0.5% 962.53 KB 965.19 KB 216.08 KB 217.09 KB UMD_DEV
react-dom-testing.production.min.js 0.0% 0.0% 117.06 KB 117.06 KB 37.75 KB 37.75 KB UMD_PROD
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 60.62 KB 60.62 KB 15.99 KB 15.99 KB NODE_DEV
react-dom.development.js 0.0% 0.0% 965.11 KB 965.2 KB 217.05 KB 217.1 KB UMD_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.0% 9.98 KB 9.98 KB 3.37 KB 3.37 KB NODE_PROD

ReactDOM: size: 0.0%, gzip: 0.0%

Size changes (stable)

Generated by 🚫 dangerJS against fe0c945

@sizebot
Copy link

sizebot commented Feb 6, 2020

Details of bundled changes.

Comparing: 256d78d...fe0c945

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.profiling.min.js 0.0% -0.0% 123.81 KB 123.81 KB 38.77 KB 38.77 KB NODE_PROFILING
ReactDOMServer-prod.js 0.0% 0.0% 48.99 KB 48.99 KB 11.18 KB 11.18 KB FB_WWW_PROD
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 3.88 KB 3.88 KB 1.55 KB 1.55 KB UMD_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% -0.1% 1.21 KB 1.21 KB 711 B 710 B UMD_PROD
react-dom-test-utils.development.js +0.2% +0.4% 55.39 KB 55.48 KB 15.59 KB 15.65 KB UMD_DEV
react-dom-testing.profiling.min.js +2.9% +2.3% 121.37 KB 124.89 KB 38.36 KB 39.26 KB NODE_PROFILING
ReactDOMTesting-prod.js 🔺+16.5% 🔺+17.2% 340.91 KB 397.21 KB 62.23 KB 72.95 KB FB_WWW_PROD
react-dom-server.browser.development.js +0.1% +0.2% 139.32 KB 139.41 KB 36.94 KB 36.99 KB UMD_DEV
ReactDOMTesting-profiling.js +16.1% +17.1% 351.69 KB 408.45 KB 64.18 KB 75.15 KB FB_WWW_PROFILING
react-dom-server.browser.production.min.js 0.0% -0.0% 20.46 KB 20.46 KB 7.5 KB 7.5 KB UMD_PROD
react-dom-test-utils.development.js +0.2% +0.4% 53.66 KB 53.75 KB 15.27 KB 15.33 KB NODE_DEV
react-dom-server.browser.development.js +0.1% +0.2% 135.26 KB 135.34 KB 35.92 KB 35.97 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% 🔺+0.1% 10.99 KB 10.99 KB 4.1 KB 4.1 KB NODE_PROD
react-dom.development.js 0.0% 0.0% 965.13 KB 965.22 KB 217.07 KB 217.12 KB UMD_DEV
react-dom.development.js 0.0% 0.0% 959.22 KB 959.3 KB 215.4 KB 215.45 KB NODE_DEV
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 60.63 KB 60.63 KB 16 KB 16 KB NODE_DEV
react-dom-unstable-fizz.node.development.js 0.0% -0.1% 4.42 KB 4.42 KB 1.65 KB 1.65 KB NODE_DEV
ReactTestUtils-dev.js +0.2% +0.4% 52.58 KB 52.67 KB 14.32 KB 14.37 KB FB_WWW_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.0% 9.99 KB 9.99 KB 3.38 KB 3.38 KB NODE_PROD
ReactDOMServer-dev.js +0.1% +0.1% 140.33 KB 140.42 KB 35.53 KB 35.58 KB FB_WWW_DEV
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 3.71 KB 3.71 KB 1.5 KB 1.5 KB NODE_DEV
ReactDOM-dev.js 0.0% 0.0% 986.67 KB 986.76 KB 218.19 KB 218.23 KB FB_WWW_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% -0.2% 1.05 KB 1.05 KB 642 B 641 B NODE_PROD
ReactDOM-prod.js 0.0% 0.0% 393.59 KB 393.59 KB 71.93 KB 71.93 KB FB_WWW_PROD
react-dom-testing.development.js +0.3% +0.5% 962.55 KB 965.21 KB 216.09 KB 217.11 KB UMD_DEV
ReactDOM-profiling.js 0.0% 0.0% 404.84 KB 404.84 KB 74.09 KB 74.09 KB FB_WWW_PROFILING
react-dom-testing.production.min.js 🔺+2.9% 🔺+2.5% 117.6 KB 120.98 KB 37.9 KB 38.85 KB UMD_PROD
react-dom-testing.profiling.min.js +2.9% +2.6% 121.12 KB 124.61 KB 39.04 KB 40.05 KB UMD_PROFILING
react-dom-testing.development.js +0.3% +0.5% 956.64 KB 959.29 KB 214.4 KB 215.44 KB NODE_DEV
react-dom-server.node.development.js +0.1% +0.2% 136.37 KB 136.45 KB 36.14 KB 36.2 KB NODE_DEV
react-dom-testing.production.min.js 🔺+2.9% 🔺+2.4% 117.69 KB 121.11 KB 37.25 KB 38.14 KB NODE_PROD
ReactDOMTesting-dev.js +0.2% +0.3% 985.24 KB 986.76 KB 217.47 KB 218.23 KB FB_WWW_DEV
react-dom-server.node.production.min.js 0.0% -0.0% 20.79 KB 20.79 KB 7.62 KB 7.62 KB NODE_PROD

ReactDOM: size: 0.0%, gzip: -0.1%

Size changes (experimental)

Generated by 🚫 dangerJS against fe0c945

@threepointone threepointone requested a review from acdlite February 6, 2020 01:23
@threepointone threepointone force-pushed the use-testing-build branch 8 times, most recently from fe3bb48 to f39963f Compare February 6, 2020 15:46
scripts/rollup/build.js Outdated Show resolved Hide resolved
Copy link
Collaborator

@acdlite acdlite left a comment

Choose a reason for hiding this comment

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

I understand why using a global is easier. But we need to figure out a solution to Jest not respecting the forks used by the build script. It's one of the main blockers to being able to get rid of the .internal suffix. This is going to become increasingly important as we start maintaining multiple builds of React (modern, legacy, etc).

In the meantime, instead of using a global, could you keep the feature flag and use a jest mock?

jest.mock('shared/ReactFeatureFlags', () =>
  require.requireActual('shared/forks/ReactFeatureFlags.testing.js')
);

This means when running the tests against source (i.e. not the bundle tests), all renderers will get the testing feature flags instead of the ones specific to their fork. But that's actually no worse than what already happens today, where they get the default feature flags. And it's no worse than using a global, which is compiled away during build.

Then, whenever we get around to solving the forking problem, it will also solve this one.

@threepointone threepointone force-pushed the use-testing-build branch 2 times, most recently from e25d4e1 to 331ab49 Compare February 7, 2020 00:49
Following up from facebook#17915 where we generated testing builds for `react-dom`, this PR uses those builds for our own tests.

- fixes `ReactFeatureFlags.testing` to use all the default flags
- changes `ReactFeatureFlags.readonly` to return `isTestEnvironment: true` (this might not strictly be needed)
- with jest, mocks `react-dom` with the testing version, both for source and builds
- uses `ReactDOM.act` in one of these tests to verify it actually works
@threepointone
Copy link
Contributor Author

Updated the PR and description. Copy pasting a specific concern -

I'll write a post before I land this, but this setup has an annoyance. If you add a new feature flag, and run your tests, your test will probably fail, since it's likely you've not added it to the .testing forks. There's nothing to warn this except for flow. which might not be running. Open to ideas for syncing these forks.

@threepointone threepointone requested a review from acdlite February 7, 2020 10:59
@acdlite
Copy link
Collaborator

acdlite commented Feb 7, 2020

You can reexport one from the other:

// shared/forks/ReactFeatureFlags.www.testing.js

export {
  flags,
  that,
  are,
  the,
  same
} from './ReactFeatureFlags.www';

export const differentFlag = 'forked';

@threepointone
Copy link
Contributor Author

I tried this and it failed because it kept referring to itself and failing the build. Maybe I didn’t try it hard enough, I’ll try again.

@@ -30,6 +30,7 @@
"README.md",
"build-info.json",
"index.js",
"testing.js",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Putting this here means it will go into the next public release. If you can't get rid of it because the bundle tests rely on it, maybe prefix with unstable?

@@ -9,4 +9,4 @@
// It lets us determine whether we're running in Fire mode without making tests internal.
const ReactFeatureFlags = require('../ReactFeatureFlags');
// Forbid writes because this wouldn't work with bundle tests.
module.exports = Object.freeze({...ReactFeatureFlags});
module.exports = Object.freeze({...ReactFeatureFlags, isTestEnvironment: true});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't need this anymore, right?

@acdlite
Copy link
Collaborator

acdlite commented Feb 7, 2020

I tried this and it failed because it kept referring to itself and failing the build.

You can move the default feature flags to their own file, shared/forks/ReactFeatureFlags.default. Then shared/ReactFeatureFlags can re-export that. And so can all the forks.

@threepointone
Copy link
Contributor Author

abandoning this for #18196

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