@@ -4,17 +4,16 @@ import * as trpc from '@trpc/server';
44import { observable } from '@trpc/server/observable' ;
55import { EventEmitter } from 'events' ;
66import { handleIPCMessage } from '../handleIPCMessage' ;
7- import { IpcMainInvokeEvent } from 'electron' ;
7+ import { IpcMainEvent } from 'electron' ;
88
99interface MockEvent {
10+ reply : MockedFunction < any > ;
1011 sender : {
1112 isDestroyed : ( ) => boolean ;
1213 on : ( event : string , cb : ( ) => void ) => void ;
13- send : MockedFunction < any > ;
1414 } ;
1515}
16- const makeEvent = ( event : MockEvent ) =>
17- event as unknown as IpcMainInvokeEvent & { sender : { send : MockedFunction < any > } } ;
16+ const makeEvent = ( event : MockEvent ) => event as unknown as IpcMainEvent & Pick < MockEvent , 'reply' > ;
1817
1918const ee = new EventEmitter ( ) ;
2019
@@ -44,10 +43,10 @@ const testRouter = t.router({
4443describe ( 'api' , ( ) => {
4544 test ( 'handles queries' , async ( ) => {
4645 const event = makeEvent ( {
46+ reply : vi . fn ( ) ,
4747 sender : {
4848 isDestroyed : ( ) => false ,
4949 on : ( ) => { } ,
50- send : vi . fn ( ) ,
5150 } ,
5251 } ) ;
5352
@@ -69,8 +68,8 @@ describe('api', () => {
6968 subscriptions : new Map ( ) ,
7069 } ) ;
7170
72- expect ( event . sender . send ) . toHaveBeenCalledOnce ( ) ;
73- expect ( event . sender . send . mock . lastCall [ 1 ] ) . toMatchObject ( {
71+ expect ( event . reply ) . toHaveBeenCalledOnce ( ) ;
72+ expect ( event . reply . mock . lastCall ! [ 1 ] ) . toMatchObject ( {
7473 id : 1 ,
7574 result : {
7675 data : {
@@ -83,10 +82,10 @@ describe('api', () => {
8382
8483 test ( 'does not respond if sender is gone' , async ( ) => {
8584 const event = makeEvent ( {
85+ reply : vi . fn ( ) ,
8686 sender : {
8787 isDestroyed : ( ) => true ,
8888 on : ( ) => { } ,
89- send : vi . fn ( ) ,
9089 } ,
9190 } ) ;
9291
@@ -108,15 +107,15 @@ describe('api', () => {
108107 subscriptions : new Map ( ) ,
109108 } ) ;
110109
111- expect ( event . sender . send ) . not . toHaveBeenCalled ( ) ;
110+ expect ( event . reply ) . not . toHaveBeenCalled ( ) ;
112111 } ) ;
113112
114113 test ( 'handles subscriptions' , async ( ) => {
115114 const event = makeEvent ( {
115+ reply : vi . fn ( ) ,
116116 sender : {
117117 isDestroyed : ( ) => false ,
118118 on : ( ) => { } ,
119- send : vi . fn ( ) ,
120119 } ,
121120 } ) ;
122121
@@ -138,12 +137,12 @@ describe('api', () => {
138137 event,
139138 } ) ;
140139
141- expect ( event . sender . send ) . not . toHaveBeenCalled ( ) ;
140+ expect ( event . reply ) . not . toHaveBeenCalled ( ) ;
142141
143142 ee . emit ( 'test' ) ;
144143
145- expect ( event . sender . send ) . toHaveBeenCalledOnce ( ) ;
146- expect ( event . sender . send . mock . lastCall [ 1 ] ) . toMatchObject ( {
144+ expect ( event . reply ) . toHaveBeenCalledOnce ( ) ;
145+ expect ( event . reply . mock . lastCall ! [ 1 ] ) . toMatchObject ( {
147146 id : 1 ,
148147 result : {
149148 data : 'test response' ,
@@ -153,10 +152,10 @@ describe('api', () => {
153152
154153 test ( 'subscription responds using custom serializer' , async ( ) => {
155154 const event = makeEvent ( {
155+ reply : vi . fn ( ) ,
156156 sender : {
157157 isDestroyed : ( ) => false ,
158158 on : ( ) => { } ,
159- send : vi . fn ( ) ,
160159 } ,
161160 } ) ;
162161
@@ -203,12 +202,12 @@ describe('api', () => {
203202 event,
204203 } ) ;
205204
206- expect ( event . sender . send ) . not . toHaveBeenCalled ( ) ;
205+ expect ( event . reply ) . not . toHaveBeenCalled ( ) ;
207206
208207 ee . emit ( 'test' ) ;
209208
210- expect ( event . sender . send ) . toHaveBeenCalledOnce ( ) ;
211- expect ( event . sender . send . mock . lastCall [ 1 ] ) . toMatchObject ( {
209+ expect ( event . reply ) . toHaveBeenCalledOnce ( ) ;
210+ expect ( event . reply . mock . lastCall ! [ 1 ] ) . toMatchObject ( {
212211 id : 1 ,
213212 result : {
214213 type : 'data' ,
0 commit comments