@samitouri / QOS-React-2 / commits / d86bc1020e

Hardened tests to ensure expectations are flushed

Brian Vaughn committed May 6, 2019 at 13:04 UTC d86bc1020ec6122a0a37685f57ab2c7a88be71d8
2 files changed +27 -3
src/__tests__/profiling-test.js
+23 -3
@@ -50,11 +50,14 @@ describe('profiling', () => {
50 utils.act(() => ReactDOM.render(<Parent count={0} />, container));
51 utils.act(() => store.stopProfiling());
52
53 + let suspenseResolved = false;
54 +
55 function Suspender({ rendererID, rootID }) {
56 const profilingSummary = store.profilingCache.ProfilingSummary.read({
57 rendererID,
58 rootID,
59 });
60 + suspenseResolved = true;
61 expect(profilingSummary).toMatchSnapshot('ProfilingSummary');
62 return null;
63 }
@@ -70,6 +73,8 @@ describe('profiling', () => {
73 )
74 );
75
76 + expect(suspenseResolved).toBe(true);
77 +
78 done();
79 });
80 });
@@ -96,12 +101,15 @@ describe('profiling', () => {
101 utils.act(() => ReactDOM.render(<Parent count={0} />, container));
102 utils.act(() => store.stopProfiling());
103
104 + let suspenseResolved = false;
105 +
106 function Suspender({ commitIndex, rendererID, rootID }) {
107 const commitDetails = store.profilingCache.CommitDetails.read({
108 commitIndex,
109 rendererID,
110 rootID,
111 });
112 + suspenseResolved = true;
113 expect(commitDetails).toMatchSnapshot(
114 `CommitDetails commitIndex: ${commitIndex}`
115 );
@@ -112,7 +120,8 @@ describe('profiling', () => {
120 const rootID = store.roots[0];
121
122 for (let commitIndex = 0; commitIndex <= 3; commitIndex++) {
115 - await utils.actSuspense(() =>
123 + suspenseResolved = false;
124 + await utils.actSuspense(() => {
125 TestRenderer.create(
126 <React.Suspense fallback={null}>
127 <Suspender
@@ -121,8 +130,9 @@ describe('profiling', () => {
130 rootID={rootID}
131 />
132 </React.Suspense>
124 - )
125 - );
133 + );
134 + });
135 + expect(suspenseResolved).toBe(true);
136 }
137
138 done();
@@ -150,12 +160,15 @@ describe('profiling', () => {
160 utils.act(() => ReactDOM.render(<Parent count={3} />, container));
161 utils.act(() => store.stopProfiling());
162
163 + let suspenseResolved = false;
164 +
165 function Suspender({ fiberID, rendererID, rootID }) {
166 const fiberCommits = store.profilingCache.FiberCommits.read({
167 fiberID,
168 rendererID,
169 rootID,
170 });
171 + suspenseResolved = true;
172 expect(fiberCommits).toMatchSnapshot(
173 `FiberCommits: element ${fiberID}`
174 );
@@ -166,6 +179,7 @@ describe('profiling', () => {
179 const rootID = store.roots[0];
180
181 for (let index = 0; index < store.numElements; index++) {
182 + suspenseResolved = false;
183 await utils.actSuspense(() => {
184 const fiberID = store.getElementIDAtIndex(index);
185 if (fiberID == null) {
@@ -181,6 +195,7 @@ describe('profiling', () => {
195 </React.Suspense>
196 );
197 });
198 + expect(suspenseResolved).toBe(true);
199 }
200
201 done();
@@ -219,11 +234,14 @@ describe('profiling', () => {
234 );
235 utils.act(() => store.stopProfiling());
236
237 + let suspenseResolved = false;
238 +
239 function Suspender({ rendererID, rootID }) {
240 const interactions = store.profilingCache.Interactions.read({
241 rendererID,
242 rootID,
243 });
244 + suspenseResolved = true;
245 expect(interactions).toMatchSnapshot('Interactions');
246 return null;
247 }
@@ -239,6 +257,8 @@ describe('profiling', () => {
257 )
258 );
259
260 + expect(suspenseResolved).toBe(true);
261 +
262 done();
263 });
264 });
src/devtools/store.js
+4
@@ -852,6 +852,10 @@ export default class Store extends EventEmitter {
852 weight: 0,
853 });
854
855 + if (this._isProfiling) {
856 + this._profilingSnapshotsByRootID.set(id, new Map());
857 + }
858 +
859 haveRootsChanged = true;
860 } else {
861 parentID = ((operations[i]: any): number);