Skip to content

Commit

Permalink
Move internalAct to internal-test-utils package
Browse files Browse the repository at this point in the history
This is not a public API. We only use it for our internal tests, the
ones in this repo. Let's move it to this private package. Practically
speaking this will also let us use async/await in the implementation.
  • Loading branch information
acdlite committed Mar 8, 2023
1 parent d814473 commit 3e19180
Show file tree
Hide file tree
Showing 82 changed files with 87 additions and 86 deletions.
2 changes: 2 additions & 0 deletions packages/internal-test-utils/ReactInternalTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {diff} from 'jest-diff';
import {equals} from '@jest/expect-utils';
import enqueueTask from './enqueueTask';

export {act} from './internalAct';

function assertYieldsWereCleared(Scheduler) {
const actualYields = Scheduler.unstable_clearLog();
if (actualYields.length !== 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const {
waitForThrow,
assertLog,
} = require('internal-test-utils');
const act = require('jest-react').act;
const act = require('internal-test-utils').act;
const Scheduler = require('scheduler/unstable_mock');

describe('ReactInternalTestUtils', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ export function act<T>(scope: () => Thenable<T>): Thenable<T> {
}
};

// TODO: This would be way simpler if we could use async/await. Move this
// function to the internal-test-utils package.
// TODO: This would be way simpler if we used async/await.
try {
const result = scope();
if (
Expand Down
4 changes: 2 additions & 2 deletions packages/react-client/src/__tests__/ReactFlight-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('ReactFlight', () => {
ReactNoop = require('react-noop-renderer');
ReactNoopFlightServer = require('react-noop-renderer/flight-server');
ReactNoopFlightClient = require('react-noop-renderer/flight-client');
act = require('jest-react').act;
act = require('internal-test-utils').act;
Scheduler = require('scheduler');
const InternalTestUtils = require('internal-test-utils');
assertLog = InternalTestUtils.assertLog;
Expand Down Expand Up @@ -1184,7 +1184,7 @@ describe('ReactFlight', () => {
ReactNoop = require('react-noop-renderer');
ReactNoopFlightServer = require('react-noop-renderer/flight-server');
ReactNoopFlightClient = require('react-noop-renderer/flight-client');
act = require('jest-react').act;
act = require('internal-test-utils').act;
Scheduler = require('scheduler');

await act(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('ReactHooksInspectionIntegration', () => {
React = require('react');
ReactTestRenderer = require('react-test-renderer');
Scheduler = require('scheduler');
act = require('jest-react').act;
act = require('internal-test-utils').act;
ReactDebugTools = require('react-debug-tools');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ describe('InspectedElement', () => {
ReactDOM = require('react-dom');
ReactDOMClient = require('react-dom/client');
PropTypes = require('prop-types');
TestUtilsAct = require('jest-react').act;
TestUtilsAct = require('internal-test-utils').act;
TestRenderer = utils.requireTestRenderer();
TestRendererAct = require('jest-react').act;
TestRendererAct = require('internal-test-utils').act;

BridgeContext =
require('react-devtools-shared/src/devtools/views/context').BridgeContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('Store component filters', () => {
React = require('react');
Types = require('react-devtools-shared/src/types');
utils = require('./utils');
internalAct = require('jest-react').act;
internalAct = require('internal-test-utils').act;

legacyRender = utils.legacyRender;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('ReactDOMConsoleErrorReporting', () => {

beforeEach(() => {
jest.resetModules();
act = require('jest-react').act;
act = require('internal-test-utils').act;
React = require('react');
ReactDOM = require('react-dom');
ReactDOMClient = require('react-dom/client');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('ReactDOMFiberAsync', () => {
React = require('react');
ReactDOM = require('react-dom');
ReactDOMClient = require('react-dom/client');
act = require('jest-react').act;
act = require('internal-test-utils').act;
Scheduler = require('scheduler');

const InternalTestUtils = require('internal-test-utils');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('ReactDOMFizzShellHydration', () => {
React = require('react');
ReactDOMClient = require('react-dom/client');
Scheduler = require('scheduler');
clientAct = require('jest-react').act;
clientAct = require('internal-test-utils').act;
ReactDOMFizzServer = require('react-dom/server');
Stream = require('stream');

Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/src/__tests__/ReactDOMHooks-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('ReactDOMHooks', () => {
ReactDOM = require('react-dom');
ReactDOMClient = require('react-dom/client');
Scheduler = require('scheduler');
act = require('jest-react').act;
act = require('internal-test-utils').act;

container = document.createElement('div');
document.body.appendChild(container);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
ReactDOM = require('react-dom');
ReactDOMClient = require('react-dom/client');
Scheduler = require('scheduler');
act = require('jest-react').act;
act = require('internal-test-utils').act;

const InternalTestUtils = require('internal-test-utils');
assertLog = InternalTestUtils.assertLog;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('ReactDOMNestedEvents', () => {
React = require('react');
ReactDOMClient = require('react-dom/client');
Scheduler = require('scheduler');
act = require('jest-react').act;
act = require('internal-test-utils').act;
useState = React.useState;

const InternalTestUtils = require('internal-test-utils');
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/src/__tests__/ReactDOMRoot-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('ReactDOMRoot', () => {
ReactDOMClient = require('react-dom/client');
ReactDOMServer = require('react-dom/server');
Scheduler = require('scheduler');
act = require('jest-react').act;
act = require('internal-test-utils').act;
useEffect = React.useEffect;

const InternalTestUtils = require('internal-test-utils');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('ReactDOMSafariMicrotaskBug-test', () => {
container = document.createElement('div');
React = require('react');
ReactDOMClient = require('react-dom/client');
act = require('jest-react').act;
act = require('internal-test-utils').act;

document.body.appendChild(container);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe('ReactDOMServerPartialHydration', () => {
React = require('react');
ReactDOM = require('react-dom');
ReactDOMClient = require('react-dom/client');
act = require('jest-react').act;
act = require('internal-test-utils').act;
ReactDOMServer = require('react-dom/server');
Scheduler = require('scheduler');
Suspense = React.Suspense;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ describe('ReactDOMServerSelectiveHydration', () => {
ReactDOM = require('react-dom');
ReactDOMClient = require('react-dom/client');
ReactDOMServer = require('react-dom/server');
act = require('jest-react').act;
act = require('internal-test-utils').act;
Scheduler = require('scheduler');
Suspense = React.Suspense;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function initModules() {
ReactDOMClient = require('react-dom/client');
ReactDOMServer = require('react-dom/server');
ReactTestUtils = require('react-dom/test-utils');
act = require('jest-react').act;
act = require('internal-test-utils').act;
if (gate(flags => flags.enableSuspenseList)) {
SuspenseList = React.SuspenseList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('ReactDOMSuspensePlaceholder', () => {
ReactDOM = require('react-dom');
ReactCache = require('react-cache');
Scheduler = require('scheduler');
act = require('jest-react').act;
act = require('internal-test-utils').act;
Suspense = React.Suspense;
container = document.createElement('div');
document.body.appendChild(container);
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/src/__tests__/ReactDOMUseId-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('useId', () => {
JSDOM = require('jsdom').JSDOM;
React = require('react');
ReactDOMClient = require('react-dom/client');
clientAct = require('jest-react').act;
clientAct = require('internal-test-utils').act;
ReactDOMFizzServer = require('react-dom/server');
Stream = require('stream');
Suspense = React.Suspense;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('ReactErrorBoundaries', () => {
ReactFeatureFlags.skipUnmountedBoundaries = true;
ReactDOM = require('react-dom');
React = require('react');
act = require('jest-react').act;
act = require('internal-test-utils').act;
Scheduler = require('scheduler');

const InternalTestUtils = require('internal-test-utils');
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/src/__tests__/ReactUpdates-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('ReactUpdates', () => {
ReactDOM = require('react-dom');
ReactDOMClient = require('react-dom/client');
ReactTestUtils = require('react-dom/test-utils');
act = require('jest-react').act;
act = require('internal-test-utils').act;
Scheduler = require('scheduler');

const InternalTestUtils = require('internal-test-utils');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ beforeEach(() => {
React = require('react');
ReactNoop = require('react-noop-renderer');
Scheduler = require('scheduler');
act = require('jest-react').act;
act = require('internal-test-utils').act;

const InternalTestUtils = require('internal-test-utils');
assertLog = InternalTestUtils.assertLog;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = function (initModules) {

function resetModules() {
({ReactDOM, ReactDOMServer} = initModules());
act = require('jest-react').act;
act = require('internal-test-utils').act;
}

function shouldUseDocument(reactElement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('DOMPluginEventSystem', () => {
ReactDOMClient = require('react-dom/client');
Scheduler = require('scheduler');
ReactDOMServer = require('react-dom/server');
act = require('jest-react').act;
act = require('internal-test-utils').act;

const InternalTestUtils = require('internal-test-utils');
waitForAll = InternalTestUtils.waitForAll;
Expand Down Expand Up @@ -1279,7 +1279,7 @@ describe('DOMPluginEventSystem', () => {
ReactDOMClient = require('react-dom/client');
Scheduler = require('scheduler');
ReactDOMServer = require('react-dom/server');
act = require('jest-react').act;
act = require('internal-test-utils').act;

const InternalTestUtils = require('internal-test-utils');
waitForAll = InternalTestUtils.waitForAll;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('ChangeEventPlugin', () => {
React = require('react');
ReactDOM = require('react-dom');
ReactDOMClient = require('react-dom/client');
act = require('jest-react').act;
act = require('internal-test-utils').act;
Scheduler = require('scheduler');

const InternalTestUtils = require('internal-test-utils');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ describe('SimpleEventPlugin', function () {
assertLog = InternalTestUtils.assertLog;
waitForAll = InternalTestUtils.waitForAll;

act = require('jest-react').act;
act = require('internal-test-utils').act;
});

it('flushes pending interactive work before exiting event handler', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function initializeModules(hasPointerEvents) {
ReactDOM = require('react-dom');
ReactDOMClient = require('react-dom/client');
Scheduler = require('scheduler');
act = require('jest-react').act;
act = require('internal-test-utils').act;

// TODO: This import throws outside of experimental mode. Figure out better
// strategy for gated imports.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('ReactFabric', () => {
require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface')
.ReactNativeViewConfigRegistry.register;

act = require('jest-react').act;
act = require('internal-test-utils').act;
});

it('should be able to create and render a native component', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async function mockRenderKeys(keyLists) {
const createReactNativeComponentClass =
require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface')
.ReactNativeViewConfigRegistry.register;
const {act} = require('jest-react');
const act = require('jest-react').act;

const mockContainerTag = 11;
const MockView = createReactNativeComponentClass('RCTMockView', () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('ReactSuspenseWithNoopRenderer', () => {
React = require('react');
ReactNoop = require('react-noop-renderer');
Scheduler = require('scheduler');
act = require('jest-react').act;
act = require('internal-test-utils').act;
Suspense = React.Suspense;
useState = React.useState;

Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/__tests__/ReactCache-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('ReactCache', () => {
ReactNoop = require('react-noop-renderer');
Cache = React.unstable_Cache;
Scheduler = require('scheduler');
act = require('jest-react').act;
act = require('internal-test-utils').act;
Suspense = React.Suspense;
cache = React.cache;
Offscreen = React.unstable_Offscreen;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('ReactClassSetStateCallback', () => {
React = require('react');
ReactNoop = require('react-noop-renderer');
Scheduler = require('scheduler');
act = require('jest-react').act;
act = require('internal-test-utils').act;

const InternalTestUtils = require('internal-test-utils');
assertLog = InternalTestUtils.assertLog;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('ReactConcurrentErrorRecovery', () => {
React = require('react');
ReactNoop = require('react-noop-renderer');
Scheduler = require('scheduler');
act = require('jest-react').act;
act = require('internal-test-utils').act;
Suspense = React.Suspense;
startTransition = React.startTransition;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('ReactLazyContextPropagation', () => {
React = require('react');
ReactNoop = require('react-noop-renderer');
Scheduler = require('scheduler');
act = require('jest-react').act;
act = require('internal-test-utils').act;
useState = React.useState;
useContext = React.useContext;
Suspense = React.Suspense;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('ReactDeferredValue', () => {
React = require('react');
ReactNoop = require('react-noop-renderer');
Scheduler = require('scheduler');
act = require('jest-react').act;
act = require('internal-test-utils').act;
startTransition = React.startTransition;
useDeferredValue = React.useDeferredValue;
useMemo = React.useMemo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('ReactEffectOrdering', () => {
React = require('react');
ReactNoop = require('react-noop-renderer');
Scheduler = require('scheduler');
act = require('jest-react').act;
act = require('internal-test-utils').act;
useEffect = React.useEffect;
useLayoutEffect = React.useLayoutEffect;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('ReactExpiration', () => {
React = require('react');
ReactNoop = require('react-noop-renderer');
Scheduler = require('scheduler');
act = require('jest-react').act;
act = require('internal-test-utils').act;
startTransition = React.startTransition;
useState = React.useState;
useEffect = React.useEffect;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('ReactFlushSync', () => {
React = require('react');
ReactNoop = require('react-noop-renderer');
Scheduler = require('scheduler');
act = require('jest-react').act;
act = require('internal-test-utils').act;
useState = React.useState;
useEffect = React.useEffect;
startTransition = React.startTransition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('ReactHooks', () => {
ReactTestRenderer = require('react-test-renderer');
Scheduler = require('scheduler');
ReactDOMServer = require('react-dom/server');
act = require('jest-react').act;
act = require('internal-test-utils').act;

const InternalTestUtils = require('internal-test-utils');
assertLog = InternalTestUtils.assertLog;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('ReactHooksWithNoopRenderer', () => {
React = require('react');
ReactNoop = require('react-noop-renderer');
Scheduler = require('scheduler');
act = require('jest-react').act;
act = require('internal-test-utils').act;
useState = React.useState;
useReducer = React.useReducer;
useEffect = React.useEffect;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('ReactIncrementalErrorHandling', () => {
React = require('react');
ReactNoop = require('react-noop-renderer');
Scheduler = require('scheduler');
act = require('jest-react').act;
act = require('internal-test-utils').act;

const InternalTestUtils = require('internal-test-utils');
assertLog = InternalTestUtils.assertLog;
Expand Down
Loading

0 comments on commit 3e19180

Please sign in to comment.