From 1cacdf70a1cd2b0dac2676fcff7989bdd230a1ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Mon, 1 Sep 2025 09:18:19 -0700 Subject: [PATCH] Remove unnecessary references to internal types in performance tests (#53427) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/53427 Changelog: [internal] Migrate the imported types to the globally defined ones, so we follow the good practice of only accessing the public API in Fantom tests. Reviewed By: rshest Differential Revision: D80807160 fbshipit-source-id: 77d792b56b53c8da8409dd9133cd111afb8084f1 --- .../performance/__tests__/EventTimingAPI-itest.js | 7 ------- .../performance/__tests__/LongTasksAPI-itest.js | 7 +------ .../__tests__/Performance-benchmark-itest.js | 4 ---- .../__tests__/PerformanceObserver-itest.js | 9 --------- .../performance/__tests__/UserTiming-itest.js | 12 +++--------- 5 files changed, 4 insertions(+), 35 deletions(-) diff --git a/packages/react-native/src/private/webapis/performance/__tests__/EventTimingAPI-itest.js b/packages/react-native/src/private/webapis/performance/__tests__/EventTimingAPI-itest.js index 5c46106f95d..886a5da8481 100644 --- a/packages/react-native/src/private/webapis/performance/__tests__/EventTimingAPI-itest.js +++ b/packages/react-native/src/private/webapis/performance/__tests__/EventTimingAPI-itest.js @@ -10,24 +10,17 @@ import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment'; -import type Performance from 'react-native/src/private/webapis/performance/Performance'; -import type {PerformanceObserverEntryList} from 'react-native/src/private/webapis/performance/PerformanceObserver'; - import MaybeNativePerformance from '../specs/NativePerformance'; import * as Fantom from '@react-native/fantom'; import nullthrows from 'nullthrows'; import {useState} from 'react'; import {Text, View} from 'react-native'; import setUpPerformanceObserver from 'react-native/src/private/setup/setUpPerformanceObserver'; -import {PerformanceEventTiming} from 'react-native/src/private/webapis/performance/EventTiming'; -import {PerformanceObserver} from 'react-native/src/private/webapis/performance/PerformanceObserver'; const NativePerformance = nullthrows(MaybeNativePerformance); setUpPerformanceObserver(); -declare var performance: Performance; - function sleep(ms: number) { const end = performance.now() + ms; while (performance.now() < end) {} diff --git a/packages/react-native/src/private/webapis/performance/__tests__/LongTasksAPI-itest.js b/packages/react-native/src/private/webapis/performance/__tests__/LongTasksAPI-itest.js index 80ff9cf54f0..990663ff03b 100644 --- a/packages/react-native/src/private/webapis/performance/__tests__/LongTasksAPI-itest.js +++ b/packages/react-native/src/private/webapis/performance/__tests__/LongTasksAPI-itest.js @@ -10,15 +10,10 @@ import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment'; -import type { - PerformanceObserverCallbackOptions, - PerformanceObserverEntryList, -} from 'react-native/src/private/webapis/performance/PerformanceObserver'; +import type {PerformanceObserverCallbackOptions} from '../PerformanceObserver'; import * as Fantom from '@react-native/fantom'; import setUpPerformanceObserver from 'react-native/src/private/setup/setUpPerformanceObserver'; -import {PerformanceLongTaskTiming} from 'react-native/src/private/webapis/performance/LongTasks'; -import {PerformanceObserver} from 'react-native/src/private/webapis/performance/PerformanceObserver'; setUpPerformanceObserver(); diff --git a/packages/react-native/src/private/webapis/performance/__tests__/Performance-benchmark-itest.js b/packages/react-native/src/private/webapis/performance/__tests__/Performance-benchmark-itest.js index d69768d8d71..2829b8f94cf 100644 --- a/packages/react-native/src/private/webapis/performance/__tests__/Performance-benchmark-itest.js +++ b/packages/react-native/src/private/webapis/performance/__tests__/Performance-benchmark-itest.js @@ -10,12 +10,8 @@ import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment'; -import type Performance from 'react-native/src/private/webapis/performance/Performance'; - import * as Fantom from '@react-native/fantom'; -declare var performance: Performance; - const clearMarksAndMeasures = () => { performance.clearMarks(); performance.clearMeasures(); diff --git a/packages/react-native/src/private/webapis/performance/__tests__/PerformanceObserver-itest.js b/packages/react-native/src/private/webapis/performance/__tests__/PerformanceObserver-itest.js index c3c65486e34..77af8cb8c83 100644 --- a/packages/react-native/src/private/webapis/performance/__tests__/PerformanceObserver-itest.js +++ b/packages/react-native/src/private/webapis/performance/__tests__/PerformanceObserver-itest.js @@ -10,20 +10,11 @@ import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment'; -import type Performance from '../Performance'; -import type { - PerformanceObserver as PerformanceObserverT, - PerformanceObserverEntryList, -} from '../PerformanceObserver'; - import setUpPerformanceObserver from '../../../setup/setUpPerformanceObserver'; import * as Fantom from '@react-native/fantom'; setUpPerformanceObserver(); -declare var performance: Performance; -declare var PerformanceObserver: Class; - describe('PerformanceObserver', () => { it('receives notifications for marks and measures', () => { const callback = jest.fn(); diff --git a/packages/react-native/src/private/webapis/performance/__tests__/UserTiming-itest.js b/packages/react-native/src/private/webapis/performance/__tests__/UserTiming-itest.js index 0bc20e7c012..00714de389f 100644 --- a/packages/react-native/src/private/webapis/performance/__tests__/UserTiming-itest.js +++ b/packages/react-native/src/private/webapis/performance/__tests__/UserTiming-itest.js @@ -10,18 +10,12 @@ import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment'; -import type Performance from '../Performance'; -import type { - PerformanceEntryJSON, - PerformanceEntryList, -} from '../PerformanceEntry'; - import ensureInstance from '../../../__tests__/utilities/ensureInstance'; +import setUpPerformanceObserver from '../../../setup/setUpPerformanceObserver'; import DOMException from '../../errors/DOMException'; -import {PerformanceMark, PerformanceMeasure} from '../UserTiming'; import * as Fantom from '@react-native/fantom'; -declare var performance: Performance; +setUpPerformanceObserver(); function getThrownError(fn: () => mixed): mixed { try { @@ -32,7 +26,7 @@ function getThrownError(fn: () => mixed): mixed { throw new Error('Expected function to throw'); } -function toJSON(entries: PerformanceEntryList): Array { +function toJSON(entries: PerformanceEntryList): Array { return entries.map(entry => entry.toJSON()); }