@@ -430,39 +430,49 @@ export class AllureReporter implements ReporterV2 {
430
430
431
431
const attachmentsInBeforeHooks = this . beforeHooksAttachmentsStack . get ( test . id ) ?? [ ] ;
432
432
const attachmentsInAfterHooks = this . afterHooksAttachmentsStack . get ( test . id ) ?? [ ] ;
433
- const hookAttachmentCounts = new Map < string , number > ( ) ;
434
-
435
- for ( const hookStep of [ ...attachmentsInBeforeHooks , ...attachmentsInAfterHooks ] ) {
436
- const name = normalizeHookTitle ( hookStep . title ) ;
437
- if ( name ) {
438
- hookAttachmentCounts . set ( name , ( hookAttachmentCounts . get ( name ) || 0 ) + 1 ) ;
439
- }
440
- }
441
-
442
433
const attachmentSteps = this . attachmentSteps . get ( testUuid ) ?? [ ] ;
443
434
444
- const onlyHooksAttachments : typeof result . attachments = [ ] ;
445
- const attachmentsInSteps : typeof result . attachments = [ ] ;
446
- const attachmentCounts = new Map < string , number > ( ) ;
435
+ const attachmentToStepMap = new Map < number , { stepUuid ?: string ; isHook : boolean ; hookStep ?: AttachStack } > ( ) ;
447
436
448
- for ( const attachment of result . attachments ) {
449
- const hookCount = hookAttachmentCounts . get ( attachment . name ) || 0 ;
450
- const currentCount = attachmentCounts . get ( attachment . name ) || 0 ;
437
+ let attachmentIndex = 0 ;
451
438
452
- if ( currentCount < hookCount ) {
453
- onlyHooksAttachments . push ( attachment ) ;
454
- } else {
455
- attachmentsInSteps . push ( attachment ) ;
456
- }
439
+ for ( const hookStep of attachmentsInBeforeHooks ) {
440
+ attachmentToStepMap . set ( attachmentIndex , {
441
+ stepUuid : hookStep . uuid ,
442
+ isHook : true ,
443
+ hookStep,
444
+ } ) ;
445
+ attachmentIndex ++ ;
446
+ }
447
+
448
+ for ( const stepUuid of attachmentSteps ) {
449
+ attachmentToStepMap . set ( attachmentIndex , {
450
+ stepUuid,
451
+ isHook : false ,
452
+ } ) ;
453
+ attachmentIndex ++ ;
454
+ }
457
455
458
- attachmentCounts . set ( attachment . name , currentCount + 1 ) ;
456
+ for ( const hookStep of attachmentsInAfterHooks ) {
457
+ attachmentToStepMap . set ( attachmentIndex , {
458
+ stepUuid : hookStep . uuid ,
459
+ isHook : true ,
460
+ hookStep,
461
+ } ) ;
462
+ attachmentIndex ++ ;
459
463
}
460
464
461
- for ( let i = 0 ; i < attachmentsInSteps . length ; i ++ ) {
462
- const attachment = attachmentsInSteps [ i ] ;
463
- const attachmentStep = attachmentSteps . length > i ? attachmentSteps [ i ] : undefined ;
465
+ for ( let i = 0 ; i < result . attachments . length ; i ++ ) {
466
+ const attachment = result . attachments [ i ] ;
467
+ const stepInfo = attachmentToStepMap . get ( i ) ;
464
468
465
- await this . processAttachment ( testUuid , attachmentStep , attachment ) ;
469
+ if ( stepInfo ?. isHook ) {
470
+ continue ;
471
+ } else if ( stepInfo ?. stepUuid ) {
472
+ await this . processAttachment ( testUuid , stepInfo . stepUuid , attachment ) ;
473
+ } else {
474
+ await this . processAttachment ( testUuid , undefined , attachment ) ;
475
+ }
466
476
}
467
477
468
478
if ( result . stdout . length > 0 ) {
@@ -492,41 +502,30 @@ export class AllureReporter implements ReporterV2 {
492
502
// FIXME: temp logic for labels override, we need it here to keep the reporter compatible with v2 API
493
503
// in next iterations we need to implement the logic for every javascript integration
494
504
495
- let beforeHookIndex = 0 ;
496
- let afterHookIndex = 0 ;
497
-
498
- for ( const attachment of onlyHooksAttachments ) {
499
- let matchingBeforeHookStep = null ;
500
- let matchingAfterHookStep = null ;
501
- let targetStack = null ;
502
- let hookStep = null ;
503
-
504
- if ( beforeHookIndex < attachmentsInBeforeHooks . length ) {
505
- matchingBeforeHookStep = attachmentsInBeforeHooks [ beforeHookIndex ] ;
506
- targetStack = beforeHooksStack ;
507
- hookStep = matchingBeforeHookStep ;
508
- beforeHookIndex ++ ;
509
- } else if ( afterHookIndex < attachmentsInAfterHooks . length ) {
510
- matchingAfterHookStep = attachmentsInAfterHooks [ afterHookIndex ] ;
511
- targetStack = afterHooksStack ;
512
- hookStep = matchingAfterHookStep ;
513
- afterHookIndex ++ ;
514
- }
505
+ for ( let i = 0 ; i < result . attachments . length ; i ++ ) {
506
+ const attachment = result . attachments [ i ] ;
507
+ const stepInfo = attachmentToStepMap . get ( i ) ;
515
508
516
- if ( attachment . contentType === ALLURE_RUNTIME_MESSAGE_CONTENT_TYPE ) {
517
- await this . processAttachment ( testUuid , hookStep ?. uuid , attachment ) ;
518
- continue ;
519
- }
509
+ if ( stepInfo ?. isHook && stepInfo . hookStep ) {
510
+ const hookStep = stepInfo . hookStep ;
511
+ const isBeforeHook = attachmentsInBeforeHooks . includes ( hookStep ) ;
512
+ const targetStack = isBeforeHook ? beforeHooksStack : afterHooksStack ;
513
+
514
+ if ( attachment . contentType === ALLURE_RUNTIME_MESSAGE_CONTENT_TYPE ) {
515
+ await this . processAttachment ( testUuid , hookStep . uuid , attachment ) ;
516
+ continue ;
517
+ }
520
518
521
- if ( targetStack && hookStep ) {
522
- const stepResult = targetStack ?. findStepByUuid ( hookStep ?. uuid ) ;
523
- if ( stepResult ) {
524
- const fileName = targetStack . addAttachment ( attachment , this . allureRuntime ! . writer ) ;
525
- stepResult . attachments . push ( {
526
- name : attachment . name ,
527
- type : attachment . contentType ,
528
- source : fileName ,
529
- } ) ;
519
+ if ( targetStack ) {
520
+ const stepResult = targetStack . findStepByUuid ( hookStep . uuid ) ;
521
+ if ( stepResult ) {
522
+ const fileName = targetStack . addAttachment ( attachment , this . allureRuntime ! . writer ) ;
523
+ stepResult . attachments . push ( {
524
+ name : attachment . name ,
525
+ type : attachment . contentType ,
526
+ source : fileName ,
527
+ } ) ;
528
+ }
530
529
}
531
530
}
532
531
}
0 commit comments