@@ -526,3 +526,59 @@ test(`trace:retain-on-failure should create trace if request context is disposed
526
526
expect ( trace . apiNames ) . toContain ( 'apiRequestContext.get' ) ;
527
527
expect ( result . failed ) . toBe ( 1 ) ;
528
528
} ) ;
529
+
530
+ test ( 'should include attachments by default' , async ( { runInlineTest, server } , testInfo ) => {
531
+ const result = await runInlineTest ( {
532
+ 'playwright.config.ts' : `
533
+ module.exports = { use: { trace: 'on' } };
534
+ ` ,
535
+ 'a.spec.ts' : `
536
+ import { test, expect } from '@playwright/test';
537
+
538
+ test('pass', async ({}, testInfo) => {
539
+ testInfo.attach('foo', { body: 'bar' });
540
+ });
541
+ ` ,
542
+ } , { workers : 1 } ) ;
543
+
544
+ expect ( result . exitCode ) . toBe ( 0 ) ;
545
+ expect ( result . passed ) . toBe ( 1 ) ;
546
+ const trace = await parseTrace ( testInfo . outputPath ( 'test-results' , 'a-pass' , 'trace.zip' ) ) ;
547
+ expect ( trace . apiNames ) . toEqual ( [
548
+ 'Before Hooks' ,
549
+ `attach "foo"` ,
550
+ 'After Hooks' ,
551
+ ] ) ;
552
+ expect ( trace . actions [ 1 ] . attachments ) . toEqual ( [ {
553
+ name : 'foo' ,
554
+ contentType : 'text/plain' ,
555
+ sha1 : expect . any ( String ) ,
556
+ } ] ) ;
557
+ expect ( [ ...trace . resources . keys ( ) ] . filter ( f => f . startsWith ( 'resources/' ) ) ) . toHaveLength ( 1 ) ;
558
+ } ) ;
559
+
560
+ test ( 'should opt out of attachments' , async ( { runInlineTest, server } , testInfo ) => {
561
+ const result = await runInlineTest ( {
562
+ 'playwright.config.ts' : `
563
+ module.exports = { use: { trace: { mode: 'on', attachments: false } } };
564
+ ` ,
565
+ 'a.spec.ts' : `
566
+ import { test, expect } from '@playwright/test';
567
+
568
+ test('pass', async ({}, testInfo) => {
569
+ testInfo.attach('foo', { body: 'bar' });
570
+ });
571
+ ` ,
572
+ } , { workers : 1 } ) ;
573
+
574
+ expect ( result . exitCode ) . toBe ( 0 ) ;
575
+ expect ( result . passed ) . toBe ( 1 ) ;
576
+ const trace = await parseTrace ( testInfo . outputPath ( 'test-results' , 'a-pass' , 'trace.zip' ) ) ;
577
+ expect ( trace . apiNames ) . toEqual ( [
578
+ 'Before Hooks' ,
579
+ `attach "foo"` ,
580
+ 'After Hooks' ,
581
+ ] ) ;
582
+ expect ( trace . actions [ 1 ] . attachments ) . toEqual ( undefined ) ;
583
+ expect ( [ ...trace . resources . keys ( ) ] . filter ( f => f . startsWith ( 'resources/' ) ) ) . toHaveLength ( 0 ) ;
584
+ } ) ;
0 commit comments