mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
671520943f
commit
fe8d102663
+71
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user