@@ -45,14 +45,15 @@ import {
4545 readImageAsBase64 ,
4646} from "allure-js-commons/sdk/reporter" ;
4747import { allurePlaywrightLegacyApi } from "./legacy.js" ;
48- import type { AllurePlaywrightReporterConfig , AttachStack , ReporterV2 } from "./model.js" ;
48+ import type { AllurePlaywrightReporterConfig , AttachStack , AttachmentTarget , ReporterV2 } from "./model.js" ;
4949import {
5050 AFTER_HOOKS_ROOT_STEP_TITLE ,
5151 BEFORE_HOOKS_ROOT_STEP_TITLE ,
5252 diffEndRegexp ,
5353 isAfterHookStep ,
5454 isBeforeHookStep ,
5555 isDescendantOfStepWithTitle ,
56+ normalizeAttachStepTitle ,
5657 normalizeHookTitle ,
5758 statusToAllureStats ,
5859} from "./utils.js" ;
@@ -69,7 +70,7 @@ export class AllureReporter implements ReporterV2 {
6970 private processedDiffs : string [ ] = [ ] ;
7071 private readonly startedTestCasesTitlesCache : string [ ] = [ ] ;
7172 private readonly allureResultsUuids : Map < string , string > = new Map ( ) ;
72- private readonly attachmentTargets : Map < string , { stepUuid ?: string ; hookStep ?: AttachStack } [ ] > = new Map ( ) ;
73+ private readonly attachmentTargets : Map < string , AttachmentTarget [ ] > = new Map ( ) ;
7374 private beforeHooksStepsStack : Map < string , ShallowStepsStack > = new Map ( ) ;
7475 private afterHooksStepsStack : Map < string , ShallowStepsStack > = new Map ( ) ;
7576 private beforeHooksAttachmentsStack : Map < string , AttachStack [ ] > = new Map ( ) ;
@@ -301,10 +302,11 @@ export class AllureReporter implements ReporterV2 {
301302 if ( [ "test.attach" , "attach" ] . includes ( step . category ) && ! isHookStep ) {
302303 const parent = step . parent ? this . pwStepUuid . get ( step . parent ) ?? null : null ;
303304 const targets = this . attachmentTargets . get ( test . id ) ?? [ ] ;
304- targets . push ( { stepUuid : parent ?? undefined } ) ;
305+ targets . push ( { name : normalizeAttachStepTitle ( step . title ) , stepUuid : parent ?? undefined } ) ;
305306 this . attachmentTargets . set ( test . id , targets ) ;
306307 return ;
307308 }
309+
308310 if ( isHookStep ) {
309311 const stack = isBeforeHookDescendant
310312 ? this . beforeHooksStepsStack . get ( test . id ) !
@@ -325,7 +327,7 @@ export class AllureReporter implements ReporterV2 {
325327 stack . stopStep ( ) ;
326328
327329 const targets = this . attachmentTargets . get ( test . id ) ?? [ ] ;
328- targets . push ( { hookStep : hookStepWithUuid } ) ;
330+ targets . push ( { name : normalizeAttachStepTitle ( step . title ) , hookStep : hookStepWithUuid } ) ;
329331 this . attachmentTargets . set ( test . id , targets ) ;
330332 return ;
331333 }
@@ -477,13 +479,27 @@ export class AllureReporter implements ReporterV2 {
477479 }
478480
479481 const attachmentsInBeforeHooks = this . beforeHooksAttachmentsStack . get ( test . id ) ?? [ ] ;
480- const attachmentTargets = this . attachmentTargets . get ( test . id ) ?? [ ] ;
481482
482- let targetIndex = 0 ;
483+ // FIFO
484+ const targets = this . attachmentTargets . get ( test . id ) ?? [ ] ;
485+ const targetsByName = new Map < string , AttachmentTarget [ ] > ( ) ;
486+ for ( const t of targets ) {
487+ const q = targetsByName . get ( t . name ) ?? [ ] ;
488+ q . push ( t ) ;
489+ targetsByName . set ( t . name , q ) ;
490+ }
491+
492+ const takeByName = ( name : string ) : AttachmentTarget | undefined => {
493+ const target = targetsByName . get ( name ) ;
494+ if ( ! target || target . length === 0 ) {
495+ return undefined ;
496+ }
497+ return target . shift ( ) ;
498+ } ;
483499
484500 for ( const attachment of result . attachments ) {
485501 const isRuntimeMessage = attachment . contentType === ALLURE_RUNTIME_MESSAGE_CONTENT_TYPE ;
486- const stepInfo = targetIndex < attachmentTargets . length ? attachmentTargets [ targetIndex ++ ] : undefined ;
502+ const stepInfo = takeByName ( attachment . name ) ;
487503
488504 if ( isRuntimeMessage ) {
489505 const stepUuid = stepInfo ?. hookStep ?. uuid ?? stepInfo ?. stepUuid ;
@@ -558,6 +574,7 @@ export class AllureReporter implements ReporterV2 {
558574 } ) ;
559575 this . allureRuntime ! . stopTest ( testUuid , { duration : result . duration } ) ;
560576 this . allureRuntime ! . writeTest ( testUuid ) ;
577+ this . attachmentTargets . delete ( test . id ) ;
561578 }
562579
563580 async addSkippedResults ( ) {
0 commit comments