From fe8d1026632a42e0feb3927ecaf40ed944110242 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Mon, 13 Jan 2025 07:01:03 -0800 Subject: [PATCH] Create placeholder for User Timing API tests (#48634) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/48634 Changelog: [internal] Just a placeholder to add new tests in the future. Reviewed By: sammy-SC Differential Revision: D68093342 fbshipit-source-id: 1e1d7fd71865763ef66b3bb1c76ff8b8ebca9fd9 --- .../__tests__/UserTimingAPI-itest.js | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 packages/react-native/src/private/webapis/performance/__tests__/UserTimingAPI-itest.js diff --git a/packages/react-native/src/private/webapis/performance/__tests__/UserTimingAPI-itest.js b/packages/react-native/src/private/webapis/performance/__tests__/UserTimingAPI-itest.js new file mode 100644 index 00000000000..f016bd20160 --- /dev/null +++ b/packages/react-native/src/private/webapis/performance/__tests__/UserTimingAPI-itest.js @@ -0,0 +1,71 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow strict-local + * @format + * @oncall react_native + * @fantom_flags enableLongTaskAPI:true + */ + +import setUpPerformanceObserver from '../../../setup/setUpPerformanceObserver'; +import ensureInstance from '../../../utilities/ensureInstance'; +import {PerformanceMark} from '../UserTiming'; +import {runWorkLoop} from '@react-native/fantom'; + +import '../../../../../Libraries/Core/InitializeCore.js'; + +setUpPerformanceObserver(); + +describe('User Timing API', () => { + describe('performance.mark()', () => { + it('reports marks to observers', () => { + const callback = jest.fn(); + + const observer = new PerformanceObserver(callback); + observer.observe({type: 'mark'}); + + expect(callback).not.toHaveBeenCalled(); + + const mark1Detail = Symbol('mark1Detail'); + performance.mark('mark1', { + startTime: 100, + detail: mark1Detail, + }); + + const mark2Detail = Symbol('mark2Detail'); + performance.mark('mark2', { + startTime: 200, + detail: mark2Detail, + }); + + expect(callback).not.toHaveBeenCalled(); + + runWorkLoop(); + + expect(callback).toHaveBeenCalledTimes(1); + + const entries = callback.mock.lastCall[0].getEntries(); + expect(entries.length).toBe(2); + + const mark1 = ensureInstance(entries[0], PerformanceMark); + const mark2 = ensureInstance(entries[1], PerformanceMark); + + expect(mark1.entryType).toBe('mark'); + expect(mark1.name).toBe('mark1'); + expect(mark1.startTime).toBe(100); + expect(mark1.duration).toBe(0); + // This doesn't work through PerformanceObserver yet + // expect(mark1.detail).toBe(mark1Detail); + + expect(mark2.entryType).toBe('mark'); + expect(mark2.name).toBe('mark2'); + expect(mark2.startTime).toBe(200); + expect(mark2.duration).toBe(0); + // This doesn't work through PerformanceObserver yet + // expect(mark2.detail).toBe(mark2Detail); + }); + }); +});