Commit d17086c
authored
Decouple public, internal act implementation (#19745)
In the next major release, we intend to drop support for using the `act`
testing helper in production. (It already fires a warning.) The
rationale is that, in order for `act` to work, you must either mock the
testing environment or add extra logic at runtime. Mocking the testing
environment isn't ideal because it requires extra set up for the user.
Extra logic at runtime is fine only in development mode — we don't want
to slow down the production builds.
Since most people only run their tests in development mode, dropping
support for production should be fine; if there's demand, we can add it
back later using a special testing build that is identical to the
production build except for the additional testing logic.
One blocker for removing production support is that we currently use
`act` to test React itself. We must test React in both development and
production modes.
So, the solution is to fork `act` into separate public and
internal implementations:
- *public implementation of `act`* – exposed to users, only works in
development mode, uses special runtime logic, does not support partial
rendering
- *internal implementation of `act`* – private, works in both
development and productionm modes, only used by the React Core test
suite, uses no special runtime logic, supports partial rendering (i.e.
`toFlushAndYieldThrough`)
The internal implementation should mostly match the public
implementation's behavior, but since it's a private API, it doesn't have
to match exactly. It works by mocking the test environment: it uses a
mock build of Scheduler to flush rendering tasks, and Jest's mock timers
to flush Suspense placeholders.
---
In this first commit, I've added the internal forks of `act` and
migrated our tests to use them. The public `act` implementation is
unaffected for now; I will leave refactoring/clean-up for a later step.1 parent d38ec17 commit d17086c
File tree
36 files changed
+465
-298
lines changed- packages
- react-debug-tools/src/__tests__
- react-dom/src
- __tests__
- utils
- client
- events
- __tests__
- plugins/__tests__
- test-utils
- react-interactions/events/src/dom/create-event-handle/__tests__
- react-noop-renderer/src
- react-reconciler/src
- __tests__
- react-refresh/src/__tests__
- react-test-renderer/src
- react-transport-dom-relay/src/__tests__
- react-transport-dom-webpack/src/__tests__
- react/src/__tests__
- use-subscription/src/__tests__
36 files changed
+465
-298
lines changedLines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
Lines changed: 25 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
36 | 39 | | |
37 | 40 | | |
38 | 41 | | |
| |||
47 | 50 | | |
48 | 51 | | |
49 | 52 | | |
| 53 | + | |
50 | 54 | | |
| 55 | + | |
51 | 56 | | |
52 | 57 | | |
53 | 58 | | |
| |||
999 | 1004 | | |
1000 | 1005 | | |
1001 | 1006 | | |
1002 | | - | |
1003 | | - | |
| 1007 | + | |
| 1008 | + | |
1004 | 1009 | | |
1005 | 1010 | | |
1006 | 1011 | | |
| |||
1009 | 1014 | | |
1010 | 1015 | | |
1011 | 1016 | | |
1012 | | - | |
1013 | | - | |
| 1017 | + | |
| 1018 | + | |
1014 | 1019 | | |
1015 | 1020 | | |
1016 | 1021 | | |
| |||
1021 | 1026 | | |
1022 | 1027 | | |
1023 | 1028 | | |
1024 | | - | |
1025 | | - | |
| 1029 | + | |
| 1030 | + | |
1026 | 1031 | | |
1027 | 1032 | | |
1028 | 1033 | | |
| |||
1041 | 1046 | | |
1042 | 1047 | | |
1043 | 1048 | | |
1044 | | - | |
1045 | | - | |
| 1049 | + | |
| 1050 | + | |
1046 | 1051 | | |
1047 | 1052 | | |
1048 | 1053 | | |
| |||
1051 | 1056 | | |
1052 | 1057 | | |
1053 | 1058 | | |
1054 | | - | |
1055 | | - | |
| 1059 | + | |
| 1060 | + | |
1056 | 1061 | | |
1057 | 1062 | | |
1058 | 1063 | | |
| |||
1108 | 1113 | | |
1109 | 1114 | | |
1110 | 1115 | | |
1111 | | - | |
1112 | | - | |
| 1116 | + | |
| 1117 | + | |
1113 | 1118 | | |
1114 | 1119 | | |
1115 | 1120 | | |
| |||
1179 | 1184 | | |
1180 | 1185 | | |
1181 | 1186 | | |
1182 | | - | |
| 1187 | + | |
1183 | 1188 | | |
1184 | 1189 | | |
1185 | 1190 | | |
1186 | 1191 | | |
1187 | 1192 | | |
1188 | 1193 | | |
1189 | 1194 | | |
1190 | | - | |
| 1195 | + | |
1191 | 1196 | | |
1192 | 1197 | | |
1193 | 1198 | | |
1194 | 1199 | | |
1195 | 1200 | | |
1196 | 1201 | | |
1197 | | - | |
1198 | | - | |
| 1202 | + | |
| 1203 | + | |
1199 | 1204 | | |
1200 | 1205 | | |
1201 | 1206 | | |
| |||
1221 | 1226 | | |
1222 | 1227 | | |
1223 | 1228 | | |
1224 | | - | |
| 1229 | + | |
1225 | 1230 | | |
1226 | 1231 | | |
1227 | 1232 | | |
| |||
1281 | 1286 | | |
1282 | 1287 | | |
1283 | 1288 | | |
1284 | | - | |
| 1289 | + | |
1285 | 1290 | | |
1286 | 1291 | | |
1287 | 1292 | | |
| |||
1300 | 1305 | | |
1301 | 1306 | | |
1302 | 1307 | | |
1303 | | - | |
1304 | | - | |
| 1308 | + | |
| 1309 | + | |
1305 | 1310 | | |
1306 | 1311 | | |
1307 | 1312 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
Lines changed: 15 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| 47 | + | |
46 | 48 | | |
47 | 49 | | |
48 | 50 | | |
| |||
1063 | 1065 | | |
1064 | 1066 | | |
1065 | 1067 | | |
1066 | | - | |
| 1068 | + | |
1067 | 1069 | | |
1068 | 1070 | | |
1069 | 1071 | | |
| |||
1281 | 1283 | | |
1282 | 1284 | | |
1283 | 1285 | | |
1284 | | - | |
| 1286 | + | |
1285 | 1287 | | |
1286 | 1288 | | |
1287 | 1289 | | |
| |||
1322 | 1324 | | |
1323 | 1325 | | |
1324 | 1326 | | |
1325 | | - | |
| 1327 | + | |
1326 | 1328 | | |
1327 | 1329 | | |
1328 | 1330 | | |
| |||
1356 | 1358 | | |
1357 | 1359 | | |
1358 | 1360 | | |
1359 | | - | |
| 1361 | + | |
1360 | 1362 | | |
1361 | 1363 | | |
1362 | 1364 | | |
1363 | 1365 | | |
1364 | | - | |
| 1366 | + | |
1365 | 1367 | | |
1366 | 1368 | | |
1367 | 1369 | | |
| |||
1391 | 1393 | | |
1392 | 1394 | | |
1393 | 1395 | | |
1394 | | - | |
| 1396 | + | |
1395 | 1397 | | |
1396 | 1398 | | |
1397 | 1399 | | |
| |||
1418 | 1420 | | |
1419 | 1421 | | |
1420 | 1422 | | |
1421 | | - | |
| 1423 | + | |
1422 | 1424 | | |
1423 | 1425 | | |
1424 | 1426 | | |
1425 | 1427 | | |
1426 | | - | |
| 1428 | + | |
1427 | 1429 | | |
1428 | 1430 | | |
1429 | 1431 | | |
| |||
1518 | 1520 | | |
1519 | 1521 | | |
1520 | 1522 | | |
1521 | | - | |
| 1523 | + | |
1522 | 1524 | | |
1523 | 1525 | | |
1524 | 1526 | | |
| |||
1603 | 1605 | | |
1604 | 1606 | | |
1605 | 1607 | | |
1606 | | - | |
| 1608 | + | |
1607 | 1609 | | |
1608 | 1610 | | |
1609 | 1611 | | |
| |||
1616 | 1618 | | |
1617 | 1619 | | |
1618 | 1620 | | |
1619 | | - | |
| 1621 | + | |
1620 | 1622 | | |
1621 | 1623 | | |
1622 | 1624 | | |
| |||
1703 | 1705 | | |
1704 | 1706 | | |
1705 | 1707 | | |
1706 | | - | |
| 1708 | + | |
1707 | 1709 | | |
1708 | 1710 | | |
1709 | 1711 | | |
| |||
1968 | 1970 | | |
1969 | 1971 | | |
1970 | 1972 | | |
1971 | | - | |
| 1973 | + | |
1972 | 1974 | | |
1973 | 1975 | | |
1974 | 1976 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
| 82 | + | |
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
101 | 102 | | |
102 | 103 | | |
103 | 104 | | |
| 105 | + | |
104 | 106 | | |
105 | 107 | | |
106 | 108 | | |
| |||
880 | 882 | | |
881 | 883 | | |
882 | 884 | | |
883 | | - | |
| 885 | + | |
884 | 886 | | |
885 | 887 | | |
886 | 888 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| |||
124 | 126 | | |
125 | 127 | | |
126 | 128 | | |
127 | | - | |
| 129 | + | |
128 | 130 | | |
129 | 131 | | |
130 | 132 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
0 commit comments