@@ -69,28 +69,28 @@ const assertValidMeasurements = (measurement: RawThreadCpuProfile['measurements'
6969
7070describe ( 'Private bindings' , ( ) => {
7171 it ( 'does not crash if collect resources is false' , async ( ) => {
72- PrivateCpuProfilerBindings . startProfiling ( 'profiled-program' ) ;
72+ PrivateCpuProfilerBindings . startProfiling ! ( 'profiled-program' ) ;
7373 await wait ( 100 ) ;
7474 expect ( ( ) => {
75- const profile = PrivateCpuProfilerBindings . stopProfiling ( 'profiled-program' , 0 , 0 , false ) ;
75+ const profile = PrivateCpuProfilerBindings . stopProfiling ! ( 'profiled-program' , 0 , 0 , false ) ;
7676 if ( ! profile ) throw new Error ( 'No profile' ) ;
7777 } ) . not . toThrow ( ) ;
7878 } ) ;
7979
8080 it ( 'throws if invalid format is supplied' , async ( ) => {
81- PrivateCpuProfilerBindings . startProfiling ( 'profiled-program' ) ;
81+ PrivateCpuProfilerBindings . startProfiling ! ( 'profiled-program' ) ;
8282 await wait ( 100 ) ;
8383 expect ( ( ) => {
84- const profile = PrivateCpuProfilerBindings . stopProfiling ( 'profiled-program' , Number . MAX_SAFE_INTEGER , 0 , false ) ;
84+ const profile = PrivateCpuProfilerBindings . stopProfiling ! ( 'profiled-program' , Number . MAX_SAFE_INTEGER , 0 , false ) ;
8585 if ( ! profile ) throw new Error ( 'No profile' ) ;
8686 } ) . toThrow ( 'StopProfiling expects a valid format type as second argument.' ) ;
8787 } ) ;
8888
8989 it ( 'collects resources' , async ( ) => {
90- PrivateCpuProfilerBindings . startProfiling ( 'profiled-program' ) ;
90+ PrivateCpuProfilerBindings . startProfiling ! ( 'profiled-program' ) ;
9191 await wait ( 100 ) ;
9292
93- const profile = PrivateCpuProfilerBindings . stopProfiling ( 'profiled-program' , 0 , 0 , true ) ;
93+ const profile = PrivateCpuProfilerBindings . stopProfiling ! ( 'profiled-program' , 0 , 0 , true ) ;
9494 if ( ! profile ) throw new Error ( 'No profile' ) ;
9595
9696 expect ( profile . resources . length ) . toBeGreaterThan ( 0 ) ;
@@ -104,10 +104,10 @@ describe('Private bindings', () => {
104104 } ) ;
105105
106106 it ( 'does not collect resources' , async ( ) => {
107- PrivateCpuProfilerBindings . startProfiling ( 'profiled-program' ) ;
107+ PrivateCpuProfilerBindings . startProfiling ! ( 'profiled-program' ) ;
108108 await wait ( 100 ) ;
109109
110- const profile = PrivateCpuProfilerBindings . stopProfiling ( 'profiled-program' , 0 , 0 , false ) ;
110+ const profile = PrivateCpuProfilerBindings . stopProfiling ! ( 'profiled-program' , 0 , 0 , false ) ;
111111 if ( ! profile ) throw new Error ( 'No profile' ) ;
112112
113113 expect ( profile . resources . length ) . toBe ( 0 ) ;
@@ -337,4 +337,27 @@ describe('Profiler bindings', () => {
337337 const hasDeoptimizedFrame = profile . frames . some ( f => f . deopt_reasons && f . deopt_reasons . length > 0 ) ;
338338 expect ( hasDeoptimizedFrame ) . toBe ( true ) ;
339339 } ) ;
340+
341+ it ( 'does not crash if the native startProfiling function is not available' , async ( ) => {
342+ const original = PrivateCpuProfilerBindings . startProfiling ;
343+ PrivateCpuProfilerBindings . startProfiling = undefined ;
344+
345+ expect ( ( ) => {
346+ CpuProfilerBindings . startProfiling ( 'profiled-program' ) ;
347+ } ) . not . toThrow ( ) ;
348+
349+ PrivateCpuProfilerBindings . startProfiling = original ;
350+ } ) ;
351+
352+ it ( 'does not crash if the native stopProfiling function is not available' , async ( ) => {
353+ // eslint-disable-next-line @typescript-eslint/unbound-method
354+ const original = PrivateCpuProfilerBindings . stopProfiling ;
355+ PrivateCpuProfilerBindings . stopProfiling = undefined ;
356+
357+ expect ( ( ) => {
358+ CpuProfilerBindings . stopProfiling ( 'profiled-program' , 0 ) ;
359+ } ) . not . toThrow ( ) ;
360+
361+ PrivateCpuProfilerBindings . stopProfiling = original ;
362+ } ) ;
340363} ) ;
0 commit comments