|
1 | 1 | import type { AsyncContextStrategy } from '@sentry/core'; |
2 | | -import { GLOBAL_OBJ, setAsyncContextStrategy } from '@sentry/core'; |
| 2 | +import { debug, GLOBAL_OBJ, setAsyncContextStrategy } from '@sentry/core'; |
3 | 3 | import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; |
4 | 4 | import { invokeOrchestrionInstrumentation } from '../../src/orchestrion/instrumentation'; |
5 | 5 |
|
@@ -190,4 +190,43 @@ describe('invokeOrchestrionInstrumentation', () => { |
190 | 190 | expect(callback).not.toHaveBeenCalled(); |
191 | 191 | expect(client.listenerCount()).toBe(1); |
192 | 192 | }); |
| 193 | + |
| 194 | + describe('on Cloudflare', () => { |
| 195 | + beforeEach(() => { |
| 196 | + vi.stubGlobal('navigator', { userAgent: 'Cloudflare-Workers' }); |
| 197 | + }); |
| 198 | + |
| 199 | + afterEach(() => { |
| 200 | + vi.unstubAllGlobals(); |
| 201 | + vi.restoreAllMocks(); |
| 202 | + }); |
| 203 | + |
| 204 | + it('warns once when the vite plugin did not run', () => { |
| 205 | + const warn = vi.spyOn(debug, 'warn').mockImplementation(() => undefined); |
| 206 | + |
| 207 | + invokeOrchestrionInstrumentation(makeClient() as never, ['openai'], vi.fn(), []); |
| 208 | + invokeOrchestrionInstrumentation(makeClient() as never, ['openai'], vi.fn(), []); |
| 209 | + |
| 210 | + expect(warn).toHaveBeenCalledTimes(1); |
| 211 | + expect(warn).toHaveBeenCalledWith(expect.stringContaining('`@sentry/cloudflare/vite` plugin did not run')); |
| 212 | + }); |
| 213 | + |
| 214 | + it('does not warn when the vite plugin ran, even before any module loaded', () => { |
| 215 | + GLOBAL_OBJ.__SENTRY_ORCHESTRION__ = { bundler: new Set() }; |
| 216 | + const warn = vi.spyOn(debug, 'warn').mockImplementation(() => undefined); |
| 217 | + |
| 218 | + invokeOrchestrionInstrumentation(makeClient() as never, ['pg'], vi.fn(), []); |
| 219 | + |
| 220 | + expect(warn).not.toHaveBeenCalled(); |
| 221 | + }); |
| 222 | + }); |
| 223 | + |
| 224 | + it('does not warn about the Cloudflare plugin on other runtimes', () => { |
| 225 | + const warn = vi.spyOn(debug, 'warn').mockImplementation(() => undefined); |
| 226 | + |
| 227 | + invokeOrchestrionInstrumentation(makeClient() as never, ['redis'], vi.fn(), []); |
| 228 | + |
| 229 | + expect(warn).not.toHaveBeenCalled(); |
| 230 | + warn.mockRestore(); |
| 231 | + }); |
193 | 232 | }); |
0 commit comments