mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Hardened tests to ensure expectations are flushed
This commit is contained in:
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user