Skip to content

Commit 1b7c9ea

Browse files
rubennortefacebook-github-bot
authored andcommitted
Add 2 tests demonstrating broken behavior in performance.measure (#52588)
Summary: Pull Request resolved: #52588 Changelog: [internal] This adds tests to show how `performance.measure` isn't spec compliant when `end` and `duration` are used. This will be fixed in the following diff. Reviewed By: javache Differential Revision: D78193069 fbshipit-source-id: 30ba4874c4d2b4adb20608fc8d5ed61bfd6d92d8
1 parent cb59eb2 commit 1b7c9ea

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

packages/react-native/src/private/webapis/performance/Performance.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ export type PerformanceMeasureOptions =
4848
detail?: DetailType,
4949
start?: DOMHighResTimeStamp | string,
5050
end?: DOMHighResTimeStamp | string,
51+
}>
52+
| $ReadOnly<{
53+
detail?: DetailType,
54+
duration?: DOMHighResTimeStamp | string,
55+
end?: DOMHighResTimeStamp | string,
5156
}>;
5257

5358
const ENTRY_TYPES_AVAILABLE_FROM_TIMELINE: $ReadOnlyArray<PerformanceEntryType> =

packages/react-native/src/private/webapis/performance/__tests__/UserTiming-itest.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,48 @@ describe('User Timing', () => {
293293
expect(measure.detail).toBe(null);
294294
});
295295

296+
// TODO fix case
297+
// eslint-disable-next-line jest/no-disabled-tests
298+
it.skip('works with an end timestamp and a duration', () => {
299+
const measure = performance.measure(
300+
'measure-with-end-timestamp-and-duration',
301+
{
302+
end: 40,
303+
duration: 30,
304+
},
305+
);
306+
307+
expect(measure).toBeInstanceOf(PerformanceMeasure);
308+
expect(measure.entryType).toBe('measure');
309+
expect(measure.name).toBe('measure-with-end-timestamp-and-duration');
310+
expect(measure.startTime).toBe(10);
311+
expect(measure.duration).toBe(30);
312+
expect(measure.detail).toBe(null);
313+
});
314+
315+
// TODO fix case
316+
// eslint-disable-next-line jest/no-disabled-tests
317+
it.skip('works with an end mark and a duration', () => {
318+
performance.mark('end-mark', {
319+
startTime: 40,
320+
});
321+
322+
const measure = performance.measure(
323+
'measure-with-end-mark-and-duration',
324+
{
325+
end: 'end-mark',
326+
duration: 30,
327+
},
328+
);
329+
330+
expect(measure).toBeInstanceOf(PerformanceMeasure);
331+
expect(measure.entryType).toBe('measure');
332+
expect(measure.name).toBe('measure-with-end-mark-and-duration');
333+
expect(measure.startTime).toBe(10);
334+
expect(measure.duration).toBe(30);
335+
expect(measure.detail).toBe(null);
336+
});
337+
296338
it('throws if the specified mark does NOT exist', () => {
297339
const missingStartMarkError = ensureInstance(
298340
getThrownError(() => {

0 commit comments

Comments
 (0)