Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ module.exports = {
__PROFILE__: true,
__UMD__: true,
__EXPERIMENTAL__: true,
__TESTING__: true,
trustedTypes: true,
},
};
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import type {DehydratedData} from 'react-devtools-shared/src/devtools/views/Comp
import type {FrontendBridge} from 'react-devtools-shared/src/bridge';
import type Store from 'react-devtools-shared/src/devtools/store';

// unmock the testing builds
jest.unmock('react');
jest.unmock('react-dom');

describe('InspectedElementContext', () => {
let React;
let ReactDOM;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
* @flow
*/

// unmock the testing builds
jest.unmock('react');
jest.unmock('react-dom');

describe('Store (legacy)', () => {
let React;
let ReactDOM;
Expand Down
38 changes: 0 additions & 38 deletions packages/react-dom/npm/testing.js

This file was deleted.

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

if (process.env.NODE_ENV === 'production') {
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', () => {
Copy link
Contributor Author

@threepointone threepointone Mar 3, 2020

Choose a reason for hiding this comment

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

I could probably remove this test. Or rewrite it to run across the dev/prod+testing matrix. Thinking about options, not blocking a review.

const spy = spyOnDevAndProd(console, 'error');

act(() => {});
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions packages/react-reconciler/src/ReactFiberHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ function mountEffect(
): void {
if (__DEV__) {
// $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
if ('undefined' !== typeof jest) {
if (__TESTING__ || 'undefined' !== typeof jest) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this will "fix" #15439

warnIfNotCurrentlyActingEffectsInDEV(currentlyRenderingFiber);
}
}
Expand All @@ -980,7 +980,7 @@ function updateEffect(
): void {
if (__DEV__) {
// $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
if ('undefined' !== typeof jest) {
if (__TESTING__ || 'undefined' !== typeof jest) {
warnIfNotCurrentlyActingEffectsInDEV(currentlyRenderingFiber);
}
}
Expand Down Expand Up @@ -1360,7 +1360,7 @@ function dispatchAction<S, A>(
}
if (__DEV__) {
// $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
if ('undefined' !== typeof jest) {
if (__TESTING__ || 'undefined' !== typeof jest) {
warnIfNotScopedWithMatchingAct(fiber);
warnIfNotCurrentlyActingUpdatesInDev(fiber);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/react-reconciler/src/ReactFiberReconciler.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ import {
findHostInstancesForRefresh,
} from './ReactFiberHotReloading';

// used by isTestEnvironment builds
// used by __TESTING__ builds
import enqueueTask from 'shared/enqueueTask';
import * as Scheduler from 'scheduler';
// end isTestEnvironment imports
// end __TESTING__ imports

type OpaqueRoot = FiberRoot;

Expand Down Expand Up @@ -238,7 +238,7 @@ export function updateContainer(
const currentTime = requestCurrentTimeForUpdate();
if (__DEV__) {
// $FlowExpectedError - jest isn't a global, and isn't recognized outside of tests
if ('undefined' !== typeof jest) {
if (__TESTING__ || 'undefined' !== typeof jest) {
warnIfUnmockedScheduler(current);
warnIfNotScopedWithMatchingAct(current);
}
Expand Down
10 changes: 6 additions & 4 deletions packages/react-reconciler/src/ReactFiberWorkLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ function finishConcurrentRender(
hasNotProcessedNewUpdates &&
// do not delay if we're inside an act() scope
!(
__DEV__ &&
(__DEV__ || __TESTING__) &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need a plan for all the other warnings. Do we need to update all the other warning guards, too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don’t think we have to change anything?

flushSuspenseFallbacksInTests &&
IsThisRendererActing.current
)
Expand Down Expand Up @@ -855,7 +855,7 @@ function finishConcurrentRender(
if (
// do not delay if we're inside an act() scope
!(
__DEV__ &&
(__DEV__ || __TESTING__) &&
flushSuspenseFallbacksInTests &&
IsThisRendererActing.current
)
Expand Down Expand Up @@ -946,7 +946,7 @@ function finishConcurrentRender(
if (
// do not delay if we're inside an act() scope
!(
__DEV__ &&
(__DEV__ || __TESTING__) &&
flushSuspenseFallbacksInTests &&
IsThisRendererActing.current
) &&
Expand Down Expand Up @@ -2815,7 +2815,9 @@ function warnAboutRenderPhaseUpdatesInDEV(fiber) {
}

// a 'shared' variable that changes when act() opens/closes in tests.
export const IsThisRendererActing = {current: (false: boolean)};
// $FlowExpectedError avoids a shape check on IsThisRendererActing
export const IsThisRendererActing: {current: boolean} =
__DEV__ || __TESTING__ ? {current: false} : null;

export function warnIfNotScopedWithMatchingAct(fiber: Fiber): void {
if (__DEV__) {
Expand Down
7 changes: 7 additions & 0 deletions packages/react/npm/unstable-testing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-unstable-testing.production.min.js');
} else {
module.exports = require('./cjs/react-unstable-testing.development.js');
}
1 change: 1 addition & 0 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"README.md",
"build-info.json",
"index.js",
"unstable-testing.js",
"cjs/",
"umd/"
],
Expand Down
5 changes: 4 additions & 1 deletion packages/react/src/ReactSharedInternals.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const ReactSharedInternals = {
ReactCurrentDispatcher,
ReactCurrentBatchConfig,
ReactCurrentOwner,
IsSomeRendererActing,
// Used by renderers to avoid bundling object-assign twice in UMD bundles:
assign,
};
Expand All @@ -31,4 +30,8 @@ if (__DEV__) {
});
}

if (__DEV__ || __TESTING__) {
ReactSharedInternals.IsSomeRendererActing = IsSomeRendererActing;
}

export default ReactSharedInternals;
10 changes: 10 additions & 0 deletions packages/react/unstable-testing.classic.fb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

export * from './index.classic.fb';
10 changes: 10 additions & 0 deletions packages/react/unstable-testing.experimental.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

export * from './index.experimental';
10 changes: 10 additions & 0 deletions packages/react/unstable-testing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

export * from './index';
Loading