Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import type Store from 'react-devtools-shared/src/devtools/store';

import {getVersionedRenderImplementation} from './utils';
import {ElementTypeFunction} from 'react-devtools-shared/src/frontend/types';
import {getChartData as getRankedChartDataFromBuilder} from 'react-devtools-shared/src/devtools/views/Profiler/RankedChartBuilder';

describe('profiling charts', () => {
let React;
Expand All @@ -31,6 +33,72 @@ describe('profiling charts', () => {

const {render} = getVersionedRenderImplementation();

it('ranked chart should ignore durations for nodes missing from the commit tree', () => {
const commitTree = {
rootID: 1,
nodes: new Map([
[
1,
{
children: [2],
compiledWithForget: false,
displayName: null,
hocDisplayNames: null,
id: 1,
key: null,
parentID: 0,
treeBaseDuration: 0,
type: ElementTypeFunction,
},
],
[
2,
{
children: [],
compiledWithForget: false,
displayName: 'Parent',
hocDisplayNames: null,
id: 2,
key: null,
parentID: 1,
treeBaseDuration: 10,
type: ElementTypeFunction,
},
],
]),
};
const profilerStore = {
getCommitData() {
return {
fiberActualDurations: new Map([
[2, 10],
[3, 5],
]),
fiberSelfDurations: new Map([
[2, 10],
[3, 5],
]),
};
},
};

const chartData = getRankedChartDataFromBuilder({
commitIndex: 0,
commitTree,
profilerStore,
rootID: 123,
});

expect(chartData.nodes).toEqual([
{
id: 2,
label: 'Parent (10ms)',
name: 'Parent',
value: 10,
},
]);
});

function getFlamegraphChartData(rootID, commitIndex) {
const commitTree = store.profilerStore.profilingCache.getCommitTree({
commitIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function getChartData({
const node = nodes.get(id);

if (node == null) {
throw Error(`Could not find node with id "${id}" in commit tree`);
return;
}

const {displayName, key, parentID, type, compiledWithForget} = node;
Expand Down