@@ -23,6 +23,58 @@ export type ReporterOptions = {
23
23
isTest : boolean ;
24
24
} ;
25
25
26
+ const copyResultsToWatchFolder = async ( allureResults : string , allureResultsWatch : string ) => {
27
+ if ( allureResults === allureResultsWatch ) {
28
+ log ( `afterSpec allureResultsWatch the same as allureResults ${ allureResults } , will not copy` ) ;
29
+
30
+ return ;
31
+ }
32
+
33
+ const results = glob . sync ( `${ allureResults } /*.*` ) ;
34
+
35
+ if ( ! existsSync ( allureResultsWatch ) ) {
36
+ const mkdirSyncWithTry = ( dir : string ) => {
37
+ for ( let i = 0 ; i < 5 ; i ++ ) {
38
+ try {
39
+ mkdirSync ( dir ) ;
40
+
41
+ return ;
42
+ } catch ( err ) {
43
+ // ignore
44
+ }
45
+ }
46
+ } ;
47
+ mkdirSyncWithTry ( allureResultsWatch ) ;
48
+ }
49
+ log ( `allureResults: ${ allureResults } ` ) ;
50
+ log ( `allureResultsWatch: ${ allureResultsWatch } ` ) ;
51
+ let doneFiles = 0 ;
52
+ const started = Date . now ( ) ;
53
+ const timeout = 10000 ;
54
+
55
+ results . forEach ( res => {
56
+ const to = `${ allureResultsWatch } /${ basename ( res ) } ` ;
57
+ log ( `copy file ${ res } to ${ to } ` ) ;
58
+ copyFile ( res , to , err => {
59
+ if ( err ) {
60
+ log ( err ) ;
61
+ }
62
+ rm ( res , ( ) => {
63
+ // ignore
64
+ } ) ;
65
+ doneFiles = doneFiles + 1 ;
66
+ } ) ;
67
+ } ) ;
68
+
69
+ while ( doneFiles < results . length ) {
70
+ if ( Date . now ( ) - started >= timeout ) {
71
+ console . error ( `${ packageLog } Could not write all attachments in ${ timeout } ms` ) ;
72
+ break ;
73
+ }
74
+ await delay ( 100 ) ;
75
+ }
76
+ } ;
77
+
26
78
export const allureTasks = ( opts : ReporterOptions ) : AllureTasks => {
27
79
// todo config
28
80
let allureReporter = new AllureReporter ( opts ) ;
@@ -301,6 +353,7 @@ export const allureTasks = (opts: ReporterOptions): AllureTasks => {
301
353
allureReporter . screenshotOne ( arg ) ;
302
354
log ( 'screenshotOne' ) ;
303
355
} ,
356
+
304
357
// add all screenshots
305
358
attachScreenshots : ( arg : AllureTaskArgs < 'attachScreenshots' > ) => {
306
359
log ( `attachScreenshots ${ JSON . stringify ( arg ) } ` ) ;
@@ -310,74 +363,25 @@ export const allureTasks = (opts: ReporterOptions): AllureTasks => {
310
363
log ( 'attachScreenshots' ) ;
311
364
} ,
312
365
313
- attachVideoToTests : async ( arg : AllureTaskArgs < 'attachVideoToTests' > ) => {
366
+ /* attachVideoToTests: async (arg: AllureTaskArgs<'attachVideoToTests'>) => {
314
367
log(`attachScreenshots ${JSON.stringify(arg)}`);
315
368
await allureReporter.attachVideoToTests(arg);
316
369
log('attachVideoToTests');
317
- } ,
370
+ },*/
318
371
319
372
async afterSpec ( arg : AllureTaskArgs < 'afterSpec' > ) {
320
373
log ( `afterSpec ${ JSON . stringify ( arg ) } ` ) ;
321
374
322
375
if ( arg . results && arg . results ?. video ) {
323
- const { video } = arg . results ;
376
+ const { video } = arg . results ?? { } ;
324
377
log ( `afterSpec video path: ${ video } ` ) ;
325
378
326
379
await allureReporter . attachVideoToTests ( { path : video ?? '' } ) ;
327
380
} else {
328
381
console . error ( `${ packageLog } No video path in afterSpec result` ) ;
329
382
}
330
383
331
- if ( allureResults === allureResultsWatch ) {
332
- log ( `afterSpec allureResultsWatch the same as allureResults ${ allureResults } , will not copy` ) ;
333
-
334
- return ;
335
- }
336
-
337
- const results = glob . sync ( `${ allureResults } /*.*` ) ;
338
-
339
- if ( ! existsSync ( allureResultsWatch ) ) {
340
- const mkdirSyncWithTry = ( dir : string ) => {
341
- for ( let i = 0 ; i < 5 ; i ++ ) {
342
- try {
343
- mkdirSync ( dir ) ;
344
-
345
- return ;
346
- } catch ( err ) {
347
- // ignore
348
- }
349
- }
350
- } ;
351
- mkdirSyncWithTry ( allureResultsWatch ) ;
352
- }
353
- log ( `allureResults: ${ allureResults } ` ) ;
354
- log ( `allureResultsWatch: ${ allureResultsWatch } ` ) ;
355
- let doneFiles = 0 ;
356
- const started = Date . now ( ) ;
357
- const timeout = 10000 ;
358
-
359
- results . forEach ( res => {
360
- const to = `${ allureResultsWatch } /${ basename ( res ) } ` ;
361
- log ( `copy file ${ res } to ${ to } ` ) ;
362
- copyFile ( res , to , err => {
363
- if ( err ) {
364
- log ( err ) ;
365
- }
366
- rm ( res , ( ) => {
367
- // ignore
368
- } ) ;
369
- doneFiles = doneFiles + 1 ;
370
- } ) ;
371
- } ) ;
372
-
373
- while ( doneFiles < results . length ) {
374
- if ( Date . now ( ) - started >= timeout ) {
375
- console . error ( `${ packageLog } Could not write all attachments in ${ timeout } ms` ) ;
376
- break ;
377
- }
378
- await delay ( 100 ) ;
379
- }
380
-
384
+ await copyResultsToWatchFolder ( allureResults , allureResultsWatch ) ;
381
385
log ( 'afterSpec' ) ;
382
386
} ,
383
387
0 commit comments