Hardened tests to ensure expectations are flushed

This commit is contained in:
Brian Vaughn
2019-05-06 13:04:14 -07:00
parent 705cd9b109
commit d86bc1020e
2 changed files with 27 additions and 3 deletions
+23 -3
View File
@@ -50,11 +50,14 @@ describe('profiling', () => {
utils.act(() => ReactDOM.render(<Parent count={0} />, container));
utils.act(() => store.stopProfiling());
let suspenseResolved = false;
function Suspender({ rendererID, rootID }) {
const profilingSummary = store.profilingCache.ProfilingSummary.read({
rendererID,
rootID,
});
suspenseResolved = true;
expect(profilingSummary).toMatchSnapshot('ProfilingSummary');
return null;
}
@@ -70,6 +73,8 @@ describe('profiling', () => {
)
);
expect(suspenseResolved).toBe(true);
done();
});
});
@@ -96,12 +101,15 @@ describe('profiling', () => {
utils.act(() => ReactDOM.render(<Parent count={0} />, container));
utils.act(() => store.stopProfiling());
let suspenseResolved = false;
function Suspender({ commitIndex, rendererID, rootID }) {
const commitDetails = store.profilingCache.CommitDetails.read({
commitIndex,
rendererID,
rootID,
});
suspenseResolved = true;
expect(commitDetails).toMatchSnapshot(
`CommitDetails commitIndex: ${commitIndex}`
);
@@ -112,7 +120,8 @@ describe('profiling', () => {
const rootID = store.roots[0];
for (let commitIndex = 0; commitIndex <= 3; commitIndex++) {
await utils.actSuspense(() =>
suspenseResolved = false;
await utils.actSuspense(() => {
TestRenderer.create(
<React.Suspense fallback={null}>
<Suspender
@@ -121,8 +130,9 @@ describe('profiling', () => {
rootID={rootID}
/>
</React.Suspense>
)
);
);
});
expect(suspenseResolved).toBe(true);
}
done();
@@ -150,12 +160,15 @@ describe('profiling', () => {
utils.act(() => ReactDOM.render(<Parent count={3} />, container));
utils.act(() => store.stopProfiling());
let suspenseResolved = false;
function Suspender({ fiberID, rendererID, rootID }) {
const fiberCommits = store.profilingCache.FiberCommits.read({
fiberID,
rendererID,
rootID,
});
suspenseResolved = true;
expect(fiberCommits).toMatchSnapshot(
`FiberCommits: element ${fiberID}`
);
@@ -166,6 +179,7 @@ describe('profiling', () => {
const rootID = store.roots[0];
for (let index = 0; index < store.numElements; index++) {
suspenseResolved = false;
await utils.actSuspense(() => {
const fiberID = store.getElementIDAtIndex(index);
if (fiberID == null) {
@@ -181,6 +195,7 @@ describe('profiling', () => {
</React.Suspense>
);
});
expect(suspenseResolved).toBe(true);
}
done();
@@ -219,11 +234,14 @@ describe('profiling', () => {
);
utils.act(() => store.stopProfiling());
let suspenseResolved = false;
function Suspender({ rendererID, rootID }) {
const interactions = store.profilingCache.Interactions.read({
rendererID,
rootID,
});
suspenseResolved = true;
expect(interactions).toMatchSnapshot('Interactions');
return null;
}
@@ -239,6 +257,8 @@ describe('profiling', () => {
)
);
expect(suspenseResolved).toBe(true);
done();
});
});
+4
View File
@@ -852,6 +852,10 @@ export default class Store extends EventEmitter {
weight: 0,
});
if (this._isProfiling) {
this._profilingSnapshotsByRootID.set(id, new Map());
}
haveRootsChanged = true;
} else {
parentID = ((operations[i]: any): number);