Skip to content

Commit 8f01a08

Browse files
committed
Bring back OSS testing builds
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 some tests in TestUtilsAct to reflect this
1 parent 62861bb commit 8f01a08

26 files changed

+196
-134
lines changed

packages/react-dom/npm/testing.js

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
if (process.env.NODE_ENV === 'production') {
4+
// DCE check should happen before ReactDOM bundle executes so that
5+
// DevTools can report bad minification during injection.
6+
module.exports = require('./cjs/react-dom-unstable-testing.production.min.js');
7+
} else {
8+
module.exports = require('./cjs/react-dom-unstable-testing.development.js');
9+
}

packages/react-dom/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"unstable-fizz.browser.js",
4040
"unstable-fizz.node.js",
4141
"unstable-native-dependencies.js",
42+
"unstable-testing.js",
4243
"cjs/",
4344
"umd/"
4445
],

packages/react-dom/src/__tests__/ReactTestUtilsAct-test.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
let React;
1111
let ReactDOM;
12-
let ReactTestUtils;
1312
let SchedulerTracing;
1413
let Scheduler;
1514
let act;
@@ -25,7 +24,7 @@ function sleep(period) {
2524
});
2625
}
2726

28-
describe('ReactTestUtils.act()', () => {
27+
describe('act()', () => {
2928
// first we run all the tests with concurrent mode
3029
if (__EXPERIMENTAL__) {
3130
let concurrentRoot = null;
@@ -155,10 +154,9 @@ function runActTests(label, render, unmount, rerender) {
155154
jest.resetModules();
156155
React = require('react');
157156
ReactDOM = require('react-dom');
158-
ReactTestUtils = require('react-dom/test-utils');
159157
SchedulerTracing = require('scheduler/tracing');
160158
Scheduler = require('scheduler');
161-
act = ReactTestUtils.act;
159+
act = ReactDOM.act;
162160
container = document.createElement('div');
163161
document.body.appendChild(container);
164162
});
@@ -721,7 +719,7 @@ function runActTests(label, render, unmount, rerender) {
721719
});
722720

723721
describe('suspense', () => {
724-
if (__DEV__ && __EXPERIMENTAL__) {
722+
if (__EXPERIMENTAL__) {
725723
// todo - remove __DEV__ check once we start using testing builds
726724
it('triggers fallbacks if available', async () => {
727725
let resolved = false;
@@ -792,7 +790,7 @@ function runActTests(label, render, unmount, rerender) {
792790
}
793791
});
794792
describe('warn in prod mode', () => {
795-
it('warns if you try to use act() in prod mode', () => {
793+
xit('warns if you try to use act() in prod mode', () => {
796794
const spy = spyOnDevAndProd(console, 'error');
797795

798796
act(() => {});

packages/react-reconciler/src/ReactFiberWorkLoop.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
warnAboutUnmockedScheduler,
2929
flushSuspenseFallbacksInTests,
3030
disableSchedulerTimeoutBasedOnReactExpirationTime,
31+
isTestEnvironment,
3132
} from 'shared/ReactFeatureFlags';
3233
import ReactSharedInternals from 'shared/ReactSharedInternals';
3334
import invariant from 'shared/invariant';
@@ -789,7 +790,7 @@ function finishConcurrentRender(
789790
hasNotProcessedNewUpdates &&
790791
// do not delay if we're inside an act() scope
791792
!(
792-
__DEV__ &&
793+
(__DEV__ || isTestEnvironment) &&
793794
flushSuspenseFallbacksInTests &&
794795
IsThisRendererActing.current
795796
)
@@ -855,7 +856,7 @@ function finishConcurrentRender(
855856
if (
856857
// do not delay if we're inside an act() scope
857858
!(
858-
__DEV__ &&
859+
(__DEV__ || isTestEnvironment) &&
859860
flushSuspenseFallbacksInTests &&
860861
IsThisRendererActing.current
861862
)
@@ -946,7 +947,7 @@ function finishConcurrentRender(
946947
if (
947948
// do not delay if we're inside an act() scope
948949
!(
949-
__DEV__ &&
950+
(__DEV__ || isTestEnvironment) &&
950951
flushSuspenseFallbacksInTests &&
951952
IsThisRendererActing.current
952953
) &&

0 commit comments

Comments
 (0)