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
This commit is contained in:
Rubén Norte
2025-09-08 14:41:23 +01:00
committed by Vitali Zaidman
parent 72d4a1cbd4
commit 1cacdf70a1
5 changed files with 4 additions and 35 deletions
@@ -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) {}
@@ -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();
@@ -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();
@@ -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<PerformanceObserverT>;
describe('PerformanceObserver', () => {
it('receives notifications for marks and measures', () => {
const callback = jest.fn();
@@ -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<PerformanceEntryJSON> {
function toJSON(entries: PerformanceEntryList): Array<mixed> {
return entries.map(entry => entry.toJSON());
}