@@ -28,7 +28,7 @@ import type { ProcessExitData } from './processHost';
2828import type { TestGroup } from './testGroups' ;
2929import type { TestError , TestResult , TestStep } from '../../types/testReporter' ;
3030import type { FullConfigInternal } from '../common/config' ;
31- import type { AttachmentPayload , DonePayload , RunPayload , SerializedConfig , StepBeginPayload , StepEndPayload , TeardownErrorsPayload , TestBeginPayload , TestEndPayload , TestOutputPayload , TestPausedPayload } from '../common/ipc' ;
31+ import type { AttachmentPayload , DonePayload , RunPayload , SerializedConfig , StepBeginPayload , StepEndPayload , TeardownErrorsPayload , TestBeginPayload , TestEndPayload , TestErrorsPayload , TestOutputPayload , TestPausedPayload } from '../common/ipc' ;
3232import type { Suite } from '../common/test' ;
3333import type { TestCase } from '../common/test' ;
3434import type { ReporterV2 } from '../reporters/reporterV2' ;
@@ -322,7 +322,6 @@ class JobDispatcher {
322322 // Do not show more than one error to avoid confusion, but report
323323 // as interrupted to indicate that we did actually start the test.
324324 params . status = 'interrupted' ;
325- params . errors = [ ] ;
326325 }
327326 const data = this . _dataByTestId . get ( params . testId ) ;
328327 if ( ! data ) {
@@ -333,8 +332,6 @@ class JobDispatcher {
333332 this . _remainingByTestId . delete ( params . testId ) ;
334333 const { result, test } = data ;
335334 result . duration = params . duration ;
336- result . errors = params . errors ;
337- result . error = result . errors [ 0 ] ;
338335 result . status = params . status ;
339336 result . annotations = params . annotations ;
340337 test . annotations = [ ...params . annotations ] ; // last test result wins
@@ -429,6 +426,23 @@ class JobDispatcher {
429426 }
430427 }
431428
429+ private _onTestErrors ( params : TestErrorsPayload ) {
430+ if ( this . _failureTracker . hasReachedMaxFailures ( ) ) {
431+ // Do not show more than one error to avoid confusion.
432+ return ;
433+ }
434+
435+ const data = this . _dataByTestId . get ( params . testId ) ! ;
436+ if ( ! data )
437+ return ;
438+ const { test, result } = data ;
439+ for ( const error of params . errors ) {
440+ result . errors . push ( error ) ;
441+ result . error = result . errors [ 0 ] ;
442+ this . _reporter . onTestError ?.( test , result , error ) ;
443+ }
444+ }
445+
432446 private _failTestWithErrors ( test : TestCase , errors : TestError [ ] ) {
433447 const runData = this . _dataByTestId . get ( test . id ) ;
434448 // There might be a single test that has started but has not finished yet.
@@ -439,8 +453,11 @@ class JobDispatcher {
439453 result = test . _appendTestResult ( ) ;
440454 this . _reporter . onTestBegin ?.( test , result ) ;
441455 }
442- result . errors = [ ...errors ] ;
443- result . error = result . errors [ 0 ] ;
456+ for ( const error of errors ) {
457+ result . errors . push ( error ) ;
458+ result . error = result . errors [ 0 ] ;
459+ this . _reporter . onTestError ?.( test , result , error ) ;
460+ }
444461 result . status = errors . length ? 'failed' : 'skipped' ;
445462 this . _reportTestEnd ( test , result ) ;
446463 this . _failedTests . add ( test ) ;
@@ -578,31 +595,36 @@ class JobDispatcher {
578595 eventsHelper . addEventListener ( worker , 'stepBegin' , this . _onStepBegin . bind ( this ) ) ,
579596 eventsHelper . addEventListener ( worker , 'stepEnd' , this . _onStepEnd . bind ( this ) ) ,
580597 eventsHelper . addEventListener ( worker , 'attach' , this . _onAttach . bind ( this ) ) ,
598+ eventsHelper . addEventListener ( worker , 'testErrors' , this . _onTestErrors . bind ( this ) ) ,
581599 eventsHelper . addEventListener ( worker , 'testPaused' , this . _onTestPaused . bind ( this , worker ) ) ,
582600 eventsHelper . addEventListener ( worker , 'done' , this . _onDone . bind ( this ) ) ,
583601 eventsHelper . addEventListener ( worker , 'exit' , this . onExit . bind ( this ) ) ,
584602 ] ;
585603 }
586604
587605 private _onTestPaused ( worker : WorkerHost , params : TestPausedPayload ) {
606+ const data = this . _dataByTestId . get ( params . testId ) ;
607+ if ( ! data )
608+ return ;
609+
610+ const { test, result } = data ;
611+
588612 const sendMessage = async ( message : { request : any } ) => {
589613 try {
590614 if ( this . jobResult . isDone ( ) )
591615 throw new Error ( 'Test has already stopped' ) ;
592616 const response = await worker . sendCustomMessage ( { testId : params . testId , request : message . request } ) ;
593617 if ( response . error )
594- addLocationAndSnippetToError ( this . _config . config , response . error ) ;
618+ addLocationAndSnippetToError ( this . _config . config , response . error , test . location . file ) ;
595619 return response ;
596620 } catch ( e ) {
597621 const error = serializeError ( e ) ;
598- addLocationAndSnippetToError ( this . _config . config , error ) ;
622+ addLocationAndSnippetToError ( this . _config . config , error , test . location . file ) ;
599623 return { response : undefined , error } ;
600624 }
601625 } ;
602626
603- for ( const error of params . errors )
604- addLocationAndSnippetToError ( this . _config . config , error ) ;
605- this . _failureTracker . onTestPaused ?.( { ...params , sendMessage } ) ;
627+ this . _failureTracker . onTestPaused ?.( { errors : result . errors , sendMessage } ) ;
606628 }
607629
608630 skipWholeJob ( ) : boolean {
0 commit comments