@@ -919,22 +919,25 @@ test.describe('analyzeTsFile', () => {
919919 } ) ;
920920
921921 test ( 'should detect events for all custom function signature variations' , ( ) => {
922+ const methodEventFile = path . join ( fixturesDir , 'typescript' , 'method-event.ts' ) ;
922923 const variants = [
923- { sig : 'customTrackFunction0' , event : 'custom_event0' } ,
924- { sig : 'customTrackFunction1(EVENT_NAME, PROPERTIES)' , event : 'custom_event1' } ,
925- { sig : 'customTrackFunction2(userId, EVENT_NAME, PROPERTIES)' , event : 'custom_event2' } ,
926- { sig : 'customTrackFunction3(EVENT_NAME, PROPERTIES, userEmail)' , event : 'custom_event3' } ,
927- { sig : 'customTrackFunction4(userId, EVENT_NAME, userAddress, PROPERTIES, userEmail)' , event : 'custom_event4' } ,
928- { sig : 'CustomModule.track(userId, EVENT_NAME, PROPERTIES)' , event : 'custom_module_event' } ,
929- { sig : 'customTrackFunction5' , event : 'FailedPayment' } ,
930- { sig : 'this.props.customTrackFunction6(EVENT_NAME, PROPERTIES)' , event : 'ViewedAttorneyAgreement' } ,
931- { sig : 'customTrackFunction7(EVENT_NAME, PROPERTIES)' , event : 'InitiatedPayment' } ,
924+ { sig : 'customTrackFunction0' , event : 'custom_event0' , file : testFilePath } ,
925+ { sig : 'customTrackFunction1(EVENT_NAME, PROPERTIES)' , event : 'custom_event1' , file : testFilePath } ,
926+ { sig : 'customTrackFunction2(userId, EVENT_NAME, PROPERTIES)' , event : 'custom_event2' , file : testFilePath } ,
927+ { sig : 'customTrackFunction3(EVENT_NAME, PROPERTIES, userEmail)' , event : 'custom_event3' , file : testFilePath } ,
928+ { sig : 'customTrackFunction4(userId, EVENT_NAME, userAddress, PROPERTIES, userEmail)' , event : 'custom_event4' , file : testFilePath } ,
929+ { sig : 'CustomModule.track(userId, EVENT_NAME, PROPERTIES)' , event : 'custom_module_event' , file : testFilePath } ,
930+ { sig : 'customTrackFunction5' , event : 'FailedPayment' , file : testFilePath } ,
931+ { sig : 'this.props.customTrackFunction6(EVENT_NAME, PROPERTIES)' , event : 'ViewedAttorneyAgreement' , file : testFilePath } ,
932+ { sig : 'customTrackFunction7(EVENT_NAME, PROPERTIES)' , event : 'InitiatedPayment' , file : testFilePath } ,
933+ // Method-as-event signature
934+ { sig : 'eventCalls.EVENT_NAME(PROPERTIES)' , event : 'viewItemList' , file : methodEventFile } ,
932935 ] ;
933936
934- variants . forEach ( ( { sig, event } ) => {
935- const program = createProgram ( testFilePath ) ;
937+ variants . forEach ( ( { sig, event, file } ) => {
938+ const program = createProgram ( file ) ;
936939 const customFunctionSignatures = [ parseCustomFunctionSignature ( sig ) ] ;
937- const events = analyzeTsFile ( testFilePath , program , customFunctionSignatures ) ;
940+ const events = analyzeTsFile ( file , program , customFunctionSignatures ) ;
938941 const found = events . find ( e => e . eventName === event && e . source === 'custom' ) ;
939942 assert . ok ( found , `Should detect ${ event } for signature ${ sig } ` ) ;
940943 } ) ;
@@ -980,6 +983,18 @@ test.describe('analyzeTsFile', () => {
980983 // Ensure built-in provider events remain unaffected
981984 const builtInCount = events . filter ( e => e . source !== 'custom' ) . length ;
982985 assert . ok ( builtInCount >= 10 , 'Should still include built-in provider events' ) ;
986+
987+ // Test method-as-event signature separately (different file)
988+ const methodEventFile = path . join ( fixturesDir , 'typescript' , 'method-event.ts' ) ;
989+ const methodProgram = createProgram ( methodEventFile ) ;
990+ const methodAsEventSignatures = [ parseCustomFunctionSignature ( 'eventCalls.EVENT_NAME(PROPERTIES)' ) ] ;
991+ const methodEvents = analyzeTsFile ( methodEventFile , methodProgram , methodAsEventSignatures ) ;
992+
993+ const methodEventNames = [ 'viewItemList' , 'addToCart' , 'removeFromCart' , 'beginCheckout' , 'purchase' , 'pageView' , 'complexOperation' ] ;
994+ methodEventNames . forEach ( eventName => {
995+ const evt = methodEvents . find ( e => e . eventName === eventName && e . source === 'custom' ) ;
996+ assert . ok ( evt , `Expected to find method-as-event ${ eventName } ` ) ;
997+ } ) ;
983998 } ) ;
984999
9851000 test ( 'should resolve constants imported via path alias from tsconfig' , ( ) => {
0 commit comments