Skip to content

Commit b08fe8f

Browse files
committed
Fix DevTools regression test actions and assertions
1 parent 47664de commit b08fe8f

File tree

5 files changed

+213
-96
lines changed

5 files changed

+213
-96
lines changed

packages/react-devtools-shared/src/__tests__/__serializers__/storeSerializer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export function test(maybeStore) {
1212
}
1313

1414
// print() is part of Jest's serializer API
15-
export function print(store, serialize, indent) {
16-
return printStore(store);
15+
export function print(store, serialize, indent, includeSuspense = true) {
16+
return printStore(store, false, null, includeSuspense);
1717
}
1818

1919
// Used for Jest snapshot testing.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,7 @@ describe('ProfilingCache', () => {
866866
"hocDisplayNames": null,
867867
"id": 1,
868868
"key": null,
869+
"stack": null,
869870
"type": 11,
870871
},
871872
],
@@ -908,6 +909,7 @@ describe('ProfilingCache', () => {
908909
"hocDisplayNames": null,
909910
"id": 1,
910911
"key": null,
912+
"stack": null,
911913
"type": 11,
912914
},
913915
],

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,17 @@ describe('commit tree', () => {
188188
[root]
189189
▾ <App>
190190
<Suspense>
191+
[suspense-root] rects={null}
192+
<Suspense name="App" rects={null}>
191193
`);
192194
utils.act(() => legacyRender(<App renderChildren={true} />));
193195
expect(store).toMatchInlineSnapshot(`
194196
[root]
195197
▾ <App>
196198
▾ <Suspense>
197199
<LazyInnerComponent>
200+
[suspense-root] rects={null}
201+
<Suspense name="App" rects={null}>
198202
`);
199203
utils.act(() => legacyRender(<App renderChildren={false} />));
200204
expect(store).toMatchInlineSnapshot(`
@@ -272,6 +276,8 @@ describe('commit tree', () => {
272276
[root]
273277
▾ <App>
274278
<Suspense>
279+
[suspense-root] rects={null}
280+
<Suspense name="App" rects={null}>
275281
`);
276282
utils.act(() => legacyRender(<App renderChildren={false} />));
277283
expect(store).toMatchInlineSnapshot(`

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

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,35 @@ describe('Store', () => {
2424
let store;
2525
let withErrorsOrWarningsIgnored;
2626

27+
function readValue(promise) {
28+
if (typeof React.use === 'function') {
29+
return React.use(promise);
30+
}
31+
32+
// Support for React < 19.0
33+
switch (promise.status) {
34+
case 'fulfilled':
35+
return promise.value;
36+
case 'rejected':
37+
throw promise.reason;
38+
case 'pending':
39+
throw promise;
40+
default:
41+
promise.status = 'pending';
42+
promise.then(
43+
value => {
44+
promise.status = 'fulfilled';
45+
promise.value = value;
46+
},
47+
reason => {
48+
promise.status = 'rejected';
49+
promise.reason = reason;
50+
},
51+
);
52+
throw promise;
53+
}
54+
}
55+
2756
beforeAll(() => {
2857
// JSDDOM doesn't implement getClientRects so we're just faking one for testing purposes
2958
Element.prototype.getClientRects = function (this: Element) {
@@ -107,11 +136,7 @@ describe('Store', () => {
107136
let Dynamic = null;
108137
const Owner = () => {
109138
Dynamic = <Child />;
110-
if (React.use) {
111-
React.use(promise);
112-
} else {
113-
throw promise;
114-
}
139+
readValue(promise);
115140
};
116141
const Parent = () => {
117142
return Dynamic;
@@ -462,12 +487,9 @@ describe('Store', () => {
462487
// @reactVersion >= 18.0
463488
it('should display Suspense nodes properly in various states', async () => {
464489
const Loading = () => <div>Loading...</div>;
490+
const never = new Promise(() => {});
465491
const SuspendingComponent = () => {
466-
if (React.use) {
467-
React.use(new Promise(() => {}));
468-
} else {
469-
throw new Promise(() => {});
470-
}
492+
readValue(never);
471493
};
472494
const Component = () => {
473495
return <div>Hello</div>;
@@ -514,12 +536,9 @@ describe('Store', () => {
514536
it('should support nested Suspense nodes', async () => {
515537
const Component = () => null;
516538
const Loading = () => <div>Loading...</div>;
539+
const never = new Promise(() => {});
517540
const Never = () => {
518-
if (React.use) {
519-
React.use(new Promise(() => {}));
520-
} else {
521-
throw new Promise(() => {});
522-
}
541+
readValue(never);
523542
};
524543

525544
const Wrapper = ({
@@ -1019,12 +1038,9 @@ describe('Store', () => {
10191038

10201039
it('should display a partially rendered SuspenseList', async () => {
10211040
const Loading = () => <div>Loading...</div>;
1041+
const never = new Promise(() => {});
10221042
const SuspendingComponent = () => {
1023-
if (React.use) {
1024-
React.use(new Promise(() => {}));
1025-
} else {
1026-
throw new Promise(() => {});
1027-
}
1043+
readValue(never);
10281044
};
10291045
const Component = () => {
10301046
return <div>Hello</div>;
@@ -1379,12 +1395,9 @@ describe('Store', () => {
13791395
// @reactVersion >= 18.0
13801396
it('should display Suspense nodes properly in various states', async () => {
13811397
const Loading = () => <div>Loading...</div>;
1398+
const never = new Promise(() => {});
13821399
const SuspendingComponent = () => {
1383-
if (React.use) {
1384-
React.use(new Promise(() => {}));
1385-
} else {
1386-
throw new Promise(() => {});
1387-
}
1400+
readValue(never);
13881401
};
13891402
const Component = () => {
13901403
return <div>Hello</div>;
@@ -2081,6 +2094,8 @@ describe('Store', () => {
20812094
[root]
20822095
▾ <App>
20832096
<Suspense>
2097+
[suspense-root] rects={null}
2098+
<Suspense name="App" rects={null}>
20842099
`);
20852100

20862101
// Render again to unmount it before it finishes loading
@@ -2826,7 +2841,7 @@ describe('Store', () => {
28262841

28272842
function Component({children, promise}) {
28282843
if (promise) {
2829-
React.use(promise);
2844+
readValue(promise);
28302845
}
28312846
return <div>{children}</div>;
28322847
}
@@ -2901,7 +2916,7 @@ describe('Store', () => {
29012916

29022917
function Component({children, promise}) {
29032918
if (promise) {
2904-
React.use(promise);
2919+
readValue(promise);
29052920
}
29062921
return <div>{children}</div>;
29072922
}

0 commit comments

Comments
 (0)