Skip to content

Commit

Permalink
fix(core): Return checkin id from client (#8116)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhiPrasad committed May 15, 2023
1 parent 9a267eb commit 5440807
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
9 changes: 8 additions & 1 deletion packages/browser/test/unit/sdk.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable @typescript-eslint/unbound-method */
import { createTransport, Scope } from '@sentry/core';
import { MockIntegration } from '@sentry/core/test/lib/sdk.test';
import type { Client, Integration } from '@sentry/types';
import { resolvedSyncPromise } from '@sentry/utils';

Expand All @@ -18,6 +17,14 @@ function getDefaultBrowserOptions(options: Partial<BrowserOptions> = {}): Browse
};
}

export class MockIntegration implements Integration {
public name: string;
public setupOnce: () => void = jest.fn();
public constructor(name: string) {
this.name = name;
}
}

jest.mock('@sentry/core', () => {
const original = jest.requireActual('@sentry/core');
return {
Expand Down
7 changes: 2 additions & 5 deletions packages/core/src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,14 @@ export function startTransaction(
* to create a monitor automatically when sending a check in.
*/
export function captureCheckIn(checkIn: CheckIn, upsertMonitorConfig?: MonitorConfig): string {
const capturedCheckIn =
checkIn.status !== 'in_progress' && checkIn.checkInId ? checkIn : { ...checkIn, checkInId: uuid4() };

const client = getCurrentHub().getClient();
if (!client) {
__DEBUG_BUILD__ && logger.warn('Cannot capture check-in. No client defined.');
} else if (!client.captureCheckIn) {
__DEBUG_BUILD__ && logger.warn('Cannot capture check-in. Client does not support sending check-ins.');
} else {
client.captureCheckIn(capturedCheckIn, upsertMonitorConfig);
return client.captureCheckIn(checkIn, upsertMonitorConfig);
}

return capturedCheckIn.checkInId;
return uuid4();
}
2 changes: 1 addition & 1 deletion packages/core/test/lib/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('captureCheckIn', () => {
} as unknown as Client;
});

expect(captureCheckIn({ monitorSlug: 'gogogo', status: 'in_progress' })).toStrictEqual(expect.any(String));
expect(captureCheckIn({ monitorSlug: 'gogogo', status: 'in_progress' })).toStrictEqual('some-id-wasd-1234');
});

it('returns an id when client is undefined', () => {
Expand Down

0 comments on commit 5440807

Please sign in to comment.