@@ -8,13 +8,18 @@ import path from 'path'
88
99class MyReporter implements Reporter {
1010 outputFolder : string ;
11- testResults : Array < { title : string , id : string , trace : any } > ;
11+ testResults : Array < string > ;
1212
1313 constructor ( ) {
14- this . outputFolder = 'playwright-traces '
14+ this . outputFolder = 'playwright-errors '
1515 this . cleanupFolder ( )
1616 this . testResults = [ ]
1717 }
18+
19+ removeColorCodes ( input : string ) {
20+ return input . replace ( / \[ [ 0 - 9 ; ] * m / g, '' )
21+ }
22+
1823 cleanupFolder ( ) {
1924 const folderPath = path . resolve ( this . outputFolder )
2025
@@ -35,14 +40,31 @@ class MyReporter implements Reporter {
3540 }
3641
3742 onTestEnd ( test : TestCase , result : TestResult ) {
38- if ( result . attachments . length !== 0 ) {
39- console . log ( 'title:' , test . title )
40- console . log ( 'attachments' , result . attachments )
41- this . testResults . push ( {
42- id : test . id ,
43- title : test . title ,
44- trace : result . attachments . find ( attachment => attachment . name === 'trace' ) . path ,
45- } )
43+ if ( result . status !== test . expectedStatus ) {
44+ let testResult = `### ${ test . title }
45+ `
46+ if ( result . errors . length >= 1 ) {
47+ testResult += `\`\`\`
48+ `
49+ result . errors . forEach ( error => {
50+ if ( error . message ) {
51+ testResult += `${ this . removeColorCodes ( error . message ) }
52+
53+ `
54+ }
55+
56+ if ( error . snippet ) {
57+ testResult += `${ this . removeColorCodes ( error . snippet ) }
58+
59+ `
60+ }
61+ } )
62+ testResult += `\`\`\`
63+
64+ `
65+ }
66+
67+ this . testResults . push ( testResult )
4668 }
4769 }
4870
@@ -54,8 +76,15 @@ class MyReporter implements Reporter {
5476 }
5577
5678 // Write the collected results to a JSON file
57- const reportPath = path . join ( folderPath , 'test-traces.json' )
58- fs . writeFileSync ( reportPath , JSON . stringify ( this . testResults , null , 2 ) )
79+ const reportPath = path . join ( folderPath , 'errors.md' )
80+ let reportContent = ''
81+ if ( this . testResults . length ) {
82+ reportContent += `## Failed Tests
83+
84+ ${ this . testResults . join ( '' ) } `
85+ }
86+
87+ fs . writeFileSync ( reportPath , reportContent )
5988 }
6089}
6190export default MyReporter
0 commit comments