Skip to content

Commit

Permalink
Use testing builds for our own tests
Browse files Browse the repository at this point in the history
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
  • Loading branch information
threepointone committed Feb 6, 2020
1 parent 9e158c0 commit f4b49da
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 16 deletions.
1 change: 1 addition & 0 deletions packages/react-dom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"README.md",
"build-info.json",
"index.js",
"testing.js",
"profiling.js",
"server.js",
"server.browser.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ let React;
let ReactDOM;
let Suspense;
let ReactCache;
let ReactTestUtils;
let Scheduler;
let TextResource;
let act;
Expand All @@ -26,9 +25,8 @@ describe('ReactDOMSuspensePlaceholder', () => {
React = require('react');
ReactDOM = require('react-dom');
ReactCache = require('react-cache');
ReactTestUtils = require('react-dom/test-utils');
Scheduler = require('scheduler');
act = ReactTestUtils.act;
act = ReactDOM.act;
Suspense = React.Suspense;
container = document.createElement('div');
document.body.appendChild(container);
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/forks/ReactFeatureFlags.readonly.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
25 changes: 13 additions & 12 deletions packages/shared/forks/ReactFeatureFlags.testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@
* @flow
*/

import invariant from 'shared/invariant';
// keep in sync with ReactFeatureFlags.js
// only isTestEnvironment is different, and true

import typeof * as FeatureFlagsType from 'shared/ReactFeatureFlags';
import typeof * as PersistentFeatureFlagsType from './ReactFeatureFlags.persistent';

export const debugRenderPhaseSideEffectsForStrictMode = false;
export const enableUserTimingAPI = __DEV__;
export const debugRenderPhaseSideEffectsForStrictMode = __DEV__;
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
export const warnAboutDeprecatedLifecycles = true;
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
export const enableProfilerTimer = __PROFILE__;
export const enableSchedulerTracing = __PROFILE__;
export const enableSuspenseServerRenderer = false;
export const enableSelectiveHydration = false;
export const enableChunksAPI = false;
export const enableSuspenseServerRenderer = __EXPERIMENTAL__;
export const enableSelectiveHydration = __EXPERIMENTAL__;
export const enableChunksAPI = __EXPERIMENTAL__;
export const enableSchedulerDebugging = false;
export const disableJavaScriptURLs = false;
export const disableInputAttributeSyncing = false;
export const exposeConcurrentModeAPIs = __EXPERIMENTAL__;
export const warnAboutShorthandPropertyCollision = false;
export const enableSchedulerDebugging = false;
export const enableDeprecatedFlareAPI = false;
export const enableFundamentalAPI = false;
export const enableScopeAPI = false;
Expand All @@ -34,23 +34,24 @@ export const warnAboutUnmockedScheduler = false;
export const flushSuspenseFallbacksInTests = true;
export const enableSuspenseCallback = false;
export const warnAboutDefaultPropsOnFunctionComponents = false;
export const warnAboutStringRefs = false;
export const disableLegacyContext = false;
export const disableSchedulerTimeoutBasedOnReactExpirationTime = false;
export const enableTrainModelFix = true;
export const enableTrustedTypesIntegration = false;
export const enableNativeTargetAsInstance = false;
export const deferPassiveEffectCleanupDuringUnmount = false;
export const disableInputAttributeSyncing = false;
export const warnAboutStringRefs = false;
export const disableLegacyContext = false;
export const disableCreateFactory = false;
export const disableTextareaChildren = false;
export const disableUnstableRenderSubtreeIntoContainer = false;
export const warnUnstableRenderSubtreeIntoContainer = false;
export const disableUnstableCreatePortal = false;
export const deferPassiveEffectCleanupDuringUnmount = false;
export const isTestEnvironment = true;

// Only used in www builds.
export function addUserTimingListener() {
invariant(false, 'Not implemented.');
throw new Error('Not implemented.');
}

// Flow magic to verify the exports of this file match the original version.
Expand Down
3 changes: 3 additions & 0 deletions scripts/jest/config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ module.exports = {
haste: {
hasteImplModulePath: require.resolve('./noHaste.js'),
},
moduleNameMapper: {
'^shared/ReactFeatureFlags': `<rootDir>/packages/shared/forks/ReactFeatureFlags.testing`,
},
modulePathIgnorePatterns: [
'<rootDir>/scripts/rollup/shims/',
'<rootDir>/scripts/bench/',
Expand Down
2 changes: 2 additions & 0 deletions scripts/jest/setupHostConfigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ inlinedHostConfigs.forEach(rendererInfo => {
}
});

jest.mock('react-dom', () => require.requireActual('react-dom/testing'));

// Make it possible to import this module inside
// the React package itself.
jest.mock('shared/ReactSharedInternals', () =>
Expand Down
2 changes: 2 additions & 0 deletions scripts/jest/setupTests.build.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

jest.mock('react-dom', () => require.requireActual(`react-dom/testing`));

jest.mock('scheduler', () => require.requireActual('scheduler/unstable_mock'));
jest.mock('scheduler/src/SchedulerHostConfig', () =>
require.requireActual('scheduler/src/forks/SchedulerHostConfig.mock.js')
Expand Down

0 comments on commit f4b49da

Please sign in to comment.