Skip to content

Commit

Permalink
Bring back OSS testing builds
Browse files Browse the repository at this point in the history
We removed this in facebook#18138 to unblock 16.13. This PR brings it back, with some changes -
- testing builds are prefixed with `unstable-`, i.e - `react-dom/unstable-testing`
- added back to `bundles.js`
- reintroduces the `isTestEnvironment`feature flag. Not used to generate the actual builds, but is used for test specific logic
- flushes suspense fallbacks in prod for testing builds
- changes tests in TestUtilsAct to reflect this
- misc test config changes
  • Loading branch information
threepointone committed Mar 2, 2020
1 parent 62861bb commit c5a591c
Show file tree
Hide file tree
Showing 30 changed files with 414 additions and 369 deletions.
5 changes: 4 additions & 1 deletion fixtures/dom/src/__tests__/nested-act-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ let TestAct;
global.__DEV__ = process.env.NODE_ENV !== 'production';

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

describe('unmocked scheduler', () => {
beforeEach(() => {
jest.resetModules();
React = require('react');
DOMAct = require('react-dom/test-utils').act;
DOMAct = require('react-dom').act;
TestRenderer = require('react-test-renderer');
TestAct = TestRenderer.act;
});
Expand Down
19 changes: 10 additions & 9 deletions fixtures/dom/src/__tests__/wrong-act-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
let React;
let ReactDOM;
let ReactART;
let TestUtils;
let ARTSVGMode;
let ARTCurrentMode;
let TestRenderer;
Expand All @@ -20,6 +19,9 @@ global.__DEV__ = process.env.NODE_ENV !== 'production';
global.__EXPERIMENTAL__ = process.env.RELEASE_CHANNEL === 'experimental';

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

function App(props) {
return 'hello world';
Expand All @@ -29,7 +31,6 @@ beforeEach(() => {
jest.resetModules();
React = require('react');
ReactDOM = require('react-dom');
TestUtils = require('react-dom/test-utils');
ReactART = require('react-art');
ARTSVGMode = require('art/modes/svg');
ARTCurrentMode = require('art/modes/current');
Expand Down Expand Up @@ -70,7 +71,7 @@ beforeEach(() => {
});

it("doesn't warn when you use the right act + renderer: dom", () => {
TestUtils.act(() => {
ReactDOM.act(() => {
ReactDOM.render(<App />, document.createElement('div'));
});
});
Expand All @@ -86,7 +87,7 @@ it('resets correctly across renderers', () => {
React.useEffect(() => {}, []);
return null;
}
TestUtils.act(() => {
ReactDOM.act(() => {
TestRenderer.act(() => {});
expect(() => {
TestRenderer.create(<Effecty />);
Expand Down Expand Up @@ -123,7 +124,7 @@ it('warns when using the wrong act version - test + dom: updates', () => {

it('warns when using the wrong act version - dom + test: .create()', () => {
expect(() => {
TestUtils.act(() => {
ReactDOM.act(() => {
TestRenderer.create(<App />);
});
}).toWarnDev(["It looks like you're using the wrong act()"], {
Expand All @@ -134,7 +135,7 @@ it('warns when using the wrong act version - dom + test: .create()', () => {
it('warns when using the wrong act version - dom + test: .update()', () => {
const root = TestRenderer.create(<App key="one" />);
expect(() => {
TestUtils.act(() => {
ReactDOM.act(() => {
root.update(<App key="two" />);
});
}).toWarnDev(["It looks like you're using the wrong act()"], {
Expand All @@ -151,14 +152,14 @@ it('warns when using the wrong act version - dom + test: updates', () => {
}
TestRenderer.create(<Counter />);
expect(() => {
TestUtils.act(() => {
ReactDOM.act(() => {
setCtr(1);
});
}).toWarnDev(["It looks like you're using the wrong act()"]);
});

it('does not warn when nesting react-act inside react-dom', () => {
TestUtils.act(() => {
ReactDOM.act(() => {
ReactDOM.render(<ARTTest />, document.createElement('div'));
});
});
Expand All @@ -171,7 +172,7 @@ it('does not warn when nesting react-act inside react-test-renderer', () => {

it("doesn't warn if you use nested acts from different renderers", () => {
TestRenderer.act(() => {
TestUtils.act(() => {
ReactDOM.act(() => {
TestRenderer.create(<App />);
});
});
Expand Down
38 changes: 0 additions & 38 deletions packages/react-dom/npm/testing.js

This file was deleted.

9 changes: 9 additions & 0 deletions packages/react-dom/npm/unstable-testing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
// DCE check should happen before ReactDOM bundle executes so that
// DevTools can report bad minification during injection.
module.exports = require('./cjs/react-dom-unstable-testing.production.min.js');
} else {
module.exports = require('./cjs/react-dom-unstable-testing.development.js');
}
1 change: 1 addition & 0 deletions packages/react-dom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"unstable-fizz.browser.js",
"unstable-fizz.node.js",
"unstable-native-dependencies.js",
"unstable-testing.js",
"cjs/",
"umd/"
],
Expand Down
10 changes: 4 additions & 6 deletions packages/react-dom/src/__tests__/ReactTestUtilsAct-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

let React;
let ReactDOM;
let ReactTestUtils;
let SchedulerTracing;
let Scheduler;
let act;
Expand All @@ -25,7 +24,7 @@ function sleep(period) {
});
}

describe('ReactTestUtils.act()', () => {
describe('act()', () => {
// first we run all the tests with concurrent mode
if (__EXPERIMENTAL__) {
let concurrentRoot = null;
Expand Down Expand Up @@ -155,10 +154,9 @@ function runActTests(label, render, unmount, rerender) {
jest.resetModules();
React = require('react');
ReactDOM = require('react-dom');
ReactTestUtils = require('react-dom/test-utils');
SchedulerTracing = require('scheduler/tracing');
Scheduler = require('scheduler');
act = ReactTestUtils.act;
act = ReactDOM.act;
container = document.createElement('div');
document.body.appendChild(container);
});
Expand Down Expand Up @@ -721,7 +719,7 @@ function runActTests(label, render, unmount, rerender) {
});

describe('suspense', () => {
if (__DEV__ && __EXPERIMENTAL__) {
if (__EXPERIMENTAL__) {
// todo - remove __DEV__ check once we start using testing builds
it('triggers fallbacks if available', async () => {
let resolved = false;
Expand Down Expand Up @@ -792,7 +790,7 @@ function runActTests(label, render, unmount, rerender) {
}
});
describe('warn in prod mode', () => {
it('warns if you try to use act() in prod mode', () => {
xit('warns if you try to use act() in prod mode', () => {
const spy = spyOnDevAndProd(console, 'error');

act(() => {});
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 4 additions & 3 deletions packages/react-reconciler/src/ReactFiberWorkLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
warnAboutUnmockedScheduler,
flushSuspenseFallbacksInTests,
disableSchedulerTimeoutBasedOnReactExpirationTime,
isTestEnvironment,
} from 'shared/ReactFeatureFlags';
import ReactSharedInternals from 'shared/ReactSharedInternals';
import invariant from 'shared/invariant';
Expand Down Expand Up @@ -789,7 +790,7 @@ function finishConcurrentRender(
hasNotProcessedNewUpdates &&
// do not delay if we're inside an act() scope
!(
__DEV__ &&
(__DEV__ || isTestEnvironment) &&
flushSuspenseFallbacksInTests &&
IsThisRendererActing.current
)
Expand Down Expand Up @@ -855,7 +856,7 @@ function finishConcurrentRender(
if (
// do not delay if we're inside an act() scope
!(
__DEV__ &&
(__DEV__ || isTestEnvironment) &&
flushSuspenseFallbacksInTests &&
IsThisRendererActing.current
)
Expand Down Expand Up @@ -946,7 +947,7 @@ function finishConcurrentRender(
if (
// do not delay if we're inside an act() scope
!(
__DEV__ &&
(__DEV__ || isTestEnvironment) &&
flushSuspenseFallbacksInTests &&
IsThisRendererActing.current
) &&
Expand Down
122 changes: 1 addition & 121 deletions packages/shared/ReactFeatureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,124 +7,4 @@
* @flow strict
*/

export const enableUserTimingAPI = __DEV__;

// Helps identify side effects in render-phase lifecycle hooks and setState
// reducers by double invoking them in Strict Mode.
export const debugRenderPhaseSideEffectsForStrictMode = __DEV__;

// To preserve the "Pause on caught exceptions" behavior of the debugger, we
// replay the begin phase of a failed component inside invokeGuardedCallback.
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;

// Warn about deprecated, async-unsafe lifecycles; relates to RFC #6:
export const warnAboutDeprecatedLifecycles = true;

// Gather advanced timing metrics for Profiler subtrees.
export const enableProfilerTimer = __PROFILE__;

// Trace which interactions trigger each commit.
export const enableSchedulerTracing = __PROFILE__;

// SSR experiments
export const enableSuspenseServerRenderer = __EXPERIMENTAL__;
export const enableSelectiveHydration = __EXPERIMENTAL__;

// Flight experiments
export const enableBlocksAPI = __EXPERIMENTAL__;

// Only used in www builds.
export const enableSchedulerDebugging = false;

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

// Disable javascript: URL strings in href for XSS protection.
export const disableJavaScriptURLs = false;

// Warns when a combination of updates on a dom can cause a style declaration
// that clashes with a previous one https://github.com/facebook/react/pull/14181
export const warnAboutShorthandPropertyCollision = true;

// Experimental React Flare event system and event components support.
export const enableDeprecatedFlareAPI = false;

// Experimental Host Component support.
export const enableFundamentalAPI = false;

// Experimental Scope support.
export const enableScopeAPI = false;

// New API for JSX transforms to target - https://github.com/reactjs/rfcs/pull/107

// We will enforce mocking scheduler with scheduler/unstable_mock at some point. (v17?)
// Till then, we warn about the missing mock, but still fallback to a legacy mode compatible version
export const warnAboutUnmockedScheduler = false;

// For tests, we flush suspense fallbacks in an act scope;
// *except* in some of our own tests, where we test incremental loading states.
export const flushSuspenseFallbacksInTests = true;

// Add a callback property to suspense to notify which promises are currently
// in the update queue. This allows reporting and tracing of what is causing
// the user to see a loading state.
// Also allows hydration callbacks to fire when a dehydrated boundary gets
// hydrated or deleted.
export const enableSuspenseCallback = false;

// Part of the simplification of React.createElement so we can eventually move
// from React.createElement to React.jsx
// https://github.com/reactjs/rfcs/blob/createlement-rfc/text/0000-create-element-changes.md
export const warnAboutDefaultPropsOnFunctionComponents = false;

export const disableSchedulerTimeoutBasedOnReactExpirationTime = false;

export const enableTrustedTypesIntegration = false;

// Controls sequence of passive effect destroy and create functions.
// If this flag is off, destroy and create functions may be interleaved.
// When the flag is on, all destroy functions will be run (for all fibers)
// before any create functions are run, similar to how layout effects work.
// This flag provides a killswitch if that proves to break existing code somehow.
export const runAllPassiveEffectDestroysBeforeCreates = false;

// Controls behavior of deferred effect destroy functions during unmount.
// Previously these functions were run during commit (along with layout effects).
// Ideally we should delay these until after commit for performance reasons.
// This flag provides a killswitch if that proves to break existing code somehow.
//
// WARNING This flag only has an affect if used with runAllPassiveEffectDestroysBeforeCreates.
export const deferPassiveEffectCleanupDuringUnmount = false;

// Enables a warning when trying to spread a 'key' to an element;
// a deprecated pattern we want to get rid of in the future
export const warnAboutSpreadingKeyToJSX = false;

// Internal-only attempt to debug a React Native issue. See D20130868.
export const throwEarlyForMysteriousError = false;

// --------------------------
// Future APIs to be deprecated
// --------------------------

// Prevent the value and checked attributes from syncing
// with their related DOM properties
export const disableInputAttributeSyncing = false;

export const warnAboutStringRefs = false;

export const disableLegacyContext = false;

// Disables children for <textarea> elements
export const disableTextareaChildren = false;

// Disables Maps as ReactElement children
export const disableMapsAsChildren = false;

// We should remove this flag once the above flag becomes enabled
export const warnUnstableRenderSubtreeIntoContainer = false;

// Modern event system where events get registered at roots
export const enableModernEventSystem = false;
export * from './forks/ReactFeatureFlags.default';
Loading

0 comments on commit c5a591c

Please sign in to comment.