Profilerstore Test
Profilerstore Test
describe('ProfilerStore', () => {
let React;
let ReactDOM;
let legacyRender;
let store: Store;
let utils;
beforeEach(() => {
utils = require('./utils');
utils.beforeEachProfiling();
legacyRender = utils.legacyRender;
store = global.store;
store.collapseNodesByDefault = false;
store.recordChangeDescriptions = true;
React = require('react');
ReactDOM = require('react-dom');
});
utils.act(() => {
legacyRender(<Parent key="A" count={3} />, containerA);
legacyRender(<Parent key="B" count={2} />, containerB);
});
utils.act(() => {
legacyRender(<Parent key="A" count={4} />, containerA);
legacyRender(<Parent key="B" count={1} />, containerB);
});
expect(store.profilerStore.getDataForRoot(rootA)).not.toBeNull();
expect(store.profilerStore.getDataForRoot(rootB)).not.toBeNull();
});
// This element has to be in the <body> for the event system to work.
document.body.appendChild(container);
// Only one commit should have been recorded (in response to the "change"
event).
const root = store.roots[0];
const data = store.profilerStore.getDataForRoot(root);
expect(data.commitData).toHaveLength(1);
expect(data.operations).toHaveLength(1);
});
require('scheduler').unstable_advanceTime(1);
React.useLayoutEffect(() => {
commitCount++;
});
// This element has to be in the <body> for the event system to work.
document.body.appendChild(container);
expect(commitCount).toBe(1);
commitCount = 0;
expect(() => {
utils.act(() => {
const {
ElementTypeHostComponent,
} = require('react-devtools-shared/src/frontend/types');
store.componentFilters = [
utils.createElementTypeFilter(ElementTypeHostComponent),
];
});
}).toThrow('Cannot modify filter preferences while profiling');
});
// This element has to be in the <body> for the event system to work.
document.body.appendChild(container);
// Only one commit should have been recorded (in response to the "change"
event).
const root = store.roots[0];
const data = store.profilerStore.getDataForRoot(root);
expect(data.commitData).toHaveLength(1);
expect(data.operations).toHaveLength(1);
});