@@ -7,10 +7,15 @@ import type {
77 ReportFiles ,
88 ResultFile ,
99} from "@allurereport/plugin-api" ;
10- import AwesomePlugin from "@allurereport/plugin-awesome" ;
1110import { allure1 , allure2 , attachments , cucumberjson , junitXml , readXcResultBundle } from "@allurereport/reader" ;
1211import { PathResultFile , type ResultsReader } from "@allurereport/reader-api" ;
13- import { AllureRemoteHistory , AllureServiceClient , KnownError , UnknownError } from "@allurereport/service" ;
12+ import {
13+ AllureRemoteHistory ,
14+ AllureServiceClient ,
15+ KnownError ,
16+ type RemotePluginsMap ,
17+ UnknownError ,
18+ } from "@allurereport/service" ;
1419import { generateSummary } from "@allurereport/summary" ;
1520import console from "node:console" ;
1621import { randomUUID } from "node:crypto" ;
@@ -43,7 +48,7 @@ export class AllureReport {
4348 readonly #output: string ;
4449 readonly #history: AllureHistory | undefined ;
4550 readonly #allureServiceClient: AllureServiceClient | undefined ;
46- readonly #publish: boolean ;
51+
4752 #reportUrl?: string ;
4853 #state?: Record < string , PluginState > ;
4954 #stage: "init" | "running" | "done" = "init" ;
@@ -66,7 +71,6 @@ export class AllureReport {
6671 } = opts ;
6772
6873 this . #allureServiceClient = allureServiceConfig ?. url ? new AllureServiceClient ( allureServiceConfig ) : undefined ;
69- this . #publish = allureServiceConfig ?. publish ?? false ;
7074 this . #reportUuid = randomUUID ( ) ;
7175 this . #reportName = name ;
7276 this . #eventEmitter = new EventEmitter < AllureStoreEvents > ( ) ;
@@ -111,6 +115,37 @@ export class AllureReport {
111115 return this . #qualityGate. result ;
112116 }
113117
118+ get #remotePluginsMap( ) {
119+ return this . #plugins
120+ . filter ( ( { enabled, options } ) => enabled && options . publish )
121+ . reduce (
122+ ( acc , { id, packageName, packageVersion, options } ) => ( {
123+ ...acc ,
124+ [ id ] : {
125+ packageName,
126+ packageVersion,
127+ singleFile : options . singleFile ?? false ,
128+ } ,
129+ } ) ,
130+ { } as RemotePluginsMap ,
131+ ) ;
132+ }
133+
134+ #filterRemoteFiles( files : Record < string , string > ) {
135+ return Object . entries ( files ) . reduce (
136+ ( acc , [ key , filename ] ) => {
137+ if ( ! / ^ ( d a t a | w i d g e t s | i n d e x \. h t m l $ ) / . test ( key ) ) {
138+ return acc ;
139+ }
140+
141+ acc [ key ] = filename ;
142+
143+ return acc ;
144+ } ,
145+ { } as Record < string , string > ,
146+ ) ;
147+ }
148+
114149 readDirectory = async ( resultsDir : string ) => {
115150 if ( this . #stage !== "running" ) {
116151 throw new Error ( initRequired ) ;
@@ -174,10 +209,11 @@ export class AllureReport {
174209 this . #stage = "running" ;
175210
176211 // create remote report to publish files into
177- if ( this . #allureServiceClient && this . #publish ) {
212+ if ( this . #allureServiceClient && Object . keys ( this . #remotePluginsMap ) . length > 0 ) {
178213 const { url } = await this . #allureServiceClient. createReport ( {
179214 reportUuid : this . #reportUuid,
180215 reportName : this . #reportName,
216+ plugins : this . #remotePluginsMap,
181217 } ) ;
182218
183219 this . #reportUrl = url ;
@@ -216,27 +252,24 @@ export class AllureReport {
216252 // closing it early, to prevent future reads
217253 this . #stage = "done" ;
218254
219- await this . #eachPlugin( false , async ( plugin , context , id ) => {
255+ await this . #eachPlugin( false , async ( plugin , context , { id } ) => {
220256 const pluginFiles = ( await context . state . get ( "files" ) ) ?? { } ;
257+ const remotePlugin = this . #remotePluginsMap[ id ] ;
221258
222259 await plugin . done ?.( context , this . #store) ;
223260
224- // publish only Allure Awesome reports
225- if (
226- plugin instanceof AwesomePlugin &&
227- this . #history &&
228- this . #allureServiceClient &&
229- this . #publish &&
230- Object . keys ( pluginFiles ) . length
231- ) {
261+ if ( this . #allureServiceClient && remotePlugin ) {
262+ const filteredPluginFiles = this . #filterRemoteFiles( pluginFiles as Record < string , string > ) ;
263+
232264 await Promise . all (
233- Object . entries ( pluginFiles ) . map ( ( [ key , filepath ] ) =>
265+ Object . entries ( filteredPluginFiles ) . map ( ( [ key , filepath ] ) => {
234266 this . #allureServiceClient?. addReportFile ( {
235267 reportUuid : this . #reportUuid,
268+ pluginId : id ,
236269 key,
237270 filepath,
238- } ) ,
239- ) ,
271+ } ) ;
272+ } ) ,
240273 ) ;
241274 }
242275
@@ -313,20 +346,18 @@ export class AllureReport {
313346
314347 #eachPlugin = async (
315348 initState : boolean ,
316- consumer : ( plugin : Plugin , context : PluginContext , id : string ) => Promise < void > ,
349+ consumer : ( plugin : Plugin , context : PluginContext , options : { id : string } ) => Promise < void > ,
317350 ) => {
318351 if ( initState ) {
319352 // reset state on start;
320353 this . #state = { } ;
321354 }
322355
323- for ( const descriptor of this . #plugins) {
324- if ( ! descriptor . enabled ) {
356+ for ( const { enabled , id , plugin } of this . #plugins) {
357+ if ( ! enabled ) {
325358 continue ;
326359 }
327360
328- const id = descriptor . id ;
329- const plugin = descriptor . plugin ;
330361 const pluginState = this . #getPluginState( initState , id ) ;
331362
332363 if ( ! pluginState ) {
@@ -357,7 +388,7 @@ export class AllureReport {
357388 } ;
358389
359390 try {
360- await consumer . call ( this , plugin , pluginContext , id ) ;
391+ await consumer . call ( this , plugin , pluginContext , { id } ) ;
361392
362393 if ( initState ) {
363394 this . #state! [ id ] = pluginState ;
0 commit comments