1
+ import { STRUCTURED_LOGS_ENVVAR_NAME } from '@testla/screenplay' ;
1
2
import type {
2
3
FullResult ,
3
4
Reporter , TestCase , TestResult , TestStatus ,
@@ -37,7 +38,9 @@ class TextReporter implements Reporter {
37
38
break ;
38
39
case 'failed' :
39
40
case 'timedOut' :
40
- this . failed . push ( testId ) ;
41
+ if ( ! this . failed . some ( ( entry ) => entry === testId ) ) {
42
+ this . failed . push ( testId ) ;
43
+ }
41
44
break ;
42
45
case 'passed' :
43
46
default :
@@ -76,16 +79,6 @@ class TextReporter implements Reporter {
76
79
}
77
80
}
78
81
79
- // async onStdOut(chunk: string | Buffer, test: TestCase): Promise<void> {
80
- // const result = await streamToString(
81
- // Readable.from(chunk)
82
- // .pipe(new FilterEventStream())
83
- // .pipe(new ParseEventStream())
84
- // .pipe(new TransformEventToTextStream()),
85
- // );
86
- // this.addToResultBuffer(result, test.id);
87
- // }
88
-
89
82
onBegin ( ) {
90
83
if ( this . outputFile && existsSync ( this . outputFile ) ) {
91
84
rm ( this . outputFile , ( err ) => {
@@ -95,25 +88,18 @@ class TextReporter implements Reporter {
95
88
} ) ;
96
89
}
97
90
98
- process . env . TEASLA_SCREENPLAY_STRUCTURED_LOGS = 'true' ;
91
+ process . env [ STRUCTURED_LOGS_ENVVAR_NAME ] = 'true' ;
99
92
}
100
93
101
94
async onTestEnd ( test : TestCase , result : TestResult ) {
102
- // test.results[0].stdout
103
- // this.addToResultBuffer(`${new Date().toISOString()} [CASE] ${TextReporter.getResultStatusIcon(result.status)} ${test.parent.title} > ${test.title} [${test._projectId.toUpperCase()}] [${result.status.toUpperCase()}] (${TextReporter.printRuntime(result.duration)})`, test.id);
104
- // this.write(`${new Date().toISOString()} [CASE${result.retry > 0 ? ` RETRY#${result.retry}` : ''}] ${TextReporter.getResultStatusIcon(result.status)} ${test.parent.title} > ${test.title} [${test._projectId.toUpperCase()}] [${result.status.toUpperCase()}] (${TextReporter.printRuntime(result.duration)})`);
105
- // this.write(`${TextReporter.getResultStatusIcon(result.status)} ${test.parent.title} › ${test.title} ${result.retry > 0 ? `[RETRY#${result.retry}] ` : ''}[${result.status.toUpperCase()} after ${TextReporter.printRuntime(result.duration)}] (${test._projectId.toUpperCase()})`);
95
+ // eslint-disable-next-line
96
+ // @ts -ignore
97
+ // eslint-disable-next-line
106
98
this . write ( `[${ test . _projectId . toUpperCase ( ) } ] ${ TextReporter . getResultStatusIcon ( result . status ) } ${ test . parent . title } › ${ test . title } ${ result . retry > 0 ? `[RETRY#${ result . retry } ] ` : '' } [${ result . status . toUpperCase ( ) } after ${ TextReporter . printRuntime ( result . duration ) } ]` ) ;
107
- this . write ( '────────────────────────────────' ) ;
108
- // test.results[0].stdout.forEach((line: string): void => {
109
-
110
- // });
111
- // test.results.forEach((result, index) => {
112
- // eslint-disable-next-line no-restricted-syntax
113
- // for (const resultX of test.results) {
114
- // if (resultX.retry > 0) {
115
- // this.write(`--- retry #${resultX.retry} ---`);
116
- // }
99
+ if ( result . status !== 'skipped' ) {
100
+ this . write ( '────────────────────────────────' ) ;
101
+ }
102
+
117
103
// eslint-disable-next-line no-await-in-loop
118
104
const reportString = await streamToString (
119
105
Readable . from ( result . stdout )
@@ -124,14 +110,14 @@ class TextReporter implements Reporter {
124
110
this . write ( reportString ) ;
125
111
126
112
this . putIntoBucket ( TextReporter . getTestId ( test ) , result . status ) ;
127
- // };
128
113
}
129
114
130
115
onEnd ( result : FullResult ) {
131
116
this . write ( '────────────────────────────────\n' ) ;
132
117
this . write ( `Finished the run: ${ result . status . toUpperCase ( ) } after ${ TextReporter . printRuntime ( result . duration ) } \n` ) ;
133
118
if ( this . failed . length ) {
134
119
this . write ( `Failed: ${ this . failed . length } ` ) ;
120
+ this . failed . sort ( ) . forEach ( ( failed : string ) => this . write ( ` - ${ TextReporter . reformatFailedString ( failed ) } ` ) )
135
121
}
136
122
if ( this . skipped . length ) {
137
123
this . write ( `Skipped: ${ this . skipped . length } ` ) ;
@@ -149,6 +135,12 @@ class TextReporter implements Reporter {
149
135
150
136
private static printRuntime = ( time : number ) => `${ ( Math . round ( time * 1000 ) / 1000000 ) . toFixed ( 3 ) } s` ;
151
137
138
+ private static reformatFailedString = ( str : string ) => {
139
+ const firstArrowReplaced = str . replace ( '>' , '›' ) ;
140
+ const parts = firstArrowReplaced . split ( '›' ) ;
141
+ return `[${ parts [ 0 ] . trim ( ) . toUpperCase ( ) } ] ✗ ${ parts [ 1 ] . trim ( ) . replaceAll ( '>' , '›' ) } ` ;
142
+ } ;
143
+
152
144
// eslint-disable-next-line class-methods-use-this
153
145
printsToStdio ( ) : boolean {
154
146
return false ;
0 commit comments