From 3fbc33807580523c4e25d9a86fb468a4ac92c69c Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 15 May 2023 10:40:53 +0200 Subject: [PATCH 1/2] fix(core): Return checkin id from client --- packages/core/src/exports.ts | 7 ++----- packages/core/test/lib/sdk.test.ts | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/core/src/exports.ts b/packages/core/src/exports.ts index 207cfde505b6..ba283914fbbd 100644 --- a/packages/core/src/exports.ts +++ b/packages/core/src/exports.ts @@ -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(); } diff --git a/packages/core/test/lib/sdk.test.ts b/packages/core/test/lib/sdk.test.ts index 46c694951ab2..afb1987262d9 100644 --- a/packages/core/test/lib/sdk.test.ts +++ b/packages/core/test/lib/sdk.test.ts @@ -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', () => { From 377da87712d3fc40afc4ad6c2ba82418449fee92 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 15 May 2023 12:04:20 +0200 Subject: [PATCH 2/2] fix running core tests --- packages/browser/test/unit/sdk.test.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/browser/test/unit/sdk.test.ts b/packages/browser/test/unit/sdk.test.ts index 4afac502c562..75b10d5c3ed3 100644 --- a/packages/browser/test/unit/sdk.test.ts +++ b/packages/browser/test/unit/sdk.test.ts @@ -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'; @@ -18,6 +17,14 @@ function getDefaultBrowserOptions(options: Partial = {}): 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 {