Skip to content

Commit

Permalink
handle react-dom/test-utils deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
etrepum committed May 7, 2024
1 parent 0cf183d commit 38ab551
Show file tree
Hide file tree
Showing 17 changed files with 39 additions and 18 deletions.
1 change: 1 addition & 0 deletions packages/lexical-devtools/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
"shared/environment": ["../shared/src/environment.ts"],
"shared/invariant": ["../shared/src/invariant.ts"],
"shared/normalizeClassNames": ["../shared/src/normalizeClassNames.ts"],
"shared/react-test-utils": ["../shared/src/react-test-utils.ts"],
"shared/simpleDiffWithCursor": ["../shared/src/simpleDiffWithCursor.ts"],
"shared/useLayoutEffect": ["../shared/src/useLayoutEffect.ts"],
"shared/warnOnlyOnce": ["../shared/src/warnOnlyOnce.ts"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
import {createTestEditor, TestComposer} from 'lexical/src/__tests__/utils';
import React from 'react';
import {createRoot, Root} from 'react-dom/client';
import * as ReactTestUtils from 'react-dom/test-utils';
import * as ReactTestUtils from 'shared/react-test-utils';

describe('LexicalHistory tests', () => {
let container: HTMLDivElement | null = null;
Expand Down Expand Up @@ -128,8 +128,8 @@ describe('LexicalHistory tests', () => {
await ReactTestUtils.act(async () => {
await editor.update(() => {
const root = $getRoot();
const paragraph1 = createParagraphNode('AAA');
const paragraph2 = createParagraphNode('BBB');
const paragraph1 = $createParagraphNode_('AAA');
const paragraph2 = $createParagraphNode_('BBB');

// The editor has one child that is an empty
// paragraph Node.
Expand Down Expand Up @@ -223,7 +223,7 @@ describe('LexicalHistory tests', () => {
await ReactTestUtils.act(async () => {
await editor.update(() => {
const root = $getRoot();
const paragraph = createParagraphNode('foo');
const paragraph = $createParagraphNode_('foo');
root.append(paragraph);
});
});
Expand Down Expand Up @@ -261,7 +261,7 @@ describe('LexicalHistory tests', () => {
await ReactTestUtils.act(async () => {
await editor.update(() => {
const root = $getRoot();
const paragraph = createParagraphNode('foo');
const paragraph = $createParagraphNode_('foo');
root.append(paragraph);
});
});
Expand Down Expand Up @@ -315,7 +315,7 @@ describe('LexicalHistory tests', () => {
});
});

const createParagraphNode = (text: string) => {
const $createParagraphNode_ = (text: string) => {
const paragraph = $createParagraphNode();
const textNode = $createTextNode(text);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from 'lexical';
import * as React from 'react';
import {createRoot, Root} from 'react-dom/client';
import * as ReactTestUtils from 'react-dom/test-utils';
import * as ReactTestUtils from 'shared/react-test-utils';

import {LexicalComposer} from '../../LexicalComposer';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
} from 'lexical';
import * as React from 'react';
import {createRoot, Root} from 'react-dom/client';
import * as ReactTestUtils from 'react-dom/test-utils';
import * as ReactTestUtils from 'shared/react-test-utils';

import {LexicalComposer} from '../../LexicalComposer';
import {ContentEditable} from '../../LexicalContentEditable';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import * as React from 'react';
import {createRef} from 'react';
import {createRoot, Root} from 'react-dom/client';
import * as ReactTestUtils from 'react-dom/test-utils';
import * as ReactTestUtils from 'shared/react-test-utils';

import {useLexicalIsTextContentEmpty} from '../../useLexicalIsTextContentEmpty';

Expand Down
2 changes: 1 addition & 1 deletion packages/lexical-react/src/__tests__/unit/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {LexicalEditor} from 'lexical';
import * as React from 'react';
import {Container} from 'react-dom';
import {createRoot, Root} from 'react-dom/client';
import * as ReactTestUtils from 'react-dom/test-utils';
import * as ReactTestUtils from 'shared/react-test-utils';
import * as Y from 'yjs';

import {useCollaborationContext} from '../../LexicalCollaborationContext';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import {
TestComposer,
} from 'lexical/src/__tests__/utils';
import {createRoot} from 'react-dom/client';
import * as ReactTestUtils from 'react-dom/test-utils';
import * as ReactTestUtils from 'shared/react-test-utils';

import {
applySelectionInputs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
import {createTestEditor} from 'lexical/src/__tests__/utils';
import {createRef, useEffect, useMemo} from 'react';
import {createRoot, Root} from 'react-dom/client';
import * as ReactTestUtils from 'react-dom/test-utils';
import * as ReactTestUtils from 'shared/react-test-utils';

describe('table selection', () => {
let originalText: TextNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {TableCellNode, TableNode, TableRowNode} from '@lexical/table';
import {LexicalEditor} from 'lexical';
import {initializeClipboard, TestComposer} from 'lexical/src/__tests__/utils';
import {createRoot} from 'react-dom/client';
import * as ReactTestUtils from 'react-dom/test-utils';
import * as ReactTestUtils from 'shared/react-test-utils';

jest.mock('shared/environment', () => {
const originalModule = jest.requireActual('shared/environment');
Expand Down
2 changes: 1 addition & 1 deletion packages/lexical/src/__tests__/unit/LexicalEditor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import {
} from 'react';
import {createPortal} from 'react-dom';
import {createRoot, Root} from 'react-dom/client';
import * as ReactTestUtils from 'react-dom/test-utils';
import * as ReactTestUtils from 'shared/react-test-utils';

import {
$createTestDecoratorNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
TestComposer,
} from 'lexical/src/__tests__/utils';
import {createRoot, Root} from 'react-dom/client';
import * as ReactTestUtils from 'react-dom/test-utils';
import * as ReactTestUtils from 'shared/react-test-utils';

import {
INSERT_UNORDERED_LIST_COMMAND,
Expand Down
2 changes: 1 addition & 1 deletion packages/lexical/src/__tests__/utils/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {format} from 'prettier';
import * as React from 'react';
import {createRef} from 'react';
import {createRoot} from 'react-dom/client';
import * as ReactTestUtils from 'react-dom/test-utils';
import * as ReactTestUtils from 'shared/react-test-utils';

import {CreateEditorArgs, LexicalNodeReplacement} from '../../LexicalEditor';
import {resetRandomKey} from '../../LexicalUtils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import * as React from 'react';
import {createRef, useEffect} from 'react';
import {createRoot} from 'react-dom/client';
import * as ReactTestUtils from 'react-dom/test-utils';
import * as ReactTestUtils from 'shared/react-test-utils';

import {
$createTestElementNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
import * as React from 'react';
import {createRef, useEffect, useMemo} from 'react';
import {createRoot} from 'react-dom/client';
import * as ReactTestUtils from 'react-dom/test-utils';
import * as ReactTestUtils from 'shared/react-test-utils';

import {
$createTestSegmentedNode,
Expand Down
18 changes: 18 additions & 0 deletions packages/shared/src/react-test-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import * as React from 'react';
import * as ReactTestUtils from 'react-dom/test-utils';

/**
* React 19 moved act from react-dom/test-utils to react
* https://react.dev/blog/2024/04/25/react-19-upgrade-guide#removed-react-dom-test-utils
*/
export const act =
'act' in React
? (React.act as typeof ReactTestUtils.act)
: ReactTestUtils.act;
1 change: 1 addition & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
"shared/normalizeClassNames": [
"./packages/shared/src/normalizeClassNames.ts"
],
"shared/react-test-utils": ["./packages/shared/src/react-test-utils.ts"],
"shared/simpleDiffWithCursor": [
"./packages/shared/src/simpleDiffWithCursor.ts"
],
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
"shared/normalizeClassNames": [
"./packages/shared/src/normalizeClassNames.ts"
],
"shared/react-test-utils": ["./packages/shared/src/react-test-utils.ts"],
"shared/simpleDiffWithCursor": [
"./packages/shared/src/simpleDiffWithCursor.ts"
],
Expand Down

0 comments on commit 38ab551

Please sign in to comment.