@@ -16,9 +16,11 @@ import type {
16
16
EmailEvent ,
17
17
QueueEvent ,
18
18
RequestEvent ,
19
+ RpcEvent ,
19
20
ScheduledEvent ,
20
21
TailEvent ,
21
22
TailEventMessage ,
23
+ TailEventMessageType ,
22
24
TailInfo ,
23
25
} from "../tail/createTail" ;
24
26
import type { RequestInit } from "undici" ;
@@ -91,6 +93,7 @@ describe("tail", () => {
91
93
await api . closeHelper ( ) ;
92
94
expect ( api . requests . deletion . count ) . toStrictEqual ( 1 ) ;
93
95
} ) ;
96
+
94
97
it ( "should connect to the worker assigned to a given route" , async ( ) => {
95
98
api = mockWebsocketAPIs ( ) ;
96
99
expect ( api . requests . creation . length ) . toStrictEqual ( 0 ) ;
@@ -532,6 +535,33 @@ describe("tail", () => {
532
535
await api . closeHelper ( ) ;
533
536
} ) ;
534
537
538
+ it ( "logs rpc messages in pretty format" , async ( ) => {
539
+ api = mockWebsocketAPIs ( ) ;
540
+ await runWrangler ( "tail test-worker --format pretty" ) ;
541
+
542
+ const event = generateMockRpcEvent ( ) ;
543
+ const message = generateMockEventMessage ( {
544
+ entrypoint : "MyDurableObject" ,
545
+ event,
546
+ } ) ;
547
+ const serializedMessage = serialize ( message ) ;
548
+
549
+ api . ws . send ( serializedMessage ) ;
550
+ expect (
551
+ std . out
552
+ . replace (
553
+ new Date ( mockEventTimestamp ) . toLocaleString ( ) ,
554
+ "[mock event timestamp]"
555
+ )
556
+ . replace ( mockTailExpiration . toISOString ( ) , "[mock expiration date]" )
557
+ ) . toMatchInlineSnapshot ( `
558
+ "Successfully created tail, expires at [mock expiration date]
559
+ Connected to test-worker, waiting for logs...
560
+ MyDurableObject.foo - Ok @ [mock event timestamp]"
561
+ ` ) ;
562
+ await api . closeHelper ( ) ;
563
+ } ) ;
564
+
535
565
it ( "logs scheduled messages in pretty format" , async ( ) => {
536
566
api = mockWebsocketAPIs ( ) ;
537
567
await runWrangler ( "tail test-worker --format pretty" ) ;
@@ -908,18 +938,7 @@ function serialize(message: TailEventMessage): WebSocket.RawData {
908
938
* @param event A TailEvent
909
939
* @returns true if `event` is a RequestEvent
910
940
*/
911
- function isRequest (
912
- event :
913
- | ScheduledEvent
914
- | RequestEvent
915
- | AlarmEvent
916
- | EmailEvent
917
- | TailEvent
918
- | TailInfo
919
- | QueueEvent
920
- | undefined
921
- | null
922
- ) : event is RequestEvent {
941
+ function isRequest ( event : TailEventMessageType ) : event is RequestEvent {
923
942
return Boolean ( event && "request" in event ) ;
924
943
}
925
944
@@ -1133,13 +1152,15 @@ function mockWebsocketAPIs(
1133
1152
*/
1134
1153
function generateMockEventMessage ( {
1135
1154
outcome = "ok" ,
1155
+ entrypoint = undefined ,
1136
1156
exceptions = [ ] ,
1137
1157
logs = [ ] ,
1138
1158
eventTimestamp = mockEventTimestamp ,
1139
1159
event = generateMockRequestEvent ( ) ,
1140
1160
} : Partial < TailEventMessage > ) : TailEventMessage {
1141
1161
return {
1142
1162
outcome,
1163
+ entrypoint,
1143
1164
exceptions,
1144
1165
logs,
1145
1166
eventTimestamp,
@@ -1229,3 +1250,9 @@ function generateMockQueueEvent(opts?: Partial<QueueEvent>): QueueEvent {
1229
1250
batchSize : opts ?. batchSize || 7 ,
1230
1251
} ;
1231
1252
}
1253
+
1254
+ function generateMockRpcEvent ( opts ?: Partial < RpcEvent > ) : RpcEvent {
1255
+ return {
1256
+ rpcMethod : opts ?. rpcMethod || "foo" ,
1257
+ } ;
1258
+ }
0 commit comments