Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
billyvg committed May 15, 2023
1 parent 84295c4 commit f6ab9a2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/replay/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export interface WorkerResponse {
export type AddEventResult = void;

export interface BeforeAddRecoringEvent {
(event: RecordingEvent): RecordingEvent | null | undefined
(event: RecordingEvent): RecordingEvent | null | undefined;
}

export interface ReplayNetworkOptions {
Expand Down
8 changes: 4 additions & 4 deletions packages/replay/src/util/addEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ export async function addEvent(

const replayOptions = replay.getOptions();

console.log('add event: ', typeof replayOptions.beforeAddRecordingEvent, event.type)
const eventAfterPossibleCallback = typeof replayOptions.beforeAddRecordingEvent === 'function' ?
replayOptions.beforeAddRecordingEvent(event) : event;
const eventAfterPossibleCallback =
typeof replayOptions.beforeAddRecordingEvent === 'function'
? replayOptions.beforeAddRecordingEvent(event)
: event;

if (!eventAfterPossibleCallback) {
return;
}

return await replay.eventBuffer.addEvent(eventAfterPossibleCallback);
} catch (error) {
console.error(error)
__DEBUG_BUILD__ && logger.error(error);
await replay.stop('addEvent');

Expand Down
18 changes: 6 additions & 12 deletions packages/replay/test/integration/beforeAddRecordingEvent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import type { Transport } from '@sentry/types';
import * as SentryUtils from '@sentry/utils';

import type { Replay } from '../../src';
import { DEFAULT_FLUSH_MIN_DELAY, WINDOW } from '../../src/constants';
import type { ReplayContainer } from '../../src/replay';
import { clearSession } from '../../src/session/clearSession';
import { addEvent } from '../../src/util/addEvent';
import * as SendReplayRequest from '../../src/util/sendReplayRequest';
import { BASE_TIMESTAMP, mockRrweb, mockSdk } from '../index';
import { useFakeTimers } from '../utils/use-fake-timers';
Expand Down Expand Up @@ -38,20 +36,19 @@ describe('Integration | beforeAddRecordingEvent', () => {

({ replay, integration } = await mockSdk({
replayOptions: {
beforeAddRecordingEvent: (event) => {
beforeAddRecordingEvent: event => {
const eventData = event.data as Record<string, any>;

if (eventData.tag === 'breadcrumb' && eventData.payload.category === 'ui.click') {

return {
...event,
data: {
...eventData,
payload: {
...eventData.payload,
message: 'beforeAddRecordingEvent',
}
}
},
},
};
}

Expand Down Expand Up @@ -106,7 +103,7 @@ describe('Integration | beforeAddRecordingEvent', () => {
await advanceTimers(5000);

expect(replay).toHaveLastSentReplay({
recordingPayloadHeader: {segment_id: 0},
recordingPayloadHeader: { segment_id: 0 },
recordingData: JSON.stringify([
{
type: 5,
Expand All @@ -122,7 +119,6 @@ describe('Integration | beforeAddRecordingEvent', () => {
},
},
},

]),
});
});
Expand All @@ -136,10 +132,8 @@ describe('Integration | beforeAddRecordingEvent', () => {
jest.runAllTimers();
await new Promise(process.nextTick);
expect(replay).toHaveLastSentReplay({
recordingPayloadHeader: {segment_id: 0},
recordingData: JSON.stringify([
{"data":{"isCheckout":true},"timestamp":BASE_TIMESTAMP,"type":2}
]),
recordingPayloadHeader: { segment_id: 0 },
recordingData: JSON.stringify([{ data: { isCheckout: true }, timestamp: BASE_TIMESTAMP, type: 2 }]),
});
});
});

0 comments on commit f6ab9a2

Please sign in to comment.