123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- import {RawSpanFrame} from 'sentry/utils/replays/types';
- type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
- type TestableFrame<Op extends RawSpanFrame['op']> = Overwrite<
- Partial<Extract<RawSpanFrame, {op: Op}>>,
- {endTimestamp: Date; startTimestamp: Date}
- >;
- type MockFrame<Op extends RawSpanFrame['op']> = Extract<RawSpanFrame, {op: Op}>;
- function BaseFrame<T extends RawSpanFrame['op']>(
- op: T,
- fields: TestableFrame<T>
- ): MockFrame<T> {
- return {
- op,
- description: fields.description ?? '',
- startTimestamp: fields.startTimestamp.getTime() / 1000,
- endTimestamp: fields.endTimestamp.getTime() / 1000,
- data: fields.data,
- } as MockFrame<T>;
- }
- export function ReplayWebVitalFrameFixture(
- fields: TestableFrame<'largest-contentful-paint' | 'cumulative-layout-shift' | 'first-input-delay' | 'interaction-to-next-paint'
- >
- ): MockFrame<'largest-contentful-paint' | 'cumulative-layout-shift' | 'first-input-delay' | 'interaction-to-next-paint'
- > {
- return BaseFrame(fields.op ?? 'largest-contentful-paint', {
- ...fields,
- data: {
- nodeId: fields.data?.nodeId,
- size: fields.data?.size ?? 0,
- value: fields.data?.value ?? 0,
- rating: fields.data?.rating ?? "good",
- },
- });
- }
- export function ReplayMemoryFrameFixture(
- fields: TestableFrame<'memory'>
- ): MockFrame<'memory'> {
- return BaseFrame('memory', {
- ...fields,
- data: {
- memory: {
- jsHeapSizeLimit: fields.data?.memory?.jsHeapSizeLimit ?? 0,
- totalJSHeapSize: fields.data?.memory?.totalJSHeapSize ?? 0,
- usedJSHeapSize: fields.data?.memory?.usedJSHeapSize ?? 0,
- },
- },
- });
- }
- export function ReplayNavigationFrameFixture(
- fields: TestableFrame<
- 'navigation.navigate' | 'navigation.reload' | 'navigation.back_forward'
- >
- ): MockFrame<'navigation.navigate' | 'navigation.reload' | 'navigation.back_forward'> {
- return BaseFrame(fields.op ?? 'navigation.navigate', {
- ...fields,
- data: {
- decodedBodySize: fields.data?.decodedBodySize,
- domComplete: fields.data?.domComplete,
- domContentLoadedEventEnd: fields.data?.domContentLoadedEventEnd,
- domContentLoadedEventStart: fields.data?.domContentLoadedEventStart,
- domInteractive: fields.data?.domInteractive,
- duration: fields.data?.duration,
- encodedBodySize: fields.data?.encodedBodySize,
- loadEventEnd: fields.data?.loadEventEnd,
- loadEventStart: fields.data?.loadEventStart,
- redirectCount: fields.data?.redirectCount,
- size: fields.data?.size,
- },
- });
- }
- export function ReplayNavigationPushFrameFixture(
- fields: TestableFrame<'navigation.push'>
- ): MockFrame<'navigation.push'> {
- return BaseFrame('navigation.push', {
- ...fields,
- data: {
- previous: fields.data?.previous ?? '/',
- },
- });
- }
- export function ReplayPaintFrameFixture(
- fields: TestableFrame<'paint'>
- ): MockFrame<'paint'> {
- return BaseFrame('paint', fields);
- }
- export function ReplayRequestFrameFixture(
- fields: TestableFrame<'resource.fetch' | 'resource.xhr' | 'resource.http'>
- ): MockFrame<'resource.fetch' | 'resource.xhr' | 'resource.http'> {
- return BaseFrame(fields.op ?? 'resource.xhr', {
- ...fields,
- data: {
- method: fields.data?.method,
- requestBodySize: fields.data?.requestBodySize,
- responseBodySize: fields.data?.responseBodySize,
- statusCode: fields.data?.statusCode,
- request: fields.data?.request,
- response: fields.data?.response,
- },
- });
- }
- export function ReplayResourceFrameFixture(
- fields: TestableFrame<
- | 'resource.css'
- | 'resource.iframe'
- | 'resource.img'
- | 'resource.link'
- | 'resource.other'
- | 'resource.script'
- >
- ): MockFrame<
- | 'resource.css'
- | 'resource.iframe'
- | 'resource.img'
- | 'resource.link'
- | 'resource.other'
- | 'resource.script'
- > {
- return BaseFrame(fields.op ?? 'resource.other', {
- ...fields,
- data: {
- decodedBodySize: fields.data?.decodedBodySize ?? 0,
- encodedBodySize: fields.data?.encodedBodySize ?? 0,
- size: fields.data?.size ?? 0,
- statusCode: fields.data?.statusCode,
- },
- });
- }
|