@@ -48,7 +48,17 @@ const log = (...args: unknown[]) => {
48
48
} ;
49
49
50
50
const createNewContentForContainer = ( nameAttAhc : string , existingContents : Buffer , ext : string , specname : string ) => {
51
- const containerJSON = JSON . parse ( existingContents . toString ( ) ) ;
51
+ const getContentJson = ( ) => {
52
+ try {
53
+ return JSON . parse ( existingContents . toString ( ) ) ;
54
+ } catch ( e ) {
55
+ console . error ( `${ packageLog } Could not parse the contents of attachment ${ nameAttAhc } ` ) ;
56
+
57
+ return { } ;
58
+ }
59
+ } ;
60
+
61
+ const containerJSON = getContentJson ( ) ;
52
62
53
63
const after : ExecutableItem = {
54
64
name : 'video' ,
@@ -421,30 +431,35 @@ export class AllureReporter {
421
431
422
432
uuids . forEach ( uuid => {
423
433
const testFile = `${ this . allureResults } /${ uuid } -result.json` ;
424
- const contents = readFileSync ( testFile ) ;
425
- const ext = path . extname ( x . path ) ;
426
- const name = path . basename ( x . path ) ;
427
- type ParsedAttachment = { name : string ; type : ContentType ; source : string } ;
428
- const testCon : { attachments : ParsedAttachment [ ] } = JSON . parse ( contents . toString ( ) ) ;
429
- const uuidNew = randomUUID ( ) ;
430
- const nameAttAhc = `${ uuidNew } -attachment${ ext } ` ; // todo not copy same image
431
- const newPath = path . join ( this . allureResults , nameAttAhc ) ;
432
-
433
- if ( ! existsSync ( newPath ) ) {
434
- copyFileSync ( x . path , path . join ( this . allureResults , nameAttAhc ) ) ;
435
- }
436
434
437
- if ( ! testCon . attachments ) {
438
- testCon . attachments = [ ] ;
439
- }
435
+ try {
436
+ const contents = readFileSync ( testFile ) ;
437
+ const ext = path . extname ( x . path ) ;
438
+ const name = path . basename ( x . path ) ;
439
+ type ParsedAttachment = { name : string ; type : ContentType ; source : string } ;
440
+ const testCon : { attachments : ParsedAttachment [ ] } = JSON . parse ( contents . toString ( ) ) ;
441
+ const uuidNew = randomUUID ( ) ;
442
+ const nameAttAhc = `${ uuidNew } -attachment${ ext } ` ; // todo not copy same image
443
+ const newPath = path . join ( this . allureResults , nameAttAhc ) ;
440
444
441
- testCon . attachments . push ( {
442
- name : name ,
443
- type : 'image/png' ,
444
- source : nameAttAhc , // todo
445
- } ) ;
445
+ if ( ! existsSync ( newPath ) ) {
446
+ copyFileSync ( x . path , path . join ( this . allureResults , nameAttAhc ) ) ;
447
+ }
448
+
449
+ if ( ! testCon . attachments ) {
450
+ testCon . attachments = [ ] ;
451
+ }
446
452
447
- writeFileSync ( testFile , JSON . stringify ( testCon ) ) ;
453
+ testCon . attachments . push ( {
454
+ name : name ,
455
+ type : 'image/png' ,
456
+ source : nameAttAhc , // todo
457
+ } ) ;
458
+
459
+ writeFileSync ( testFile , JSON . stringify ( testCon ) ) ;
460
+ } catch ( e ) {
461
+ console . log ( `Could not attach screenshot ${ x . screenshotId } ` ) ;
462
+ }
448
463
} ) ;
449
464
} ) ;
450
465
}
@@ -474,7 +489,7 @@ export class AllureReporter {
474
489
}
475
490
476
491
if ( ! existsSync ( file ) ) {
477
- console . log ( `file ${ file } doesnt exist` ) ;
492
+ console . log ( `${ packageLog } file ${ file } doesnt exist` ) ;
478
493
479
494
return ;
480
495
}
@@ -515,14 +530,14 @@ export class AllureReporter {
515
530
516
531
readFile ( videoPath , errVideo => {
517
532
if ( errVideo ) {
518
- console . error ( `Could not read video: ${ errVideo } ` ) ;
533
+ console . error ( `${ packageLog } Could not read video: ${ errVideo } ` ) ;
519
534
520
535
return ;
521
536
}
522
537
523
538
testsAttach . forEach ( test => {
524
539
if ( ! test . parent ) {
525
- console . error ( `not writing videos since test has no parent suite: ${ test . fullName } ` ) ;
540
+ console . error ( `${ packageLog } not writing videos since test has no parent suite: ${ test . fullName } ` ) ;
526
541
527
542
return ;
528
543
}
0 commit comments