|
| 1 | +import { GLOBAL_OBJ } from '@sentry/core'; |
| 2 | +import { afterEach, beforeEach, describe, expect, it } from 'vitest'; |
| 3 | +import { isOrchestrionInjected } from '../../src/orchestrion/detect'; |
| 4 | + |
| 5 | +describe('isOrchestrionInjected', () => { |
| 6 | + beforeEach(() => { |
| 7 | + delete GLOBAL_OBJ.__SENTRY_ORCHESTRION__; |
| 8 | + }); |
| 9 | + |
| 10 | + afterEach(() => { |
| 11 | + delete GLOBAL_OBJ.__SENTRY_ORCHESTRION__; |
| 12 | + }); |
| 13 | + |
| 14 | + it('is false when no marker exists', () => { |
| 15 | + expect(isOrchestrionInjected()).toBe(false); |
| 16 | + }); |
| 17 | + |
| 18 | + it.each([ |
| 19 | + ['runtime', { runtime: [] }], |
| 20 | + ['bundler array', { bundler: ['mysql'] }], |
| 21 | + ['bundler true', { bundler: true }], |
| 22 | + ['integrations', { integrations: new Map() }], |
| 23 | + ] as const)('is true when %s injection is present', (_label, marker) => { |
| 24 | + // Cast through `unknown`: rows are `as const` (readonly) and `bundler: true` |
| 25 | + // is a valid runtime shape the marker type doesn't spell out. |
| 26 | + GLOBAL_OBJ.__SENTRY_ORCHESTRION__ = marker as unknown as typeof GLOBAL_OBJ.__SENTRY_ORCHESTRION__; |
| 27 | + expect(isOrchestrionInjected()).toBe(true); |
| 28 | + }); |
| 29 | + |
| 30 | + // The bridge is installed before hook registration succeeds, so a marker |
| 31 | + // carrying only `onInject` means nothing will publish channels. Opt-in paths |
| 32 | + // (knex, dataloader, Nest) must still fall back to OTel in that case. |
| 33 | + it('is false when only the on-inject bridge is installed', () => { |
| 34 | + GLOBAL_OBJ.__SENTRY_ORCHESTRION__ = { onInject: () => {} }; |
| 35 | + expect(isOrchestrionInjected()).toBe(false); |
| 36 | + }); |
| 37 | +}); |
0 commit comments