@@ -375,23 +375,6 @@ describe("ResultFormatter", () => {
375375 expect ( testResult . getResult ( ) ) . toEqual ( complexData ) ;
376376 } ) ;
377377
378- it ( "should throw Error when error object is not found for failed execution" , ( ) => {
379- const lambdaResponse : TestExecutionResult = {
380- status : ExecutionStatus . FAILED ,
381- result : JSON . stringify ( { error : "" } ) ,
382- } ;
383-
384- const testResult = resultFormatter . formatTestResult (
385- lambdaResponse ,
386- [ ] ,
387- mockOperationStorage ,
388- ) ;
389-
390- expect ( ( ) => testResult . getResult ( ) ) . toThrow (
391- "Could not find error result" ,
392- ) ;
393- } ) ;
394-
395378 it ( "should not clean stack trace if error had no stack trace" , ( ) => {
396379 const lambdaResponse : TestExecutionResult = {
397380 status : ExecutionStatus . FAILED ,
@@ -411,12 +394,12 @@ describe("ResultFormatter", () => {
411394 thrownError = error as Error ;
412395 }
413396 expect ( thrownError ! . stack ) . toBeDefined ( ) ;
414- expect ( thrownError ! . stack ) . toContain ( "ResultFormatter " ) ;
397+ expect ( thrownError ! . stack ) . toContain ( "result-formatter.ts " ) ;
415398 } ) ;
416399 } ) ;
417400
418401 describe ( "getError behavior" , ( ) => {
419- it ( "should not return ErrorObject for failed invocation if error object is missing" , ( ) => {
402+ it ( "should return generic error when error object is missing" , ( ) => {
420403 const mockError = "Handler execution failed" ;
421404
422405 const lambdaResponse : TestExecutionResult = {
@@ -430,9 +413,13 @@ describe("ResultFormatter", () => {
430413 mockOperationStorage ,
431414 ) ;
432415
433- expect ( ( ) => testResult . getError ( ) ) . toThrow (
434- "Could not find error result" ,
435- ) ;
416+ const error = testResult . getError ( ) ;
417+ expect ( error ) . toEqual ( {
418+ errorMessage : 'Execution failed with status "FAILED"' ,
419+ errorData : undefined ,
420+ errorType : undefined ,
421+ stackTrace : undefined ,
422+ } ) ;
436423 } ) ;
437424
438425 it ( "should throw error when called on successful execution" , ( ) => {
@@ -452,40 +439,6 @@ describe("ResultFormatter", () => {
452439 ) ;
453440 } ) ;
454441
455- it ( "should throw error when parsing fails" , ( ) => {
456- const lambdaResponse : TestExecutionResult = {
457- status : ExecutionStatus . FAILED ,
458- result : "Raw error message - not JSON" ,
459- } ;
460-
461- const testResult = resultFormatter . formatTestResult (
462- lambdaResponse ,
463- [ ] ,
464- mockOperationStorage ,
465- ) ;
466-
467- expect ( ( ) => testResult . getError ( ) ) . toThrow (
468- "Could not find error result" ,
469- ) ;
470- } ) ;
471-
472- it ( "should throw error when error field is not a string" , ( ) => {
473- const lambdaResponse : TestExecutionResult = {
474- status : ExecutionStatus . FAILED ,
475- result : JSON . stringify ( { error : { nested : "object" } } ) ,
476- } ;
477-
478- const testResult = resultFormatter . formatTestResult (
479- lambdaResponse ,
480- [ ] ,
481- mockOperationStorage ,
482- ) ;
483-
484- expect ( ( ) => testResult . getError ( ) ) . toThrow (
485- "Could not find error result" ,
486- ) ;
487- } ) ;
488-
489442 it ( "should return ErrorObject when error object is specified" , ( ) => {
490443 const lambdaResponse : TestExecutionResult = {
491444 status : ExecutionStatus . FAILED ,
@@ -672,5 +625,27 @@ describe("ResultFormatter", () => {
672625 stackTrace : [ "stack line 1" , "stack line 2" ] ,
673626 } ) ;
674627 } ) ;
628+
629+ it ( "should return timeout error when status is TIMED_OUT and no error data exists" , ( ) => {
630+ const lambdaResponse : TestExecutionResult = {
631+ status : ExecutionStatus . TIMED_OUT ,
632+ result : JSON . stringify ( { someField : "value" } ) ,
633+ // No error property - testing the TIMED_OUT specific case
634+ } ;
635+
636+ const testResult = resultFormatter . formatTestResult (
637+ lambdaResponse ,
638+ [ ] ,
639+ mockOperationStorage ,
640+ ) ;
641+
642+ const error = testResult . getError ( ) ;
643+ expect ( error ) . toEqual ( {
644+ errorMessage : `Execution failed with status "TIMED_OUT"` ,
645+ errorData : undefined ,
646+ errorType : undefined ,
647+ stackTrace : undefined ,
648+ } ) ;
649+ } ) ;
675650 } ) ;
676651} ) ;
0 commit comments