From d09299bf85198305e088ecd353f8b3b21c3d710a Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Wed, 22 May 2019 08:05:34 -0700 Subject: [PATCH] Cleaned up some tests --- .../__snapshots__/profilingCache-test.js.snap | 1518 ++++++++++------- src/__tests__/profilingCache-test.js | 192 +-- src/__tests__/profilingCharts-test.js | 60 +- .../profilingCommitTreeBuilder-test.js | 20 +- src/__tests__/utils.js | 8 +- 5 files changed, 1066 insertions(+), 732 deletions(-) diff --git a/src/__tests__/__snapshots__/profilingCache-test.js.snap b/src/__tests__/__snapshots__/profilingCache-test.js.snap index a6f2d1c4d6..077ad260fb 100644 --- a/src/__tests__/__snapshots__/profilingCache-test.js.snap +++ b/src/__tests__/__snapshots__/profilingCache-test.js.snap @@ -149,182 +149,181 @@ Object { `; exports[`ProfilingCache should collect data for each commit: imported data 1`] = ` -"{ - \\"version\\": 5, - \\"dataForRoots\\": [ - { - \\"commitData\\": [ - { - \\"duration\\": 12, - \\"fiberActualDurations\\": [ - [ +Object { + "dataForRoots": Array [ + Object { + "commitData": Array [ + Object { + "duration": 12, + "fiberActualDurations": Array [ + Array [ 1, - 12 + 12, ], - [ + Array [ 2, - 12 + 12, ], - [ + Array [ 3, - 0 + 0, ], - [ + Array [ 4, - 1 + 1, ], - [ + Array [ 5, - 1 - ] - ], - \\"fiberSelfDurations\\": [ - [ 1, - 0 ], - [ + ], + "fiberSelfDurations": Array [ + Array [ + 1, + 0, + ], + Array [ 2, - 10 + 10, ], - [ + Array [ 3, - 0 + 0, ], - [ + Array [ 4, - 1 + 1, ], - [ + Array [ 5, - 1 - ] - ], - \\"interactionIDs\\": [], - \\"priorityLevel\\": \\"Immediate\\", - \\"screenshot\\": null, - \\"timestamp\\": 12 - }, - { - \\"duration\\": 13, - \\"fiberActualDurations\\": [ - [ - 3, - 0 + 1, ], - [ + ], + "interactionIDs": Array [], + "priorityLevel": "Immediate", + "screenshot": null, + "timestamp": 12, + }, + Object { + "duration": 13, + "fiberActualDurations": Array [ + Array [ + 3, + 0, + ], + Array [ 4, - 1 - ], - [ - 6, - 2 - ], - [ - 2, - 13 - ], - [ 1, - 13 - ] - ], - \\"fiberSelfDurations\\": [ - [ - 3, - 0 ], - [ + Array [ + 6, + 2, + ], + Array [ + 2, + 13, + ], + Array [ + 1, + 13, + ], + ], + "fiberSelfDurations": Array [ + Array [ + 3, + 0, + ], + Array [ 4, - 1 + 1, ], - [ + Array [ 6, - 2 - ], - [ 2, - 10 ], - [ + Array [ + 2, + 10, + ], + Array [ 1, - 0 - ] + 0, + ], ], - \\"interactionIDs\\": [], - \\"priorityLevel\\": \\"Immediate\\", - \\"screenshot\\": null, - \\"timestamp\\": 25 + "interactionIDs": Array [], + "priorityLevel": "Immediate", + "screenshot": null, + "timestamp": 25, }, - { - \\"duration\\": 10, - \\"fiberActualDurations\\": [ - [ + Object { + "duration": 10, + "fiberActualDurations": Array [ + Array [ 3, - 0 + 0, ], - [ + Array [ 2, - 10 + 10, ], - [ + Array [ 1, - 10 - ] + 10, + ], ], - \\"fiberSelfDurations\\": [ - [ + "fiberSelfDurations": Array [ + Array [ 3, - 0 + 0, ], - [ + Array [ 2, - 10 + 10, ], - [ + Array [ 1, - 0 - ] + 0, + ], ], - \\"interactionIDs\\": [], - \\"priorityLevel\\": \\"Immediate\\", - \\"screenshot\\": null, - \\"timestamp\\": 35 + "interactionIDs": Array [], + "priorityLevel": "Immediate", + "screenshot": null, + "timestamp": 35, }, - { - \\"duration\\": 10, - \\"fiberActualDurations\\": [ - [ + Object { + "duration": 10, + "fiberActualDurations": Array [ + Array [ 2, - 10 + 10, ], - [ + Array [ 1, - 10 - ] + 10, + ], ], - \\"fiberSelfDurations\\": [ - [ + "fiberSelfDurations": Array [ + Array [ 2, - 10 + 10, ], - [ + Array [ 1, - 0 - ] + 0, + ], ], - \\"interactionIDs\\": [], - \\"priorityLevel\\": \\"Immediate\\", - \\"screenshot\\": null, - \\"timestamp\\": 45 - } + "interactionIDs": Array [], + "priorityLevel": "Immediate", + "screenshot": null, + "timestamp": 45, + }, ], - \\"displayName\\": \\"Parent\\", - \\"initialTreeBaseDurations\\": [], - \\"interactionCommits\\": [], - \\"interactions\\": [], - \\"operations\\": [ - [ + "displayName": "Parent", + "initialTreeBaseDurations": Array [], + "interactionCommits": Array [], + "interactions": Array [], + "operations": Array [ + Array [ 1, 1, 17, @@ -392,9 +391,9 @@ exports[`ProfilingCache should collect data for each commit: imported data 1`] = 0, 4, 5, - 1000 + 1000, ], - [ + Array [ 1, 1, 8, @@ -428,9 +427,9 @@ exports[`ProfilingCache should collect data for each commit: imported data 1`] = 5, 4, 1, - 14000 + 14000, ], - [ + Array [ 1, 1, 0, @@ -448,22 +447,23 @@ exports[`ProfilingCache should collect data for each commit: imported data 1`] = 5, 4, 1, - 11000 + 11000, ], - [ + Array [ 1, 1, 0, 2, 1, - 3 - ] + 3, + ], ], - \\"rootID\\": 1, - \\"snapshots\\": [] - } - ] -}" + "rootID": 1, + "snapshots": Array [], + }, + ], + "version": 5, +} `; exports[`ProfilingCache should collect data for each rendered fiber: FiberCommits: element 2 1`] = ` @@ -502,155 +502,154 @@ Array [ `; exports[`ProfilingCache should collect data for each rendered fiber: imported data 1`] = ` -"{ - \\"version\\": 5, - \\"dataForRoots\\": [ - { - \\"commitData\\": [ - { - \\"duration\\": 11, - \\"fiberActualDurations\\": [ - [ +Object { + "dataForRoots": Array [ + Object { + "commitData": Array [ + Object { + "duration": 11, + "fiberActualDurations": Array [ + Array [ 1, - 11 + 11, ], - [ + Array [ 2, - 11 + 11, ], - [ + Array [ 3, - 0 + 0, ], - [ + Array [ 4, - 1 - ] - ], - \\"fiberSelfDurations\\": [ - [ 1, - 0 ], - [ + ], + "fiberSelfDurations": Array [ + Array [ + 1, + 0, + ], + Array [ 2, - 10 + 10, ], - [ + Array [ 3, - 0 + 0, ], - [ + Array [ 4, - 1 - ] + 1, + ], ], - \\"interactionIDs\\": [], - \\"priorityLevel\\": \\"Immediate\\", - \\"screenshot\\": null, - \\"timestamp\\": 11 + "interactionIDs": Array [], + "priorityLevel": "Immediate", + "screenshot": null, + "timestamp": 11, }, - { - \\"duration\\": 11, - \\"fiberActualDurations\\": [ - [ + Object { + "duration": 11, + "fiberActualDurations": Array [ + Array [ 3, - 0 + 0, ], - [ + Array [ 5, - 1 - ], - [ - 2, - 11 - ], - [ 1, - 11 - ] + ], + Array [ + 2, + 11, + ], + Array [ + 1, + 11, + ], ], - \\"fiberSelfDurations\\": [ - [ + "fiberSelfDurations": Array [ + Array [ 3, - 0 + 0, ], - [ + Array [ 5, - 1 - ], - [ - 2, - 10 - ], - [ 1, - 0 - ] + ], + Array [ + 2, + 10, + ], + Array [ + 1, + 0, + ], ], - \\"interactionIDs\\": [], - \\"priorityLevel\\": \\"Immediate\\", - \\"screenshot\\": null, - \\"timestamp\\": 22 + "interactionIDs": Array [], + "priorityLevel": "Immediate", + "screenshot": null, + "timestamp": 22, }, - { - \\"duration\\": 13, - \\"fiberActualDurations\\": [ - [ + Object { + "duration": 13, + "fiberActualDurations": Array [ + Array [ 3, - 0 + 0, ], - [ + Array [ 5, - 1 - ], - [ - 6, - 2 - ], - [ - 2, - 13 - ], - [ 1, - 13 - ] + ], + Array [ + 6, + 2, + ], + Array [ + 2, + 13, + ], + Array [ + 1, + 13, + ], ], - \\"fiberSelfDurations\\": [ - [ + "fiberSelfDurations": Array [ + Array [ 3, - 0 + 0, ], - [ + Array [ 5, - 1 - ], - [ - 6, - 2 - ], - [ - 2, - 10 - ], - [ 1, - 0 - ] + ], + Array [ + 6, + 2, + ], + Array [ + 2, + 10, + ], + Array [ + 1, + 0, + ], ], - \\"interactionIDs\\": [], - \\"priorityLevel\\": \\"Immediate\\", - \\"screenshot\\": null, - \\"timestamp\\": 35 - } + "interactionIDs": Array [], + "priorityLevel": "Immediate", + "screenshot": null, + "timestamp": 35, + }, ], - \\"displayName\\": \\"Parent\\", - \\"initialTreeBaseDurations\\": [], - \\"interactionCommits\\": [], - \\"interactions\\": [], - \\"operations\\": [ - [ + "displayName": "Parent", + "initialTreeBaseDurations": Array [], + "interactionCommits": Array [], + "interactions": Array [], + "operations": Array [ + Array [ 1, 1, 15, @@ -706,9 +705,9 @@ exports[`ProfilingCache should collect data for each rendered fiber: imported da 0, 4, 4, - 1000 + 1000, ], - [ + Array [ 1, 1, 8, @@ -741,9 +740,9 @@ exports[`ProfilingCache should collect data for each rendered fiber: imported da 4, 4, 1, - 12000 + 12000, ], - [ + Array [ 1, 1, 8, @@ -777,17 +776,18 @@ exports[`ProfilingCache should collect data for each rendered fiber: imported da 4, 4, 1, - 14000 - ] + 14000, + ], ], - \\"rootID\\": 1, - \\"snapshots\\": [] - } - ] -}" + "rootID": 1, + "snapshots": Array [], + }, + ], + "version": 5, +} `; -exports[`ProfilingCache should collect data for each root: ProfilingSummary 1`] = ` +exports[`ProfilingCache should collect data for each root (including ones added or mounted after profiling started): Data for root Parent 1`] = ` Object { "commitData": Array [ Object { @@ -795,14 +795,14 @@ Object { "fiberActualDurations": Map { 3 => 0, 4 => 1, - 6 => 2, + 10 => 2, 2 => 13, 1 => 13, }, "fiberSelfDurations": Map { 3 => 0, 4 => 1, - 6 => 2, + 10 => 2, 2 => 10, 1 => 0, }, @@ -826,7 +826,7 @@ Object { "interactionIDs": Array [], "priorityLevel": "Immediate", "screenshot": null, - "timestamp": 23, + "timestamp": 34, }, Object { "duration": 10, @@ -841,7 +841,7 @@ Object { "interactionIDs": Array [], "priorityLevel": "Immediate", "screenshot": null, - "timestamp": 33, + "timestamp": 44, }, ], "displayName": "Parent", @@ -868,14 +868,14 @@ Object { 1, 50, 1, - 6, + 10, 5, 2, 2, 1, 2, 4, - 6, + 10, 2000, 4, 2, @@ -885,7 +885,7 @@ Object { 4, 3, 4, - 6, + 10, 5, 4, 1, @@ -897,7 +897,7 @@ Object { 0, 2, 2, - 6, + 10, 4, 4, 2, @@ -967,153 +967,318 @@ Object { } `; -exports[`ProfilingCache should collect data for each root: imported data 1`] = ` -"{ - \\"version\\": 5, - \\"dataForRoots\\": [ - { - \\"commitData\\": [ - { - \\"duration\\": 13, - \\"fiberActualDurations\\": [ - [ - 3, - 0 - ], - [ - 4, - 1 - ], - [ - 6, - 2 - ], - [ - 2, - 13 - ], - [ - 1, - 13 - ] - ], - \\"fiberSelfDurations\\": [ - [ - 3, - 0 - ], - [ - 4, - 1 - ], - [ - 6, - 2 - ], - [ - 2, - 10 - ], - [ - 1, - 0 - ] - ], - \\"interactionIDs\\": [], - \\"priorityLevel\\": \\"Immediate\\", - \\"screenshot\\": null, - \\"timestamp\\": 13 - }, - { - \\"duration\\": 10, - \\"fiberActualDurations\\": [ - [ - 3, - 0 - ], - [ - 2, - 10 - ], - [ - 1, - 10 - ] - ], - \\"fiberSelfDurations\\": [ - [ - 3, - 0 - ], - [ - 2, - 10 - ], - [ - 1, - 0 - ] - ], - \\"interactionIDs\\": [], - \\"priorityLevel\\": \\"Immediate\\", - \\"screenshot\\": null, - \\"timestamp\\": 23 - }, - { - \\"duration\\": 10, - \\"fiberActualDurations\\": [ - [ - 2, - 10 - ], - [ - 1, - 10 - ] - ], - \\"fiberSelfDurations\\": [ - [ - 2, - 10 - ], - [ - 1, - 0 - ] - ], - \\"interactionIDs\\": [], - \\"priorityLevel\\": \\"Immediate\\", - \\"screenshot\\": null, - \\"timestamp\\": 33 - } +exports[`ProfilingCache should collect data for each root (including ones added or mounted after profiling started): Data for root Parent 2`] = ` +Object { + "commitData": Array [ + Object { + "duration": 11, + "fiberActualDurations": Map { + 11 => 11, + 12 => 11, + 13 => 0, + 14 => 1, + }, + "fiberSelfDurations": Map { + 11 => 0, + 12 => 10, + 13 => 0, + 14 => 1, + }, + "interactionIDs": Array [], + "priorityLevel": "Immediate", + "screenshot": null, + "timestamp": 24, + }, + ], + "displayName": "Parent", + "initialTreeBaseDurations": Map {}, + "interactionCommits": Map {}, + "interactions": Map {}, + "operations": Array [ + Uint32Array [ + 1, + 11, + 15, + 6, + 80, + 97, + 114, + 101, + 110, + 116, + 5, + 67, + 104, + 105, + 108, + 100, + 1, + 48, + 1, + 11, + 11, + 1, + 1, + 4, + 11, + 11000, + 1, + 12, + 5, + 11, + 0, + 1, + 0, + 4, + 12, + 11000, + 1, + 13, + 5, + 12, + 12, + 2, + 3, + 4, + 13, + 0, + 1, + 14, + 8, + 12, + 12, + 2, + 0, + 4, + 14, + 1000, + ], + ], + "rootID": 11, + "snapshots": Map {}, +} +`; + +exports[`ProfilingCache should collect data for each root (including ones added or mounted after profiling started): Data for root Parent 3`] = ` +Object { + "commitData": Array [ + Object { + "duration": 0, + "fiberActualDurations": Map {}, + "fiberSelfDurations": Map {}, + "interactionIDs": Array [], + "priorityLevel": "Immediate", + "screenshot": null, + "timestamp": 34, + }, + ], + "displayName": "Parent", + "initialTreeBaseDurations": Map { + 6 => 11, + 7 => 11, + 8 => 0, + 9 => 1, + }, + "interactionCommits": Map {}, + "interactions": Map {}, + "operations": Array [ + Uint32Array [ + 1, + 6, + 0, + 2, + 4, + 9, + 8, + 7, + 6, + ], + ], + "rootID": 6, + "snapshots": Map { + 6 => Object { + "children": Array [ + 7, ], - \\"displayName\\": \\"Parent\\", - \\"initialTreeBaseDurations\\": [ - [ + "displayName": null, + "id": 6, + "key": null, + "type": 11, + }, + 7 => Object { + "children": Array [ + 8, + 9, + ], + "displayName": "Parent", + "id": 7, + "key": null, + "type": 5, + }, + 8 => Object { + "children": Array [], + "displayName": "Child", + "id": 8, + "key": "0", + "type": 5, + }, + 9 => Object { + "children": Array [], + "displayName": "Child", + "id": 9, + "key": null, + "type": 8, + }, + }, +} +`; + +exports[`ProfilingCache should collect data for each root (including ones added or mounted after profiling started): imported data 1`] = ` +Object { + "dataForRoots": Array [ + Object { + "commitData": Array [ + Object { + "duration": 13, + "fiberActualDurations": Array [ + Array [ + 3, + 0, + ], + Array [ + 4, + 1, + ], + Array [ + 10, + 2, + ], + Array [ + 2, + 13, + ], + Array [ + 1, + 13, + ], + ], + "fiberSelfDurations": Array [ + Array [ + 3, + 0, + ], + Array [ + 4, + 1, + ], + Array [ + 10, + 2, + ], + Array [ + 2, + 10, + ], + Array [ + 1, + 0, + ], + ], + "interactionIDs": Array [], + "priorityLevel": "Immediate", + "screenshot": null, + "timestamp": 13, + }, + Object { + "duration": 10, + "fiberActualDurations": Array [ + Array [ + 3, + 0, + ], + Array [ + 2, + 10, + ], + Array [ + 1, + 10, + ], + ], + "fiberSelfDurations": Array [ + Array [ + 3, + 0, + ], + Array [ + 2, + 10, + ], + Array [ + 1, + 0, + ], + ], + "interactionIDs": Array [], + "priorityLevel": "Immediate", + "screenshot": null, + "timestamp": 34, + }, + Object { + "duration": 10, + "fiberActualDurations": Array [ + Array [ + 2, + 10, + ], + Array [ + 1, + 10, + ], + ], + "fiberSelfDurations": Array [ + Array [ + 2, + 10, + ], + Array [ + 1, + 0, + ], + ], + "interactionIDs": Array [], + "priorityLevel": "Immediate", + "screenshot": null, + "timestamp": 44, + }, + ], + "displayName": "Parent", + "initialTreeBaseDurations": Array [ + Array [ 1, - 12 + 12, ], - [ + Array [ 2, - 12 + 12, ], - [ + Array [ 3, - 0 + 0, ], - [ + Array [ 4, - 1 + 1, ], - [ + Array [ 5, - 1 - ] + 1, + ], ], - \\"interactionCommits\\": [], - \\"interactions\\": [], - \\"operations\\": [ - [ + "interactionCommits": Array [], + "interactions": Array [], + "operations": Array [ + Array [ 1, 1, 8, @@ -1126,14 +1291,14 @@ exports[`ProfilingCache should collect data for each root: imported data 1`] = ` 1, 50, 1, - 6, + 10, 5, 2, 2, 1, 2, 4, - 6, + 10, 2000, 4, 2, @@ -1143,19 +1308,19 @@ exports[`ProfilingCache should collect data for each root: imported data 1`] = ` 4, 3, 4, - 6, + 10, 5, 4, 1, - 14000 + 14000, ], - [ + Array [ 1, 1, 0, 2, 2, - 6, + 10, 4, 4, 2, @@ -1167,79 +1332,288 @@ exports[`ProfilingCache should collect data for each root: imported data 1`] = ` 5, 4, 1, - 11000 + 11000, ], - [ + Array [ 1, 1, 0, 2, 1, - 3 - ] - ], - \\"rootID\\": 1, - \\"snapshots\\": [ - [ - 1, - { - \\"id\\": 1, - \\"children\\": [ - 2 - ], - \\"displayName\\": null, - \\"key\\": null, - \\"type\\": 11 - } + 3, ], - [ + ], + "rootID": 1, + "snapshots": Array [ + Array [ + 1, + Object { + "children": Array [ + 2, + ], + "displayName": null, + "id": 1, + "key": null, + "type": 11, + }, + ], + Array [ 2, - { - \\"id\\": 2, - \\"children\\": [ + Object { + "children": Array [ 3, 4, - 5 + 5, ], - \\"displayName\\": \\"Parent\\", - \\"key\\": null, - \\"type\\": 5 - } + "displayName": "Parent", + "id": 2, + "key": null, + "type": 5, + }, ], - [ + Array [ 3, - { - \\"id\\": 3, - \\"children\\": [], - \\"displayName\\": \\"Child\\", - \\"key\\": \\"0\\", - \\"type\\": 5 - } + Object { + "children": Array [], + "displayName": "Child", + "id": 3, + "key": "0", + "type": 5, + }, ], - [ + Array [ 4, - { - \\"id\\": 4, - \\"children\\": [], - \\"displayName\\": \\"Child\\", - \\"key\\": \\"1\\", - \\"type\\": 5 - } + Object { + "children": Array [], + "displayName": "Child", + "id": 4, + "key": "1", + "type": 5, + }, ], - [ + Array [ 5, - { - \\"id\\": 5, - \\"children\\": [], - \\"displayName\\": \\"Child\\", - \\"key\\": null, - \\"type\\": 8 - } - ] - ] - } - ] -}" + Object { + "children": Array [], + "displayName": "Child", + "id": 5, + "key": null, + "type": 8, + }, + ], + ], + }, + Object { + "commitData": Array [ + Object { + "duration": 11, + "fiberActualDurations": Array [ + Array [ + 11, + 11, + ], + Array [ + 12, + 11, + ], + Array [ + 13, + 0, + ], + Array [ + 14, + 1, + ], + ], + "fiberSelfDurations": Array [ + Array [ + 11, + 0, + ], + Array [ + 12, + 10, + ], + Array [ + 13, + 0, + ], + Array [ + 14, + 1, + ], + ], + "interactionIDs": Array [], + "priorityLevel": "Immediate", + "screenshot": null, + "timestamp": 24, + }, + ], + "displayName": "Parent", + "initialTreeBaseDurations": Array [], + "interactionCommits": Array [], + "interactions": Array [], + "operations": Array [ + Array [ + 1, + 11, + 15, + 6, + 80, + 97, + 114, + 101, + 110, + 116, + 5, + 67, + 104, + 105, + 108, + 100, + 1, + 48, + 1, + 11, + 11, + 1, + 1, + 4, + 11, + 11000, + 1, + 12, + 5, + 11, + 0, + 1, + 0, + 4, + 12, + 11000, + 1, + 13, + 5, + 12, + 12, + 2, + 3, + 4, + 13, + 0, + 1, + 14, + 8, + 12, + 12, + 2, + 0, + 4, + 14, + 1000, + ], + ], + "rootID": 11, + "snapshots": Array [], + }, + Object { + "commitData": Array [ + Object { + "duration": 0, + "fiberActualDurations": Array [], + "fiberSelfDurations": Array [], + "interactionIDs": Array [], + "priorityLevel": "Immediate", + "screenshot": null, + "timestamp": 34, + }, + ], + "displayName": "Parent", + "initialTreeBaseDurations": Array [ + Array [ + 6, + 11, + ], + Array [ + 7, + 11, + ], + Array [ + 8, + 0, + ], + Array [ + 9, + 1, + ], + ], + "interactionCommits": Array [], + "interactions": Array [], + "operations": Array [ + Array [ + 1, + 6, + 0, + 2, + 4, + 9, + 8, + 7, + 6, + ], + ], + "rootID": 6, + "snapshots": Array [ + Array [ + 6, + Object { + "children": Array [ + 7, + ], + "displayName": null, + "id": 6, + "key": null, + "type": 11, + }, + ], + Array [ + 7, + Object { + "children": Array [ + 8, + 9, + ], + "displayName": "Parent", + "id": 7, + "key": null, + "type": 5, + }, + ], + Array [ + 8, + Object { + "children": Array [], + "displayName": "Child", + "id": 8, + "key": "0", + "type": 5, + }, + ], + Array [ + 9, + Object { + "children": Array [], + "displayName": "Child", + "id": 9, + "key": null, + "type": 8, + }, + ], + ], + }, + ], + "version": 5, +} `; exports[`ProfilingCache should report every traced interaction: Interactions 1`] = ` @@ -1260,140 +1634,139 @@ Array [ `; exports[`ProfilingCache should report every traced interaction: imported data 1`] = ` -"{ - \\"version\\": 5, - \\"dataForRoots\\": [ - { - \\"commitData\\": [ - { - \\"duration\\": 11, - \\"fiberActualDurations\\": [ - [ +Object { + "dataForRoots": Array [ + Object { + "commitData": Array [ + Object { + "duration": 11, + "fiberActualDurations": Array [ + Array [ 1, - 11 + 11, ], - [ + Array [ 2, - 11 + 11, ], - [ + Array [ 3, - 0 + 0, ], - [ + Array [ 4, - 1 - ] - ], - \\"fiberSelfDurations\\": [ - [ 1, - 0 ], - [ + ], + "fiberSelfDurations": Array [ + Array [ + 1, + 0, + ], + Array [ 2, - 10 + 10, ], - [ + Array [ 3, - 0 + 0, ], - [ + Array [ 4, - 1 - ] + 1, + ], ], - \\"interactionIDs\\": [ - 0 + "interactionIDs": Array [ + 0, ], - \\"priorityLevel\\": \\"Immediate\\", - \\"screenshot\\": null, - \\"timestamp\\": 11 + "priorityLevel": "Immediate", + "screenshot": null, + "timestamp": 11, }, - { - \\"duration\\": 11, - \\"fiberActualDurations\\": [ - [ + Object { + "duration": 11, + "fiberActualDurations": Array [ + Array [ 3, - 0 + 0, ], - [ + Array [ 5, - 1 - ], - [ - 2, - 11 - ], - [ 1, - 11 - ] + ], + Array [ + 2, + 11, + ], + Array [ + 1, + 11, + ], ], - \\"fiberSelfDurations\\": [ - [ + "fiberSelfDurations": Array [ + Array [ 3, - 0 + 0, ], - [ + Array [ 5, - 1 - ], - [ - 2, - 10 - ], - [ 1, - 0 - ] + ], + Array [ + 2, + 10, + ], + Array [ + 1, + 0, + ], ], - \\"interactionIDs\\": [ - 1 + "interactionIDs": Array [ + 1, ], - \\"priorityLevel\\": \\"Immediate\\", - \\"screenshot\\": null, - \\"timestamp\\": 22 - } + "priorityLevel": "Immediate", + "screenshot": null, + "timestamp": 22, + }, ], - \\"displayName\\": \\"Parent\\", - \\"initialTreeBaseDurations\\": [], - \\"interactionCommits\\": [ - [ + "displayName": "Parent", + "initialTreeBaseDurations": Array [], + "interactionCommits": Array [ + Array [ 0, - [ - 0 - ] + Array [ + 0, + ], ], - [ + Array [ 1, - [ - 1 - ] - ] + Array [ + 1, + ], + ], ], - \\"interactions\\": [ - [ + "interactions": Array [ + Array [ 0, - { - \\"__count\\": 1, - \\"id\\": 0, - \\"name\\": \\"mount: one child\\", - \\"timestamp\\": 0 - } + Object { + "__count": 1, + "id": 0, + "name": "mount: one child", + "timestamp": 0, + }, ], - [ + Array [ 1, - { - \\"__count\\": 0, - \\"id\\": 1, - \\"name\\": \\"update: two children\\", - \\"timestamp\\": 11 - } - ] + Object { + "__count": 0, + "id": 1, + "name": "update: two children", + "timestamp": 11, + }, + ], ], - \\"operations\\": [ - [ + "operations": Array [ + Array [ 1, 1, 15, @@ -1449,9 +1822,9 @@ exports[`ProfilingCache should report every traced interaction: imported data 1` 0, 4, 4, - 1000 + 1000, ], - [ + Array [ 1, 1, 8, @@ -1484,12 +1857,13 @@ exports[`ProfilingCache should report every traced interaction: imported data 1` 4, 4, 1, - 12000 - ] + 12000, + ], ], - \\"rootID\\": 1, - \\"snapshots\\": [] - } - ] -}" + "rootID": 1, + "snapshots": Array [], + }, + ], + "version": 5, +} `; diff --git a/src/__tests__/profilingCache-test.js b/src/__tests__/profilingCache-test.js index 8ea903dee1..c93d347ea8 100644 --- a/src/__tests__/profilingCache-test.js +++ b/src/__tests__/profilingCache-test.js @@ -29,7 +29,7 @@ describe('ProfilingCache', () => { TestRenderer = utils.requireTestRenderer(); }); - it('should collect data for each root', async done => { + it('should collect data for each root (including ones added or mounted after profiling started)', () => { const Parent = ({ count }) => { Scheduler.advanceTime(10); const children = new Array(count) @@ -48,58 +48,72 @@ describe('ProfilingCache', () => { }; const MemoizedChild = React.memo(Child); - const container = document.createElement('div'); + const containerA = document.createElement('div'); + const containerB = document.createElement('div'); + const containerC = document.createElement('div'); - utils.act(() => ReactDOM.render(, container)); + utils.act(() => ReactDOM.render(, containerA)); + utils.act(() => ReactDOM.render(, containerB)); utils.act(() => store.profilerStore.startProfiling()); - utils.act(() => ReactDOM.render(, container)); - utils.act(() => ReactDOM.render(, container)); - utils.act(() => ReactDOM.render(, container)); + utils.act(() => ReactDOM.render(, containerA)); + utils.act(() => ReactDOM.render(, containerC)); + utils.act(() => ReactDOM.render(, containerA)); + utils.act(() => ReactDOM.unmountComponentAtNode(containerB)); + utils.act(() => ReactDOM.render(, containerA)); utils.act(() => store.profilerStore.stopProfiling()); - let profilingDataForRoot = null; + let allProfilingDataForRoots = []; - // TODO (profarc) Add multi roots - - function Suspender({ previousProfilingDataForRoot, rootID }) { - profilingDataForRoot = store.profilerStore.getDataForRoot(rootID); + function Validator({ previousProfilingDataForRoot, rootID }) { + const profilingDataForRoot = store.profilerStore.getDataForRoot(rootID); if (previousProfilingDataForRoot != null) { expect(profilingDataForRoot).toEqual(previousProfilingDataForRoot); } else { - expect(profilingDataForRoot).toMatchSnapshot('ProfilingSummary'); + expect(profilingDataForRoot).toMatchSnapshot( + `Data for root ${profilingDataForRoot.displayName}` + ); } + allProfilingDataForRoots.push(profilingDataForRoot); return null; } - const rootID = store.roots[0]; + const dataForRoots = + store.profilerStore.profilingData !== null + ? store.profilerStore.profilingData.dataForRoots + : null; - await utils.actAsync(() => - TestRenderer.create( - - - - ) - ); + expect(dataForRoots).not.toBeNull(); - expect(profilingDataForRoot).not.toBeNull(); + if (dataForRoots !== null) { + dataForRoots.forEach(dataForRoot => { + utils.act(() => + TestRenderer.create( + + ) + ); + }); + } - utils.exportImportHelper(bridge, store, rootID); + expect(allProfilingDataForRoots).toHaveLength(3); - await utils.actAsync(() => - TestRenderer.create( - - { + utils.act(() => + TestRenderer.create( + - - ) - ); - - done(); + ) + ); + }); }); - it('should collect data for each commit', async done => { + it('should collect data for each commit', () => { const Parent = ({ count }) => { Scheduler.advanceTime(10); const children = new Array(count) @@ -129,7 +143,7 @@ describe('ProfilingCache', () => { const allCommitData = []; - function Suspender({ commitIndex, previousCommitDetails, rootID }) { + function Validator({ commitIndex, previousCommitDetails, rootID }) { const commitData = store.profilerStore.getCommitData(rootID, commitIndex); if (previousCommitDetails != null) { expect(commitData).toEqual(previousCommitDetails); @@ -145,41 +159,35 @@ describe('ProfilingCache', () => { const rootID = store.roots[0]; for (let commitIndex = 0; commitIndex < 4; commitIndex++) { - await utils.actAsync(() => { + utils.act(() => { TestRenderer.create( - - - + ); }); } expect(allCommitData).toHaveLength(4); - utils.exportImportHelper(bridge, store, rootID); + utils.exportImportHelper(bridge, store); for (let commitIndex = 0; commitIndex < 4; commitIndex++) { - await utils.actAsync(() => { + utils.act(() => { TestRenderer.create( - - - + ); }); } - - done(); }); - it('should calculate a self duration based on actual children (not filtered children)', async done => { + it('should calculate a self duration based on actual children (not filtered children)', () => { store.componentFilters = [utils.createDisplayNameFilter('^Parent$')]; const Grandparent = () => { @@ -208,7 +216,7 @@ describe('ProfilingCache', () => { let commitData = null; - function Suspender({ commitIndex, rootID }) { + function Validator({ commitIndex, rootID }) { commitData = store.profilerStore.getCommitData(rootID, commitIndex); expect(commitData).toMatchSnapshot( `CommitDetails with filtered self durations` @@ -218,17 +226,11 @@ describe('ProfilingCache', () => { const rootID = store.roots[0]; - await utils.actAsync(() => { - TestRenderer.create( - - - - ); + utils.act(() => { + TestRenderer.create(); }); expect(commitData).not.toBeNull(); - - done(); }); it('should calculate self duration correctly for suspended views', async done => { @@ -270,7 +272,7 @@ describe('ProfilingCache', () => { const allCommitData = []; - function Suspender({ commitIndex, rootID }) { + function Validator({ commitIndex, rootID }) { const commitData = store.profilerStore.getCommitData(rootID, commitIndex); allCommitData.push(commitData); expect(commitData).toMatchSnapshot( @@ -282,11 +284,9 @@ describe('ProfilingCache', () => { const rootID = store.roots[0]; for (let commitIndex = 0; commitIndex < 2; commitIndex++) { - await utils.actAsync(() => { + utils.act(() => { TestRenderer.create( - - - + ); }); } @@ -296,7 +296,7 @@ describe('ProfilingCache', () => { done(); }); - it('should collect data for each rendered fiber', async done => { + it('should collect data for each rendered fiber', () => { const Parent = ({ count }) => { Scheduler.advanceTime(10); const children = new Array(count) @@ -325,7 +325,7 @@ describe('ProfilingCache', () => { const allFiberCommits = []; - function Suspender({ fiberID, previousFiberCommits, rootID }) { + function Validator({ fiberID, previousFiberCommits, rootID }) { const fiberCommits = store.profilerStore.profilingCache.getFiberCommits({ fiberID, rootID, @@ -344,49 +344,43 @@ describe('ProfilingCache', () => { const rootID = store.roots[0]; for (let index = 0; index < store.numElements; index++) { - await utils.actAsync(() => { + utils.act(() => { const fiberID = store.getElementIDAtIndex(index); if (fiberID == null) { throw Error(`Unexpected null ID for element at index ${index}`); } TestRenderer.create( - - - + ); }); } expect(allFiberCommits).toHaveLength(store.numElements); - utils.exportImportHelper(bridge, store, rootID); + utils.exportImportHelper(bridge, store); for (let index = 0; index < store.numElements; index++) { - await utils.actAsync(() => { + utils.act(() => { const fiberID = store.getElementIDAtIndex(index); if (fiberID == null) { throw Error(`Unexpected null ID for element at index ${index}`); } TestRenderer.create( - - - + ); }); } - - done(); }); - it('should report every traced interaction', async done => { + it('should report every traced interaction', () => { const Parent = ({ count }) => { Scheduler.advanceTime(10); const children = new Array(count) @@ -426,7 +420,7 @@ describe('ProfilingCache', () => { let interactions = null; - function Suspender({ previousInteractions, rootID }) { + function Validator({ previousInteractions, rootID }) { interactions = store.profilerStore.profilingCache.getInteractionsChartData( { rootID, @@ -442,26 +436,20 @@ describe('ProfilingCache', () => { const rootID = store.roots[0]; - await utils.actAsync(() => + utils.act(() => TestRenderer.create( - - - + ) ); expect(interactions).not.toBeNull(); - utils.exportImportHelper(bridge, store, rootID); + utils.exportImportHelper(bridge, store); - await utils.actAsync(() => + utils.act(() => TestRenderer.create( - - - + ) ); - - done(); }); }); diff --git a/src/__tests__/profilingCharts-test.js b/src/__tests__/profilingCharts-test.js index cebbdc0d54..d83f8b5a0f 100644 --- a/src/__tests__/profilingCharts-test.js +++ b/src/__tests__/profilingCharts-test.js @@ -27,7 +27,7 @@ describe('profiling charts', () => { }); describe('flamegraph chart', () => { - it('should contain valid data', async done => { + it('should contain valid data', () => { const Parent = ({ count }) => { Scheduler.advanceTime(10); return ( @@ -64,7 +64,7 @@ describe('profiling charts', () => { let renderFinished = false; - function Suspender({ commitIndex, rootID }) { + function Validator({ commitIndex, rootID }) { const commitTree = store.profilerStore.profilingCache.getCommitTree({ commitIndex, rootID, @@ -89,27 +89,21 @@ describe('profiling charts', () => { for (let commitIndex = 0; commitIndex < 2; commitIndex++) { renderFinished = false; - await utils.actAsync( - () => - TestRenderer.create( - - - - ), - 3 - ); + utils.act(() => { + TestRenderer.create( + + ); + }); expect(renderFinished).toBe(true); } expect(renderFinished).toBe(true); - - done(); }); }); describe('ranked chart', () => { - it('should contain valid data', async done => { + it('should contain valid data', () => { const Parent = ({ count }) => { Scheduler.advanceTime(10); return ( @@ -146,7 +140,7 @@ describe('profiling charts', () => { let renderFinished = false; - function Suspender({ commitIndex, rootID }) { + function Validator({ commitIndex, rootID }) { const commitTree = store.profilerStore.profilingCache.getCommitTree({ commitIndex, rootID, @@ -169,25 +163,19 @@ describe('profiling charts', () => { for (let commitIndex = 0; commitIndex < 2; commitIndex++) { renderFinished = false; - await utils.actAsync( - () => - TestRenderer.create( - - - - ), - 3 - ); + utils.act(() => { + TestRenderer.create( + + ); + }); expect(renderFinished).toBe(true); } - - done(); }); }); describe('interactions', () => { - it('should contain valid data', async done => { + it('should contain valid data', () => { const Parent = ({ count }) => { Scheduler.advanceTime(10); return ( @@ -224,7 +212,7 @@ describe('profiling charts', () => { let renderFinished = false; - function Suspender({ commitIndex, rootID }) { + function Validator({ commitIndex, rootID }) { const chartData = store.profilerStore.profilingCache.getInteractionsChartData( { rootID, @@ -240,20 +228,14 @@ describe('profiling charts', () => { for (let commitIndex = 0; commitIndex < 2; commitIndex++) { renderFinished = false; - await utils.actAsync( - () => - TestRenderer.create( - - - - ), - 3 - ); + utils.act(() => { + TestRenderer.create( + + ); + }); expect(renderFinished).toBe(true); } - - done(); }); }); }); diff --git a/src/__tests__/profilingCommitTreeBuilder-test.js b/src/__tests__/profilingCommitTreeBuilder-test.js index 17cf9b9e7b..e6c98c1d5e 100644 --- a/src/__tests__/profilingCommitTreeBuilder-test.js +++ b/src/__tests__/profilingCommitTreeBuilder-test.js @@ -24,7 +24,7 @@ describe('commit tree', () => { TestRenderer = utils.requireTestRenderer(); }); - it('should be able to rebuild the store tree for each commit', async done => { + it('should be able to rebuild the store tree for each commit', () => { const Parent = ({ count }) => { Scheduler.advanceTime(10); return new Array(count) @@ -47,7 +47,7 @@ describe('commit tree', () => { let renderFinished = false; - function Suspender({ commitIndex, rootID }) { + function Validator({ commitIndex, rootID }) { const commitTree = store.profilerStore.profilingCache.getCommitTree({ commitIndex, rootID, @@ -62,19 +62,13 @@ describe('commit tree', () => { for (let commitIndex = 0; commitIndex < 4; commitIndex++) { renderFinished = false; - await utils.actAsync( - () => - TestRenderer.create( - - - - ), - 3 - ); + utils.act(() => { + TestRenderer.create( + + ); + }); expect(renderFinished).toBe(true); } - - done(); }); }); diff --git a/src/__tests__/utils.js b/src/__tests__/utils.js index 934e1a593b..d30b9a7d3c 100644 --- a/src/__tests__/utils.js +++ b/src/__tests__/utils.js @@ -133,11 +133,7 @@ export function requireTestRenderer(): ReactTestRenderer { } } -export function exportImportHelper( - bridge: Bridge, - store: Store, - rootID: number -): void { +export function exportImportHelper(bridge: Bridge, store: Store): void { const { act } = require('./utils'); const { prepareProfilingDataExport, @@ -170,7 +166,7 @@ export function exportImportHelper( expect(profilingDataFrontendInitial).toEqual(profilingDataFrontend); // Snapshot the JSON-parsed object, rather than the raw string, because Jest formats the diff nicer. - expect(serializedProfilingDataExport).toMatchSnapshot('imported data'); + expect(parsedProfilingDataExport).toMatchSnapshot('imported data'); act(() => { // Apply the new exported-then-reimported data so tests can re-run assertions.