Skip to content

Commit

Permalink
Create placeholder for User Timing API tests
Browse files Browse the repository at this point in the history
Summary:
Changelog: [internal]

Just a placeholder to add new tests in the future.

Differential Revision: D68093342
  • Loading branch information
rubennorte authored and facebook-github-bot committed Jan 13, 2025
1 parent f832c45 commit 7d55284
Showing 1 changed file with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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);
});
});
});

0 comments on commit 7d55284

Please sign in to comment.