@@ -312,7 +312,7 @@ describe('Class: PowertoolsLogFormatter', () => {
312
312
} ) ;
313
313
314
314
describe ( 'Method: getCodeLocation' , ( ) => {
315
- test ( 'when the stack IS present, it returns a datetime value ISO 8601 compliant ' , ( ) => {
315
+ test ( 'when the stack IS present, it returns a location for a stackframe with absolute file path ' , ( ) => {
316
316
// Prepare
317
317
const formatter = new PowertoolsLogFormatter ( ) ;
318
318
const stack =
@@ -327,7 +327,71 @@ describe('Class: PowertoolsLogFormatter', () => {
327
327
expect ( errorLocation ) . toEqual ( '/home/foo/bar/some-file.ts:154' ) ;
328
328
} ) ;
329
329
330
- test ( 'when the stack IS NOT present, it returns a datetime value ISO 8601 compliant' , ( ) => {
330
+ test ( 'when the stack IS present, it returns a location for a stackframe ending with an optional backslash' , ( ) => {
331
+ // Prepare
332
+ const formatter = new PowertoolsLogFormatter ( ) ;
333
+ const stack =
334
+ 'Error: Things keep happening!\n' +
335
+ ' at /home/foo/bar/file-that-threw-the-error.ts:22:5\n' +
336
+ ' at SomeOther.function (/home/foo/bar/some-file.ts:154:19)\\' ;
337
+
338
+ // Act
339
+ const errorLocation = formatter . getCodeLocation ( stack ) ;
340
+
341
+ // Assess
342
+ expect ( errorLocation ) . toEqual ( '/home/foo/bar/some-file.ts:154' ) ;
343
+ } ) ;
344
+ test ( 'when the stack IS present, it returns a location for a path containing multiple colons' , ( ) => {
345
+ // Prepare
346
+ const formatter = new PowertoolsLogFormatter ( ) ;
347
+ const stack =
348
+ 'Error: The message failed to send\n' +
349
+ 'at REPL2:1:17\n' +
350
+ 'at Script.runInThisContext (node:vm:130:12)\n' +
351
+ '... 7 lines matching cause stack trace ...\n' +
352
+ 'at [_line] [as _line] (node:internal/readline/interface:886:18) {\n' +
353
+ '[cause]: Error: The remote HTTP server responded with a 500 status\n' +
354
+ ' at REPL1:1:15\n' +
355
+ ' at Script.runInThisContext (node:vm:130:12)\n' +
356
+ ' at REPLServer.defaultEval (node:repl:574:29)\n' +
357
+ ' at bound (node:domain:426:15)\n' +
358
+ ' at REPLServer.runBound [as eval] (node:domain:437:12)\n' +
359
+ ' at REPLServer.onLine (node:repl:902:10)\n' +
360
+ ' at REPLServer.emit (node:events:549:35)\n' +
361
+ ' at REPLServer.emit (node:domain:482:12)\n' +
362
+ ' at [_onLine] [as _onLine] (node:internal/readline/interface:425:12)\n' +
363
+ ' at [_line] [as _line] (node:internal/readline/interface:886:18) \n' ;
364
+
365
+ // Act
366
+ const errorLocation = formatter . getCodeLocation ( stack ) ;
367
+
368
+ // Assess
369
+ expect ( errorLocation ) . toEqual ( 'node:vm:130' ) ;
370
+ } ) ;
371
+
372
+ test ( 'when the stack IS present, it returns a location for a nested path' , ( ) => {
373
+ // Prepare
374
+
375
+ const formatter = new PowertoolsLogFormatter ( ) ;
376
+ const stack =
377
+ 'Error: unknown\n' +
378
+ 'at eval (eval at <anonymous> (file:///home/foo/bar/some-file.ts:1:35), <anonymous>:1:7)\n' +
379
+ 'at <anonymous> (/home/foo/bar/file-that-threw-the-error.ts:52:3)\n' +
380
+ 'at ModuleJob.run (node:internal/modules/esm/module_job:218:25)\n' +
381
+ 'at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)\n' +
382
+ 'at async loadESM (node:internal/process/esm_loader:28:7)\n' +
383
+ 'at async handleMainPromise (node:internal/modules/run_main:113:12)\n' ;
384
+
385
+ // Act
386
+ const errorLocation = formatter . getCodeLocation ( stack ) ;
387
+
388
+ // Assess
389
+ expect ( errorLocation ) . toEqual (
390
+ '/home/foo/bar/file-that-threw-the-error.ts:52'
391
+ ) ;
392
+ } ) ;
393
+
394
+ test ( 'when the stack IS NOT present, it returns an empty location' , ( ) => {
331
395
// Prepare
332
396
const formatter = new PowertoolsLogFormatter ( ) ;
333
397
const stack = undefined ;
@@ -339,7 +403,7 @@ describe('Class: PowertoolsLogFormatter', () => {
339
403
expect ( errorLocation ) . toEqual ( '' ) ;
340
404
} ) ;
341
405
342
- test ( 'when the stack IS NOT present, it returns a datetime value ISO 8601 compliant ' , ( ) => {
406
+ test ( 'when the stack IS present, if a stackframe does not have a location, it returns an empty location ' , ( ) => {
343
407
// Prepare
344
408
const formatter = new PowertoolsLogFormatter ( ) ;
345
409
const stack = 'A weird stack trace...' ;
0 commit comments