Skip to content

Commit bed8fb4

Browse files
committed
Update tests to use async act and use()
1 parent 00ddfbe commit bed8fb4

File tree

7 files changed

+383
-350
lines changed

7 files changed

+383
-350
lines changed

packages/react-devtools-shared/src/__tests__/preprocessData-test.js

Lines changed: 51 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ describe('Timeline profiler', () => {
857857
{
858858
"batchUID": 0,
859859
"depth": 0,
860-
"duration": 0.014,
860+
"duration": 0.012,
861861
"lanes": "0b0000000000000000000000000000101",
862862
"timestamp": 0.008,
863863
"type": "render-idle",
@@ -873,67 +873,51 @@ describe('Timeline profiler', () => {
873873
{
874874
"batchUID": 0,
875875
"depth": 0,
876-
"duration": 0.010,
876+
"duration": 0.008,
877877
"lanes": "0b0000000000000000000000000000101",
878878
"timestamp": 0.012,
879879
"type": "commit",
880880
},
881-
{
882-
"batchUID": 0,
883-
"depth": 1,
884-
"duration": 0.001,
885-
"lanes": "0b0000000000000000000000000000101",
886-
"timestamp": 0.02,
887-
"type": "layout-effects",
888-
},
889881
{
890882
"batchUID": 0,
891883
"depth": 0,
892884
"duration": 0.004,
893885
"lanes": "0b0000000000000000000000000000101",
894-
"timestamp": 0.023,
886+
"timestamp": 0.021,
895887
"type": "passive-effects",
896888
},
897889
],
898890
1 => [
899891
{
900892
"batchUID": 1,
901893
"depth": 0,
902-
"duration": 0.014,
894+
"duration": 0.012,
903895
"lanes": "0b0000000000000000000000000000101",
904-
"timestamp": 0.028,
896+
"timestamp": 0.026,
905897
"type": "render-idle",
906898
},
907899
{
908900
"batchUID": 1,
909901
"depth": 0,
910902
"duration": 0.003,
911903
"lanes": "0b0000000000000000000000000000101",
912-
"timestamp": 0.028,
904+
"timestamp": 0.026,
913905
"type": "render",
914906
},
915907
{
916908
"batchUID": 1,
917909
"depth": 0,
918-
"duration": 0.010,
910+
"duration": 0.008,
919911
"lanes": "0b0000000000000000000000000000101",
920-
"timestamp": 0.032,
912+
"timestamp": 0.03,
921913
"type": "commit",
922914
},
923-
{
924-
"batchUID": 1,
925-
"depth": 1,
926-
"duration": 0.001,
927-
"lanes": "0b0000000000000000000000000000101",
928-
"timestamp": 0.04,
929-
"type": "layout-effects",
930-
},
931915
{
932916
"batchUID": 1,
933917
"depth": 0,
934918
"duration": 0.003,
935919
"lanes": "0b0000000000000000000000000000101",
936-
"timestamp": 0.043,
920+
"timestamp": 0.039,
937921
"type": "passive-effects",
938922
},
939923
],
@@ -949,26 +933,26 @@ describe('Timeline profiler', () => {
949933
{
950934
"componentName": "App",
951935
"duration": 0.002,
952-
"timestamp": 0.024,
936+
"timestamp": 0.022,
953937
"type": "passive-effect-mount",
954938
"warning": null,
955939
},
956940
{
957941
"componentName": "App",
958942
"duration": 0.001,
959-
"timestamp": 0.029,
943+
"timestamp": 0.027,
960944
"type": "render",
961945
"warning": null,
962946
},
963947
{
964948
"componentName": "App",
965949
"duration": 0.001,
966-
"timestamp": 0.044,
950+
"timestamp": 0.04,
967951
"type": "passive-effect-mount",
968952
"warning": null,
969953
},
970954
],
971-
"duration": 0.046,
955+
"duration": 0.042,
972956
"flamechart": [],
973957
"internalModuleSourceToRanges": Map {
974958
undefined => [
@@ -1031,7 +1015,7 @@ describe('Timeline profiler', () => {
10311015
{
10321016
"batchUID": 0,
10331017
"depth": 0,
1034-
"duration": 0.014,
1018+
"duration": 0.012,
10351019
"lanes": "0b0000000000000000000000000000101",
10361020
"timestamp": 0.008,
10371021
"type": "render-idle",
@@ -1047,65 +1031,49 @@ describe('Timeline profiler', () => {
10471031
{
10481032
"batchUID": 0,
10491033
"depth": 0,
1050-
"duration": 0.010,
1034+
"duration": 0.008,
10511035
"lanes": "0b0000000000000000000000000000101",
10521036
"timestamp": 0.012,
10531037
"type": "commit",
10541038
},
1055-
{
1056-
"batchUID": 0,
1057-
"depth": 1,
1058-
"duration": 0.001,
1059-
"lanes": "0b0000000000000000000000000000101",
1060-
"timestamp": 0.02,
1061-
"type": "layout-effects",
1062-
},
10631039
{
10641040
"batchUID": 0,
10651041
"depth": 0,
10661042
"duration": 0.004,
10671043
"lanes": "0b0000000000000000000000000000101",
1068-
"timestamp": 0.023,
1044+
"timestamp": 0.021,
10691045
"type": "passive-effects",
10701046
},
10711047
{
10721048
"batchUID": 1,
10731049
"depth": 0,
1074-
"duration": 0.014,
1050+
"duration": 0.012,
10751051
"lanes": "0b0000000000000000000000000000101",
1076-
"timestamp": 0.028,
1052+
"timestamp": 0.026,
10771053
"type": "render-idle",
10781054
},
10791055
{
10801056
"batchUID": 1,
10811057
"depth": 0,
10821058
"duration": 0.003,
10831059
"lanes": "0b0000000000000000000000000000101",
1084-
"timestamp": 0.028,
1060+
"timestamp": 0.026,
10851061
"type": "render",
10861062
},
10871063
{
10881064
"batchUID": 1,
10891065
"depth": 0,
1090-
"duration": 0.010,
1066+
"duration": 0.008,
10911067
"lanes": "0b0000000000000000000000000000101",
1092-
"timestamp": 0.032,
1068+
"timestamp": 0.03,
10931069
"type": "commit",
10941070
},
1095-
{
1096-
"batchUID": 1,
1097-
"depth": 1,
1098-
"duration": 0.001,
1099-
"lanes": "0b0000000000000000000000000000101",
1100-
"timestamp": 0.04,
1101-
"type": "layout-effects",
1102-
},
11031071
{
11041072
"batchUID": 1,
11051073
"depth": 0,
11061074
"duration": 0.003,
11071075
"lanes": "0b0000000000000000000000000000101",
1108-
"timestamp": 0.043,
1076+
"timestamp": 0.039,
11091077
"type": "passive-effects",
11101078
},
11111079
],
@@ -1149,7 +1117,7 @@ describe('Timeline profiler', () => {
11491117
{
11501118
"componentName": "App",
11511119
"lanes": "0b0000000000000000000000000000101",
1152-
"timestamp": 0.025,
1120+
"timestamp": 0.023,
11531121
"type": "schedule-state-update",
11541122
"warning": null,
11551123
},
@@ -1254,6 +1222,15 @@ describe('Timeline profiler', () => {
12541222
let promise = null;
12551223
let resolvedValue = null;
12561224
function readValue(value) {
1225+
if (React.use) {
1226+
if (promise === null) {
1227+
promise = Promise.resolve(true).then(() => {
1228+
return value;
1229+
});
1230+
promise.displayName = 'Testing displayName';
1231+
}
1232+
return React.use(promise);
1233+
}
12571234
if (resolvedValue !== null) {
12581235
return resolvedValue;
12591236
} else if (promise === null) {
@@ -1273,7 +1250,7 @@ describe('Timeline profiler', () => {
12731250
const testMarks = [creactCpuProfilerSample()];
12741251

12751252
const root = ReactDOMClient.createRoot(document.createElement('div'));
1276-
utils.act(() =>
1253+
await utils.actAsync(() =>
12771254
root.render(
12781255
<React.Suspense fallback="Loading...">
12791256
<Component />
@@ -1823,6 +1800,14 @@ describe('Timeline profiler', () => {
18231800
let promise = null;
18241801
let resolvedValue = null;
18251802
function readValue(value) {
1803+
if (React.use) {
1804+
if (promise === null) {
1805+
promise = Promise.resolve(true).then(() => {
1806+
return value;
1807+
});
1808+
}
1809+
return React.use(promise);
1810+
}
18261811
if (resolvedValue !== null) {
18271812
return resolvedValue;
18281813
} else if (promise === null) {
@@ -1881,6 +1866,14 @@ describe('Timeline profiler', () => {
18811866
let promise = null;
18821867
let resolvedValue = null;
18831868
function readValue(value) {
1869+
if (React.use) {
1870+
if (promise === null) {
1871+
promise = Promise.resolve(true).then(() => {
1872+
return value;
1873+
});
1874+
}
1875+
return React.use(promise);
1876+
}
18841877
if (resolvedValue !== null) {
18851878
return resolvedValue;
18861879
} else if (promise === null) {
@@ -2192,14 +2185,6 @@ describe('Timeline profiler', () => {
21922185
"timestamp": 10,
21932186
"type": "commit",
21942187
},
2195-
{
2196-
"batchUID": 1,
2197-
"depth": 1,
2198-
"duration": 0,
2199-
"lanes": "0b0000000000000000000000000100000",
2200-
"timestamp": 10,
2201-
"type": "layout-effects",
2202-
},
22032188
{
22042189
"batchUID": 1,
22052190
"depth": 0,
@@ -2234,14 +2219,6 @@ describe('Timeline profiler', () => {
22342219
"timestamp": 10,
22352220
"type": "commit",
22362221
},
2237-
{
2238-
"batchUID": 2,
2239-
"depth": 1,
2240-
"duration": 0,
2241-
"lanes": "0b0000000000000000000000000100000",
2242-
"timestamp": 10,
2243-
"type": "layout-effects",
2244-
},
22452222
{
22462223
"batchUID": 2,
22472224
"depth": 0,
@@ -2292,8 +2269,8 @@ describe('Timeline profiler', () => {
22922269
8 => "InputContinuous",
22932270
16 => "DefaultHydration",
22942271
32 => "Default",
2295-
64 => "TransitionHydration",
2296-
128 => "Transition",
2272+
64 => undefined,
2273+
128 => "TransitionHydration",
22972274
256 => "Transition",
22982275
512 => "Transition",
22992276
1024 => "Transition",
@@ -2349,14 +2326,6 @@ describe('Timeline profiler', () => {
23492326
"timestamp": 10,
23502327
"type": "commit",
23512328
},
2352-
{
2353-
"batchUID": 1,
2354-
"depth": 1,
2355-
"duration": 0,
2356-
"lanes": "0b0000000000000000000000000100000",
2357-
"timestamp": 10,
2358-
"type": "layout-effects",
2359-
},
23602329
{
23612330
"batchUID": 1,
23622331
"depth": 0,
@@ -2389,14 +2358,6 @@ describe('Timeline profiler', () => {
23892358
"timestamp": 10,
23902359
"type": "commit",
23912360
},
2392-
{
2393-
"batchUID": 2,
2394-
"depth": 1,
2395-
"duration": 0,
2396-
"lanes": "0b0000000000000000000000000100000",
2397-
"timestamp": 10,
2398-
"type": "layout-effects",
2399-
},
24002361
{
24012362
"batchUID": 2,
24022363
"depth": 0,

packages/react-devtools-shared/src/__tests__/profilerStore-test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,11 @@ describe('ProfilerStore', () => {
215215
it('should not throw while initializing context values for Fibers within a not-yet-mounted subtree', () => {
216216
const promise = new Promise(resolve => {});
217217
const SuspendingView = () => {
218-
throw promise;
218+
if (React.use) {
219+
React.use(promise);
220+
} else {
221+
throw promise;
222+
}
219223
};
220224

221225
const App = () => {

packages/react-devtools-shared/src/__tests__/profilingCache-test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,14 @@ describe('ProfilingCache', () => {
682682
it('should calculate durations correctly for suspended views', async () => {
683683
let data;
684684
const getData = () => {
685+
if (React.use) {
686+
if (!data) {
687+
data = new Promise(resolve => {
688+
resolve('abc');
689+
});
690+
}
691+
return React.use(data);
692+
}
685693
if (data) {
686694
return data;
687695
} else {

0 commit comments

Comments
 (0)