diff --git a/src/__tests__/__snapshots__/profilingCommitTreeBuilder-test.js.snap b/src/__tests__/__snapshots__/profilingCommitTreeBuilder-test.js.snap new file mode 100644 index 0000000000..b483cd5efc --- /dev/null +++ b/src/__tests__/__snapshots__/profilingCommitTreeBuilder-test.js.snap @@ -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, +} +`; diff --git a/src/__tests__/profilingCommitTreeBuilder-test.js b/src/__tests__/profilingCommitTreeBuilder-test.js new file mode 100644 index 0000000000..bf7b630646 --- /dev/null +++ b/src/__tests__/profilingCommitTreeBuilder-test.js @@ -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) => ); + }; + const Child = React.memo(function Child() { + Scheduler.advanceTime(2); + return null; + }); + + const container = document.createElement('div'); + + utils.act(() => store.startProfiling()); + utils.act(() => ReactDOM.render(, container)); + utils.act(() => ReactDOM.render(, container)); + utils.act(() => ReactDOM.render(, container)); + utils.act(() => ReactDOM.render(, 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( + + + + ), + 3 + ); + + expect(suspenseResolved).toBe(true); + } + + done(); + }); +});