|
| 1 | +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; |
| 2 | +import type { CloudflareOptions } from '../../src/client'; |
| 3 | +import { getEffectiveRpcPropagation } from '../../src/utils/rpcOptions'; |
| 4 | + |
| 5 | +// Mock the debug module |
| 6 | +vi.mock('@sentry/core', async () => { |
| 7 | + const actual = await vi.importActual('@sentry/core'); |
| 8 | + return { |
| 9 | + ...actual, |
| 10 | + debug: { |
| 11 | + warn: vi.fn(), |
| 12 | + }, |
| 13 | + }; |
| 14 | +}); |
| 15 | + |
| 16 | +// Mock DEBUG_BUILD |
| 17 | +vi.mock('../../src/debug-build', () => ({ |
| 18 | + DEBUG_BUILD: true, |
| 19 | +})); |
| 20 | + |
| 21 | +import { debug } from '@sentry/core'; |
| 22 | + |
| 23 | +describe('getEffectiveRpcPropagation', () => { |
| 24 | + beforeEach(() => { |
| 25 | + vi.clearAllMocks(); |
| 26 | + }); |
| 27 | + |
| 28 | + afterEach(() => { |
| 29 | + vi.clearAllMocks(); |
| 30 | + }); |
| 31 | + |
| 32 | + it('returns false when neither option is set', () => { |
| 33 | + const options: CloudflareOptions = {}; |
| 34 | + expect(getEffectiveRpcPropagation(options)).toBe(false); |
| 35 | + }); |
| 36 | + |
| 37 | + it('returns enableRpcTracePropagation when only it is set (boolean true)', () => { |
| 38 | + const options: CloudflareOptions = { enableRpcTracePropagation: true }; |
| 39 | + expect(getEffectiveRpcPropagation(options)).toBe(true); |
| 40 | + }); |
| 41 | + |
| 42 | + it('returns enableRpcTracePropagation when only it is set (boolean false)', () => { |
| 43 | + const options: CloudflareOptions = { enableRpcTracePropagation: false }; |
| 44 | + expect(getEffectiveRpcPropagation(options)).toBe(false); |
| 45 | + }); |
| 46 | + |
| 47 | + it('returns true for instrumentPrototypeMethods when only it is set (with deprecation warning)', () => { |
| 48 | + const options: CloudflareOptions = { instrumentPrototypeMethods: true }; |
| 49 | + expect(getEffectiveRpcPropagation(options)).toBe(true); |
| 50 | + expect(debug.warn).toHaveBeenCalledWith(expect.stringContaining('`instrumentPrototypeMethods` is deprecated')); |
| 51 | + }); |
| 52 | + |
| 53 | + it('returns true for instrumentPrototypeMethods array when only it is set (with deprecation warning)', () => { |
| 54 | + const options: CloudflareOptions = { instrumentPrototypeMethods: ['myMethod'] }; |
| 55 | + expect(getEffectiveRpcPropagation(options)).toBe(true); |
| 56 | + expect(debug.warn).toHaveBeenCalledWith(expect.stringContaining('`instrumentPrototypeMethods` is deprecated')); |
| 57 | + }); |
| 58 | + |
| 59 | + it('returns false for empty instrumentPrototypeMethods array (with deprecation warning)', () => { |
| 60 | + const options: CloudflareOptions = { instrumentPrototypeMethods: [] }; |
| 61 | + expect(getEffectiveRpcPropagation(options)).toBe(false); |
| 62 | + expect(debug.warn).toHaveBeenCalledWith(expect.stringContaining('`instrumentPrototypeMethods` is deprecated')); |
| 63 | + }); |
| 64 | + |
| 65 | + it('prefers enableRpcTracePropagation over instrumentPrototypeMethods when both are set', () => { |
| 66 | + const options: CloudflareOptions = { |
| 67 | + enableRpcTracePropagation: true, |
| 68 | + instrumentPrototypeMethods: false, |
| 69 | + }; |
| 70 | + expect(getEffectiveRpcPropagation(options)).toBe(true); |
| 71 | + expect(debug.warn).toHaveBeenCalledWith( |
| 72 | + expect.stringContaining('Both `enableRpcTracePropagation` and `instrumentPrototypeMethods` are set'), |
| 73 | + ); |
| 74 | + }); |
| 75 | + |
| 76 | + it('prefers enableRpcTracePropagation (false) over instrumentPrototypeMethods (true) when both are set', () => { |
| 77 | + const options: CloudflareOptions = { |
| 78 | + enableRpcTracePropagation: false, |
| 79 | + instrumentPrototypeMethods: true, |
| 80 | + }; |
| 81 | + expect(getEffectiveRpcPropagation(options)).toBe(false); |
| 82 | + expect(debug.warn).toHaveBeenCalledWith( |
| 83 | + expect.stringContaining('Both `enableRpcTracePropagation` and `instrumentPrototypeMethods` are set'), |
| 84 | + ); |
| 85 | + }); |
| 86 | +}); |
0 commit comments