import { trace } from '@opentelemetry/api' ; import { registerInstrumentations } from '@opentelemetry/instrumentation' ; import * as tracing from '@opentelemetry/sdk-trace-base' ; import { WebTracerProvider } from '@opentelemetry/sdk-trace-web' ; import { LongTaskInstrumentation } from '../src' ; import { DummySpanExporter } from './util' ; const _globalThis = typeof globalThis === 'object' ? globalThis : typeof self === 'object' ? self : typeof window === 'object' ? window : typeof global === 'object' ? global : ( { } as typeof globalThis ) ; describe ( "LongTaskInstrumentation doesn't throw in unsupported environments" , ( ) => { let webTracerProvider ; let dummySpanExporter ; before ( ( ) => { webTracerProvider = new WebTracerProvider ( ) ; dummySpanExporter = new DummySpanExporter ( ) ; webTracerProvider . addSpanProcessor ( new tracing . SimpleSpanProcessor ( dummySpanExporter ) ) ; webTracerProvider . register ( ) ; } ) ; after ( ( ) => { trace . disable ( ) ; } ) ; const perfObsDesc = Object . getOwnPropertyDescriptor ( _globalThis , 'PerformanceObserver' ) ; const supportedDesc = Object . getOwnPropertyDescriptor ( PerformanceObserver , 'supportedEntryTypes' ) ; afterEach ( ( ) => { Object . defineProperty ( _globalThis , 'PerformanceObserver' , perfObsDesc ! ) ; Object . defineProperty ( PerformanceObserver , 'supportedEntryTypes' , supportedDesc ! ) ; } ) ; it ( 'No support for PerformanceObserver' , async ( ) => { delete _globalThis . PerformanceObserver ; const longTaskInstrumentation = new LongTaskInstrumentation ( { enabled : false , } ) ; const deregister = registerInstrumentations ( { instrumentations : [ longTaskInstrumentation ] , } ) ; deregister ( ) ; } ) ; it ( 'No supportedEntryTypes' , async ( ) => { delete PerformanceObserver . supportedEntryTypes ; const longTaskInstrumentation = new LongTaskInstrumentation ( { enabled : false , } ) ; const deregister = registerInstrumentations ( { instrumentations : [ longTaskInstrumentation ] , } ) ; deregister ( ) ; } ) ; it ( 'longtask not supported' , async ( ) => { Object . defineProperty ( PerformanceObserver , 'supportedEntryTypes' , { get ( ) { return [ ] ; } , configurable : true , enumerable : false , } ) ; const longTaskInstrumentation = new LongTaskInstrumentation ( { enabled : false , } ) ; const deregister = registerInstrumentations ( { instrumentations : [ longTaskInstrumentation ] , } ) ; deregister ( ) ; } ) ; } ) ;