mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Added commit tree builder test
This commit is contained in:
@@ -0,0 +1,162 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`commit tree should be able to rebuild the store tree for each commit: 0: CommitTree 1`] = `
|
||||
Object {
|
||||
"nodes": Map {
|
||||
1 => Object {
|
||||
"children": Array [
|
||||
2,
|
||||
],
|
||||
"displayName": null,
|
||||
"id": 1,
|
||||
"key": null,
|
||||
"parentID": 0,
|
||||
"treeBaseDuration": 12,
|
||||
},
|
||||
2 => Object {
|
||||
"children": Array [
|
||||
3,
|
||||
],
|
||||
"displayName": "Parent",
|
||||
"id": 2,
|
||||
"key": null,
|
||||
"parentID": 1,
|
||||
"treeBaseDuration": 12,
|
||||
},
|
||||
3 => Object {
|
||||
"children": Array [],
|
||||
"displayName": "Memo(Child)",
|
||||
"id": 3,
|
||||
"key": "0",
|
||||
"parentID": 2,
|
||||
"treeBaseDuration": 2,
|
||||
},
|
||||
},
|
||||
"rootID": 1,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`commit tree should be able to rebuild the store tree for each commit: 1: CommitTree 1`] = `
|
||||
Object {
|
||||
"nodes": Map {
|
||||
1 => Object {
|
||||
"children": Array [
|
||||
2,
|
||||
],
|
||||
"displayName": null,
|
||||
"id": 1,
|
||||
"key": null,
|
||||
"parentID": 0,
|
||||
"treeBaseDuration": 16,
|
||||
},
|
||||
2 => Object {
|
||||
"children": Array [
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
],
|
||||
"displayName": "Parent",
|
||||
"id": 2,
|
||||
"key": null,
|
||||
"parentID": 1,
|
||||
"treeBaseDuration": 16,
|
||||
},
|
||||
3 => Object {
|
||||
"children": Array [],
|
||||
"displayName": "Memo(Child)",
|
||||
"id": 3,
|
||||
"key": "0",
|
||||
"parentID": 2,
|
||||
"treeBaseDuration": 2,
|
||||
},
|
||||
4 => Object {
|
||||
"children": Array [],
|
||||
"displayName": "Memo(Child)",
|
||||
"id": 4,
|
||||
"key": "1",
|
||||
"parentID": 2,
|
||||
"treeBaseDuration": 2,
|
||||
},
|
||||
5 => Object {
|
||||
"children": Array [],
|
||||
"displayName": "Memo(Child)",
|
||||
"id": 5,
|
||||
"key": "2",
|
||||
"parentID": 2,
|
||||
"treeBaseDuration": 2,
|
||||
},
|
||||
},
|
||||
"rootID": 1,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`commit tree should be able to rebuild the store tree for each commit: 2: CommitTree 1`] = `
|
||||
Object {
|
||||
"nodes": Map {
|
||||
1 => Object {
|
||||
"children": Array [
|
||||
2,
|
||||
],
|
||||
"displayName": null,
|
||||
"id": 1,
|
||||
"key": null,
|
||||
"parentID": 0,
|
||||
"treeBaseDuration": 14,
|
||||
},
|
||||
2 => Object {
|
||||
"children": Array [
|
||||
3,
|
||||
4,
|
||||
],
|
||||
"displayName": "Parent",
|
||||
"id": 2,
|
||||
"key": null,
|
||||
"parentID": 1,
|
||||
"treeBaseDuration": 14,
|
||||
},
|
||||
3 => Object {
|
||||
"children": Array [],
|
||||
"displayName": "Memo(Child)",
|
||||
"id": 3,
|
||||
"key": "0",
|
||||
"parentID": 2,
|
||||
"treeBaseDuration": 2,
|
||||
},
|
||||
4 => Object {
|
||||
"children": Array [],
|
||||
"displayName": "Memo(Child)",
|
||||
"id": 4,
|
||||
"key": "1",
|
||||
"parentID": 2,
|
||||
"treeBaseDuration": 2,
|
||||
},
|
||||
},
|
||||
"rootID": 1,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`commit tree should be able to rebuild the store tree for each commit: 3: CommitTree 1`] = `
|
||||
Object {
|
||||
"nodes": Map {
|
||||
1 => Object {
|
||||
"children": Array [
|
||||
2,
|
||||
],
|
||||
"displayName": null,
|
||||
"id": 1,
|
||||
"key": null,
|
||||
"parentID": 0,
|
||||
"treeBaseDuration": 10,
|
||||
},
|
||||
2 => Object {
|
||||
"children": Array [],
|
||||
"displayName": "Parent",
|
||||
"id": 2,
|
||||
"key": null,
|
||||
"parentID": 1,
|
||||
"treeBaseDuration": 10,
|
||||
},
|
||||
},
|
||||
"rootID": 1,
|
||||
}
|
||||
`;
|
||||
@@ -0,0 +1,91 @@
|
||||
// @flow
|
||||
|
||||
import typeof TestRendererType from 'react-test-renderer';
|
||||
import type Store from 'src/devtools/store';
|
||||
|
||||
describe('commit tree', () => {
|
||||
let React;
|
||||
let ReactDOM;
|
||||
let Scheduler;
|
||||
let SchedulerTracing;
|
||||
let TestRenderer: TestRendererType;
|
||||
let store: Store;
|
||||
let utils;
|
||||
|
||||
beforeEach(() => {
|
||||
utils = require('./utils');
|
||||
utils.beforeEachProfiling();
|
||||
|
||||
store = global.store;
|
||||
store.collapseNodesByDefault = false;
|
||||
|
||||
React = require('react');
|
||||
ReactDOM = require('react-dom');
|
||||
Scheduler = require('scheduler');
|
||||
SchedulerTracing = require('scheduler/tracing');
|
||||
TestRenderer = utils.requireTestRenderer();
|
||||
});
|
||||
|
||||
it('should be able to rebuild the store tree for each commit', async done => {
|
||||
const Parent = ({ count }) => {
|
||||
Scheduler.advanceTime(10);
|
||||
return new Array(count)
|
||||
.fill(true)
|
||||
.map((_, index) => <Child key={index} />);
|
||||
};
|
||||
const Child = React.memo(function Child() {
|
||||
Scheduler.advanceTime(2);
|
||||
return null;
|
||||
});
|
||||
|
||||
const container = document.createElement('div');
|
||||
|
||||
utils.act(() => store.startProfiling());
|
||||
utils.act(() => ReactDOM.render(<Parent count={1} />, container));
|
||||
utils.act(() => ReactDOM.render(<Parent count={3} />, container));
|
||||
utils.act(() => ReactDOM.render(<Parent count={2} />, container));
|
||||
utils.act(() => ReactDOM.render(<Parent count={0} />, container));
|
||||
utils.act(() => store.stopProfiling());
|
||||
|
||||
let suspenseResolved = false;
|
||||
|
||||
function Suspender({ commitIndex, rendererID, rootID }) {
|
||||
const profilingSummary = store.profilingCache.ProfilingSummary.read({
|
||||
rendererID,
|
||||
rootID,
|
||||
});
|
||||
suspenseResolved = true;
|
||||
const commitTree = store.profilingCache.getCommitTree({
|
||||
commitIndex,
|
||||
profilingSummary,
|
||||
});
|
||||
expect(commitTree).toMatchSnapshot(`${commitIndex}: CommitTree`);
|
||||
return null;
|
||||
}
|
||||
|
||||
const rendererID = utils.getRendererID();
|
||||
const rootID = store.roots[0];
|
||||
|
||||
for (let commitIndex = 0; commitIndex < 4; commitIndex++) {
|
||||
suspenseResolved = false;
|
||||
|
||||
await utils.actSuspense(
|
||||
() =>
|
||||
TestRenderer.create(
|
||||
<React.Suspense fallback={null}>
|
||||
<Suspender
|
||||
commitIndex={commitIndex}
|
||||
rendererID={rendererID}
|
||||
rootID={rootID}
|
||||
/>
|
||||
</React.Suspense>
|
||||
),
|
||||
3
|
||||
);
|
||||
|
||||
expect(suspenseResolved).toBe(true);
|
||||
}
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user