@@ -4,17 +4,16 @@ import * as trpc from '@trpc/server';
4
4
import { observable } from '@trpc/server/observable' ;
5
5
import { EventEmitter } from 'events' ;
6
6
import { handleIPCMessage } from '../handleIPCMessage' ;
7
- import { IpcMainInvokeEvent } from 'electron' ;
7
+ import { IpcMainEvent } from 'electron' ;
8
8
9
9
interface MockEvent {
10
+ reply : MockedFunction < any > ;
10
11
sender : {
11
12
isDestroyed : ( ) => boolean ;
12
13
on : ( event : string , cb : ( ) => void ) => void ;
13
- send : MockedFunction < any > ;
14
14
} ;
15
15
}
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' > ;
18
17
19
18
const ee = new EventEmitter ( ) ;
20
19
@@ -44,10 +43,10 @@ const testRouter = t.router({
44
43
describe ( 'api' , ( ) => {
45
44
test ( 'handles queries' , async ( ) => {
46
45
const event = makeEvent ( {
46
+ reply : vi . fn ( ) ,
47
47
sender : {
48
48
isDestroyed : ( ) => false ,
49
49
on : ( ) => { } ,
50
- send : vi . fn ( ) ,
51
50
} ,
52
51
} ) ;
53
52
@@ -69,8 +68,8 @@ describe('api', () => {
69
68
subscriptions : new Map ( ) ,
70
69
} ) ;
71
70
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 ( {
74
73
id : 1 ,
75
74
result : {
76
75
data : {
@@ -83,10 +82,10 @@ describe('api', () => {
83
82
84
83
test ( 'does not respond if sender is gone' , async ( ) => {
85
84
const event = makeEvent ( {
85
+ reply : vi . fn ( ) ,
86
86
sender : {
87
87
isDestroyed : ( ) => true ,
88
88
on : ( ) => { } ,
89
- send : vi . fn ( ) ,
90
89
} ,
91
90
} ) ;
92
91
@@ -108,15 +107,15 @@ describe('api', () => {
108
107
subscriptions : new Map ( ) ,
109
108
} ) ;
110
109
111
- expect ( event . sender . send ) . not . toHaveBeenCalled ( ) ;
110
+ expect ( event . reply ) . not . toHaveBeenCalled ( ) ;
112
111
} ) ;
113
112
114
113
test ( 'handles subscriptions' , async ( ) => {
115
114
const event = makeEvent ( {
115
+ reply : vi . fn ( ) ,
116
116
sender : {
117
117
isDestroyed : ( ) => false ,
118
118
on : ( ) => { } ,
119
- send : vi . fn ( ) ,
120
119
} ,
121
120
} ) ;
122
121
@@ -138,12 +137,12 @@ describe('api', () => {
138
137
event,
139
138
} ) ;
140
139
141
- expect ( event . sender . send ) . not . toHaveBeenCalled ( ) ;
140
+ expect ( event . reply ) . not . toHaveBeenCalled ( ) ;
142
141
143
142
ee . emit ( 'test' ) ;
144
143
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 ( {
147
146
id : 1 ,
148
147
result : {
149
148
data : 'test response' ,
@@ -153,10 +152,10 @@ describe('api', () => {
153
152
154
153
test ( 'subscription responds using custom serializer' , async ( ) => {
155
154
const event = makeEvent ( {
155
+ reply : vi . fn ( ) ,
156
156
sender : {
157
157
isDestroyed : ( ) => false ,
158
158
on : ( ) => { } ,
159
- send : vi . fn ( ) ,
160
159
} ,
161
160
} ) ;
162
161
@@ -203,12 +202,12 @@ describe('api', () => {
203
202
event,
204
203
} ) ;
205
204
206
- expect ( event . sender . send ) . not . toHaveBeenCalled ( ) ;
205
+ expect ( event . reply ) . not . toHaveBeenCalled ( ) ;
207
206
208
207
ee . emit ( 'test' ) ;
209
208
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 ( {
212
211
id : 1 ,
213
212
result : {
214
213
type : 'data' ,
0 commit comments