@@ -1061,30 +1061,24 @@ describe('BaseClient', () => {
10611061 expect ( ( TestClient . instance ! . event ! as any ) . data ) . toBe ( 'someRandomThing' ) ;
10621062 } ) ;
10631063
1064- // TODO(v7): Add back test with client reports
1065- // test('beforeSend records dropped events', () => {
1066- // expect.assertions(1);
1067-
1068- // const client = new TestClient(
1069- // getDefaultTestClientOptions({
1070- // dsn: PUBLIC_DSN,
1071- // beforeSend() {
1072- // return null;
1073- // },
1074- // }),
1075- // );
1076- // const recordLostEventSpy = jest.fn();
1077- // jest.spyOn(client, 'getTransport').mockImplementationOnce(
1078- // () =>
1079- // ({
1080- // recordLostEvent: recordLostEventSpy,
1081- // } as any as Transport),
1082- // );
1083-
1084- // client.captureEvent({ message: 'hello' }, {});
1085-
1086- // expect(recordLostEventSpy).toHaveBeenCalledWith('before_send', 'event');
1087- // });
1064+ test ( 'beforeSend records dropped events' , ( ) => {
1065+ expect . assertions ( 1 ) ;
1066+
1067+ const client = new TestClient (
1068+ getDefaultTestClientOptions ( {
1069+ dsn : PUBLIC_DSN ,
1070+ beforeSend ( ) {
1071+ return null ;
1072+ } ,
1073+ } ) ,
1074+ ) ;
1075+
1076+ const recordLostEventSpy = jest . spyOn ( client , 'recordDroppedEvent' ) ;
1077+
1078+ client . captureEvent ( { message : 'hello' } , { } ) ;
1079+
1080+ expect ( recordLostEventSpy ) . toHaveBeenCalledWith ( 'before_send' , 'error' ) ;
1081+ } ) ;
10881082
10891083 test ( 'eventProcessor can drop the even when it returns null' , ( ) => {
10901084 expect . assertions ( 3 ) ;
@@ -1102,28 +1096,21 @@ describe('BaseClient', () => {
11021096 expect ( loggerWarnSpy ) . toBeCalledWith ( new SentryError ( 'An event processor returned null, will not send event.' ) ) ;
11031097 } ) ;
11041098
1105- // TODO(v7): Add back tests with client reports
1106- // test('eventProcessor records dropped events', () => {
1107- // expect.assertions(1);
1099+ test ( 'eventProcessor records dropped events' , ( ) => {
1100+ expect . assertions ( 1 ) ;
11081101
1109- // const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN });
1110- // const client = new TestClient(options);
1102+ const options = getDefaultTestClientOptions ( { dsn : PUBLIC_DSN } ) ;
1103+ const client = new TestClient ( options ) ;
11111104
1112- // const recordLostEventSpy = jest.fn();
1113- // jest.spyOn(client, 'getTransport').mockImplementationOnce(
1114- // () =>
1115- // ({
1116- // recordLostEvent: recordLostEventSpy,
1117- // } as any as Transport),
1118- // );
1105+ const recordLostEventSpy = jest . spyOn ( client , 'recordDroppedEvent' ) ;
11191106
1120- // const scope = new Scope();
1121- // scope.addEventProcessor(() => null);
1107+ const scope = new Scope ( ) ;
1108+ scope . addEventProcessor ( ( ) => null ) ;
11221109
1123- // client.captureEvent({ message: 'hello' }, {}, scope);
1110+ client . captureEvent ( { message : 'hello' } , { } , scope ) ;
11241111
1125- // expect(recordLostEventSpy).toHaveBeenCalledWith('event_processor', 'event ');
1126- // });
1112+ expect ( recordLostEventSpy ) . toHaveBeenCalledWith ( 'event_processor' , 'error ' ) ;
1113+ } ) ;
11271114
11281115 test ( 'eventProcessor sends an event and logs when it crashes' , ( ) => {
11291116 expect . assertions ( 3 ) ;
@@ -1154,24 +1141,17 @@ describe('BaseClient', () => {
11541141 ) ;
11551142 } ) ;
11561143
1157- // TODO(v7): Add back test with client reports
1158- // test('records events dropped due to sampleRate', () => {
1159- // expect.assertions(1);
1144+ test ( 'records events dropped due to sampleRate' , ( ) => {
1145+ expect . assertions ( 1 ) ;
11601146
1161- // const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, sampleRate: 0 });
1162- // const client = new TestClient(options);
1147+ const options = getDefaultTestClientOptions ( { dsn : PUBLIC_DSN , sampleRate : 0 } ) ;
1148+ const client = new TestClient ( options ) ;
11631149
1164- // const recordLostEventSpy = jest.fn();
1165- // jest.spyOn(client, 'getTransport').mockImplementationOnce(
1166- // () =>
1167- // ({
1168- // recordLostEvent: recordLostEventSpy,
1169- // } as any as Transport),
1170- // );
1150+ const recordLostEventSpy = jest . spyOn ( client , 'recordDroppedEvent' ) ;
11711151
1172- // client.captureEvent({ message: 'hello' }, {});
1173- // expect(recordLostEventSpy).toHaveBeenCalledWith('sample_rate', 'event ');
1174- // });
1152+ client . captureEvent ( { message : 'hello' } , { } ) ;
1153+ expect ( recordLostEventSpy ) . toHaveBeenCalledWith ( 'sample_rate' , 'error ' ) ;
1154+ } ) ;
11751155 } ) ;
11761156
11771157 describe ( 'integrations' , ( ) => {
@@ -1366,4 +1346,69 @@ describe('BaseClient', () => {
13661346 expect ( TestClient . instance ! . session ) . toBeUndefined ( ) ;
13671347 } ) ;
13681348 } ) ;
1349+
1350+ describe ( 'recordDroppedEvent()/_clearOutcomes()' , ( ) => {
1351+ test ( 'record and return outcomes' , ( ) => {
1352+ const options = getDefaultTestClientOptions ( { dsn : PUBLIC_DSN } ) ;
1353+ const client = new TestClient ( options ) ;
1354+
1355+ client . recordDroppedEvent ( 'ratelimit_backoff' , 'error' ) ;
1356+ client . recordDroppedEvent ( 'ratelimit_backoff' , 'error' ) ;
1357+ client . recordDroppedEvent ( 'network_error' , 'transaction' ) ;
1358+ client . recordDroppedEvent ( 'network_error' , 'transaction' ) ;
1359+ client . recordDroppedEvent ( 'before_send' , 'session' ) ;
1360+ client . recordDroppedEvent ( 'event_processor' , 'attachment' ) ;
1361+ client . recordDroppedEvent ( 'network_error' , 'transaction' ) ;
1362+
1363+ const clearedOutcomes = client . _clearOutcomes ( ) ;
1364+
1365+ expect ( clearedOutcomes ) . toEqual (
1366+ expect . arrayContaining ( [
1367+ {
1368+ reason : 'ratelimit_backoff' ,
1369+ category : 'error' ,
1370+ quantity : 2 ,
1371+ } ,
1372+ {
1373+ reason : 'network_error' ,
1374+ category : 'transaction' ,
1375+ quantity : 3 ,
1376+ } ,
1377+ {
1378+ reason : 'before_send' ,
1379+ category : 'session' ,
1380+ quantity : 1 ,
1381+ } ,
1382+ {
1383+ reason : 'event_processor' ,
1384+ category : 'attachment' ,
1385+ quantity : 1 ,
1386+ } ,
1387+ ] ) ,
1388+ ) ;
1389+ } ) ;
1390+
1391+ test ( 'to clear outcomes' , ( ) => {
1392+ const options = getDefaultTestClientOptions ( { dsn : PUBLIC_DSN } ) ;
1393+ const client = new TestClient ( options ) ;
1394+
1395+ client . recordDroppedEvent ( 'ratelimit_backoff' , 'error' ) ;
1396+ client . recordDroppedEvent ( 'ratelimit_backoff' , 'error' ) ;
1397+ client . recordDroppedEvent ( 'event_processor' , 'attachment' ) ;
1398+
1399+ const clearedOutcomes1 = client . _clearOutcomes ( ) ;
1400+ expect ( clearedOutcomes1 . length ) . toEqual ( 2 ) ;
1401+
1402+ const clearedOutcomes2 = client . _clearOutcomes ( ) ;
1403+ expect ( clearedOutcomes2 . length ) . toEqual ( 0 ) ;
1404+
1405+ client . recordDroppedEvent ( 'network_error' , 'attachment' ) ;
1406+
1407+ const clearedOutcomes3 = client . _clearOutcomes ( ) ;
1408+ expect ( clearedOutcomes3 . length ) . toEqual ( 1 ) ;
1409+
1410+ const clearedOutcomes4 = client . _clearOutcomes ( ) ;
1411+ expect ( clearedOutcomes4 . length ) . toEqual ( 0 ) ;
1412+ } ) ;
1413+ } ) ;
13691414} ) ;
0 commit comments