@@ -92,6 +92,7 @@ export default function (config = {}) {
9292 let testStartTime
9393 let currentUrl = null
9494 let testFailed = false
95+ let pendingArtifactCapture = null
9596 let firstFailedStepSaved = false
9697
9798 const reportDir = config . output ? path . resolve ( store . codeceptDir , config . output ) : defaultConfig . output
@@ -129,6 +130,7 @@ export default function (config = {}) {
129130 currentUrl = null
130131 testFailed = false
131132 firstFailedStepSaved = false
133+ pendingArtifactCapture = null
132134 } )
133135
134136 event . dispatcher . on ( event . step . after , step => {
@@ -162,13 +164,12 @@ export default function (config = {}) {
162164 return
163165 }
164166
165- const stepPersistPromise = persistStep ( step ) . catch ( err => {
167+ recorder . add ( `aiTrace step persistence: ${ step . toString ( ) } ` , ( ) => persistStep ( step ) . catch ( err => {
166168 output . debug ( `aiTrace: Error saving step: ${ err . message } ` )
167- } )
168- recorder . add ( `wait aiTrace step persistence: ${ step . toString ( ) } ` , ( ) => stepPersistPromise , true )
169+ } ) , true )
169170 } )
170171
171- event . dispatcher . on ( event . step . failed , async step => {
172+ event . dispatcher . on ( event . step . failed , step => {
172173 if ( ! currentTest ) return
173174 if ( step . status === 'queued' && testFailed ) {
174175 output . debug ( `aiTrace: Skipping queued failed step "${ step . toString ( ) } " - testFailed: ${ testFailed } ` )
@@ -188,11 +189,9 @@ export default function (config = {}) {
188189 }
189190 existingStep . status = 'failed'
190191
191- try {
192- await captureArtifactsForStep ( step , existingStep , existingStep . prefix )
193- } catch ( err ) {
192+ pendingArtifactCapture = captureArtifactsForStep ( step , existingStep , existingStep . prefix ) . catch ( err => {
194193 output . debug ( `aiTrace: Error updating failed step: ${ err . message } ` )
195- }
194+ } )
196195 } else {
197196 if ( stepNum === - 1 ) return
198197 if ( isStepIgnored ( step ) ) return
@@ -218,11 +217,9 @@ export default function (config = {}) {
218217 steps . push ( stepData )
219218 firstFailedStepSaved = true
220219
221- try {
222- await captureArtifactsForStep ( step , stepData , stepPrefix )
223- } catch ( err ) {
220+ pendingArtifactCapture = captureArtifactsForStep ( step , stepData , stepPrefix ) . catch ( err => {
224221 output . debug ( `aiTrace: Error capturing failed step artifacts: ${ err . message } ` )
225- }
222+ } )
226223 }
227224 } )
228225
@@ -238,7 +235,13 @@ export default function (config = {}) {
238235 if ( hookName === 'BeforeSuite' || hookName === 'AfterSuite' ) {
239236 return
240237 }
241- persist ( test , 'failed' )
238+ recorder . add ( 'aiTrace:persist failed' , async ( ) => {
239+ if ( pendingArtifactCapture ) {
240+ await pendingArtifactCapture
241+ pendingArtifactCapture = null
242+ }
243+ persist ( test , 'failed' )
244+ } , true )
242245 } )
243246
244247 async function persistStep ( step ) {
0 commit comments