fix[react-devtools]: fixed timeline profiler tests (#31261)
Fixes tests against React 18 after https://github.com/facebook/react/pull/31154: - Set `supportsTimeline` to true for `Store`. - Execute `store.profilerStore.startProfiling` after `legacyRender` import, because this is where `react-dom` is imported and renderer is registered. We don't yet propagate `isProfiling` flag to newly registered renderers, when profiling already started see: https://github.com/facebook/react/blob/d5bba18b5d81f234657586865248c5b6849599cd/packages/react-devtools-shared/src/hook.js#L203-L204
Ruslan Lesiutin committed
Oct 15, 2024 at 12:46 UTC
ec2bf022450107a77cc2850ec96b9173fc6f40eb
2 files changed
+11
-5
packages/react-devtools-shared/src/__tests__/TimelineProfiler-test.js
+8
-4
@@ -1280,13 +1280,13 @@ describe('Timeline profiler', () => {
1280
});
1281
1282
describe('when profiling', () => {
1283
- beforeEach(() => {
1284
- utils.act(() => store.profilerStore.startProfiling());
1285
- });
1286
-
1283
describe('with legacy render', () => {
1284
const {render: legacyRender} = getLegacyRenderImplementation();
1285
1286
+ beforeEach(() => {
1287
+ utils.act(() => store.profilerStore.startProfiling());
1288
+ });
1289
+
1290
// @reactVersion <= 18.2
1291
// @reactVersion >= 18.0
1292
it('should mark sync render without suspends or state updates', () => {
@@ -1537,6 +1537,10 @@ describe('Timeline profiler', () => {
1537
1538
const {render: modernRender} = getModernRenderImplementation();
1539
1540
+ beforeEach(() => {
1541
+ utils.act(() => store.profilerStore.startProfiling());
1542
+ });
1543
+
1544
it('should mark concurrent render without suspends or state updates', () => {
1545
utils.act(() => modernRender(<div />));
1546
packages/react-devtools-shared/src/__tests__/setupTests.js
+3
-1
@@ -256,7 +256,9 @@ beforeEach(() => {
256
},
257
});
258
259
- const store = new Store(((bridge: any): FrontendBridge));
259
+ const store = new Store(((bridge: any): FrontendBridge), {
260
+ supportsTimeline: true,
261
+ });
262
263
const agent = new Agent(((bridge: any): BackendBridge));
264
const hook = global.__REACT_DEVTOOLS_GLOBAL_HOOK__;