Skip to content

Commit a716d96

Browse files
gnoffrickhanlonii
authored andcommitted
[TestUtils] Build limited test-utils (#28782)
We landed a flag to disable test utils in many builds but we need to fork the entrypoint to make it work with tests properly. This also removes test-utils implementations from builds that do not support it. Currently in OSS builds the only thing in test-utils is a reexport of `act`
1 parent f765aa5 commit a716d96

File tree

6 files changed

+996
-971
lines changed

6 files changed

+996
-971
lines changed

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

Lines changed: 103 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
'use strict';
1111

12-
import {act} from 'internal-test-utils';
13-
import * as React from 'react';
14-
import * as ReactDOMClient from 'react-dom/client';
15-
import * as ReactDOMServer from 'react-dom/server';
16-
import * as ReactTestUtils from 'react-dom/test-utils';
12+
let React;
13+
let ReactDOMClient;
14+
let ReactDOMServer;
15+
let ReactTestUtils;
16+
let act;
1717

1818
function getTestDocument(markup) {
1919
const doc = document.implementation.createHTMLDocument('');
@@ -27,8 +27,105 @@ function getTestDocument(markup) {
2727
}
2828

2929
describe('ReactTestUtils', () => {
30+
beforeEach(() => {
31+
React = require('react');
32+
ReactDOMClient = require('react-dom/client');
33+
ReactDOMServer = require('react-dom/server');
34+
ReactTestUtils = require('react-dom/test-utils');
35+
act = require('internal-test-utils').act;
36+
});
37+
38+
// @gate !disableDOMTestUtils
3039
it('Simulate should have locally attached media events', () => {
31-
expect(Object.keys(ReactTestUtils.Simulate).sort()).toMatchSnapshot();
40+
expect(Object.keys(ReactTestUtils.Simulate).sort()).toMatchInlineSnapshot(`
41+
[
42+
"abort",
43+
"animationEnd",
44+
"animationIteration",
45+
"animationStart",
46+
"auxClick",
47+
"beforeInput",
48+
"blur",
49+
"canPlay",
50+
"canPlayThrough",
51+
"cancel",
52+
"change",
53+
"click",
54+
"close",
55+
"compositionEnd",
56+
"compositionStart",
57+
"compositionUpdate",
58+
"contextMenu",
59+
"copy",
60+
"cut",
61+
"doubleClick",
62+
"drag",
63+
"dragEnd",
64+
"dragEnter",
65+
"dragExit",
66+
"dragLeave",
67+
"dragOver",
68+
"dragStart",
69+
"drop",
70+
"durationChange",
71+
"emptied",
72+
"encrypted",
73+
"ended",
74+
"error",
75+
"focus",
76+
"gotPointerCapture",
77+
"input",
78+
"invalid",
79+
"keyDown",
80+
"keyPress",
81+
"keyUp",
82+
"load",
83+
"loadStart",
84+
"loadedData",
85+
"loadedMetadata",
86+
"lostPointerCapture",
87+
"mouseDown",
88+
"mouseEnter",
89+
"mouseLeave",
90+
"mouseMove",
91+
"mouseOut",
92+
"mouseOver",
93+
"mouseUp",
94+
"paste",
95+
"pause",
96+
"play",
97+
"playing",
98+
"pointerCancel",
99+
"pointerDown",
100+
"pointerEnter",
101+
"pointerLeave",
102+
"pointerMove",
103+
"pointerOut",
104+
"pointerOver",
105+
"pointerUp",
106+
"progress",
107+
"rateChange",
108+
"reset",
109+
"resize",
110+
"scroll",
111+
"seeked",
112+
"seeking",
113+
"select",
114+
"stalled",
115+
"submit",
116+
"suspend",
117+
"timeUpdate",
118+
"toggle",
119+
"touchCancel",
120+
"touchEnd",
121+
"touchMove",
122+
"touchStart",
123+
"transitionEnd",
124+
"volumeChange",
125+
"waiting",
126+
"wheel",
127+
]
128+
`);
32129
});
33130

34131
// @gate !disableDOMTestUtils
@@ -575,14 +672,6 @@ describe('ReactTestUtils', () => {
575672
});
576673
expect(idCallOrder).toEqual([CHILD]);
577674
});
578-
579-
// @gate disableDOMTestUtils
580-
it('throws', async () => {
581-
expect(ReactTestUtils.Simulate.click).toThrow(
582-
'`Simulate` was removed from `react-dom/test-utils`. ' +
583-
'See https://react.dev/warnings/react-dom-test-utils for more info.',
584-
);
585-
});
586675
});
587676

588677
// @gate !disableDOMTestUtils
@@ -626,14 +715,6 @@ describe('ReactTestUtils', () => {
626715
expect(renderedComponentType).toBe(instance);
627716
});
628717

629-
// @gate disableDOMTestUtils
630-
it('throws on every removed function', async () => {
631-
expect(ReactTestUtils.isDOMComponent).toThrow(
632-
'`isDOMComponent` was removed from `react-dom/test-utils`. ' +
633-
'See https://react.dev/warnings/react-dom-test-utils for more info.',
634-
);
635-
});
636-
637718
// @gate __DEV__
638719
it('warns when using `act`', () => {
639720
expect(() => {

packages/react-dom/src/__tests__/__snapshots__/ReactTestUtils-test.js.snap

Lines changed: 0 additions & 91 deletions
This file was deleted.

0 commit comments

Comments
 (0)