@@ -293,6 +293,55 @@ describe("tail", () => {
293
293
` ) ;
294
294
} ) ;
295
295
296
+ it ( "logs console messages and exceptions" , async ( ) => {
297
+ const api = mockWebsocketAPIs ( ) ;
298
+ await runWrangler ( "tail test-worker" ) ;
299
+
300
+ const event = generateMockRequestEvent ( ) ;
301
+ const message = generateMockEventMessage ( {
302
+ event,
303
+ logs : [
304
+ { message : [ "some string" ] , level : "log" , timestamp : 1234561 } ,
305
+ {
306
+ message : [ { complex : "object" } ] ,
307
+ level : "log" ,
308
+ timestamp : 1234562 ,
309
+ } ,
310
+ { message : [ 1234 ] , level : "error" , timestamp : 1234563 } ,
311
+ ] ,
312
+ exceptions : [
313
+ { name : "Error" , message : "some error" , timestamp : 1234564 } ,
314
+ { name : "Error" , message : { complex : "error" } , timestamp : 1234564 } ,
315
+ ] ,
316
+ } ) ;
317
+ const serializedMessage = serialize ( message ) ;
318
+
319
+ api . ws . send ( serializedMessage ) ;
320
+ expect (
321
+ std . out
322
+ . replace (
323
+ new Date ( mockEventTimestamp ) . toLocaleString ( ) ,
324
+ "[mock event timestamp]"
325
+ )
326
+ . replace (
327
+ mockTailExpiration . toLocaleString ( ) ,
328
+ "[mock expiration date]"
329
+ )
330
+ ) . toMatchInlineSnapshot ( `
331
+ "successfully created tail, expires at [mock expiration date]
332
+ Connected to test-worker, waiting for logs...
333
+ GET https://example.org/ - Ok @ [mock event timestamp]
334
+ (log) some string
335
+ (log) { complex: 'object' }
336
+ (error) 1234"
337
+ ` ) ;
338
+ expect ( std . err ) . toMatchInlineSnapshot ( `
339
+ " Error: some error
340
+ Error: { complex: 'error' }"
341
+ ` ) ;
342
+ expect ( std . warn ) . toMatchInlineSnapshot ( `""` ) ;
343
+ } ) ;
344
+
296
345
it ( "logs scheduled messages in pretty format" , async ( ) => {
297
346
const api = mockWebsocketAPIs ( ) ;
298
347
await runWrangler ( "tail test-worker --format pretty" ) ;
0 commit comments