1
1
const { getCIInformation } = require ( '../helpers/ci' ) ;
2
2
const logger = require ( '../utils/logger' ) ;
3
3
const { BeatsApi } = require ( './beats.api' ) ;
4
- const { HOOK } = require ( '../helpers/constants' ) ;
4
+ const { HOOK , PROCESS_STATUS } = require ( '../helpers/constants' ) ;
5
5
const TestResult = require ( 'test-results-parser/src/models/TestResult' ) ;
6
6
const { BeatsAttachments } = require ( './beats.attachments' ) ;
7
7
@@ -31,9 +31,7 @@ class Beats {
31
31
await this . #publishTestResults( ) ;
32
32
await this . #uploadAttachments( ) ;
33
33
this . #updateTitleLink( ) ;
34
- await this . #attachFailureSummary( ) ;
35
- await this . #attachSmartAnalysis( ) ;
36
- await this . #attachErrorClusters( ) ;
34
+ await this . #attachExtensions( ) ;
37
35
}
38
36
39
37
#setCIInfo( ) {
@@ -104,13 +102,20 @@ class Beats {
104
102
}
105
103
}
106
104
107
- async #attachFailureSummary ( ) {
105
+ async #attachExtensions ( ) {
108
106
if ( ! this . test_run_id ) {
109
107
return ;
110
108
}
111
109
if ( ! this . config . targets ) {
112
110
return ;
113
111
}
112
+ await this . #attachFailureSummary( ) ;
113
+ await this . #attachFailureAnalysis( ) ;
114
+ await this . #attachSmartAnalysis( ) ;
115
+ await this . #attachErrorClusters( ) ;
116
+ }
117
+
118
+ async #attachFailureSummary( ) {
114
119
if ( this . result . status !== 'FAIL' ) {
115
120
return ;
116
121
}
@@ -132,13 +137,29 @@ class Beats {
132
137
}
133
138
}
134
139
135
- async #attachSmartAnalysis ( ) {
136
- if ( ! this . test_run_id ) {
140
+ async #attachFailureAnalysis ( ) {
141
+ if ( this . result . status !== 'FAIL' ) {
137
142
return ;
138
143
}
139
- if ( ! this . config . targets ) {
144
+ if ( this . config . show_failure_analysis === false ) {
140
145
return ;
141
146
}
147
+ try {
148
+ logger . info ( '🪄 Fetching Failure Analysis...' ) ;
149
+ await this . #setTestRun( 'Failure Analysis Status' , 'failure_analysis_status' ) ;
150
+ this . config . extensions . push ( {
151
+ name : 'failure-analysis' ,
152
+ hook : HOOK . AFTER_SUMMARY ,
153
+ inputs : {
154
+ data : this . test_run
155
+ }
156
+ } ) ;
157
+ } catch ( error ) {
158
+ logger . error ( `❌ Unable to attach failure analysis: ${ error . message } ` , error ) ;
159
+ }
160
+ }
161
+
162
+ async #attachSmartAnalysis( ) {
142
163
if ( this . config . show_smart_analysis === false ) {
143
164
return ;
144
165
}
@@ -165,7 +186,7 @@ class Beats {
165
186
}
166
187
167
188
async #setTestRun( text , wait_for = 'smart_analysis_status' ) {
168
- if ( this . test_run && this . test_run [ wait_for ] === ' COMPLETED' ) {
189
+ if ( this . test_run && this . test_run [ wait_for ] === PROCESS_STATUS . COMPLETED ) {
169
190
return ;
170
191
}
171
192
let retry = 3 ;
@@ -175,13 +196,13 @@ class Beats {
175
196
this . test_run = await this . api . getTestRun ( this . test_run_id ) ;
176
197
const status = this . test_run && this . test_run [ wait_for ] ;
177
198
switch ( status ) {
178
- case ' COMPLETED' :
199
+ case PROCESS_STATUS . COMPLETED :
179
200
logger . debug ( `☑️ ${ text } generated successfully` ) ;
180
201
return ;
181
- case ' FAILED' :
202
+ case PROCESS_STATUS . FAILED :
182
203
logger . error ( `❌ Failed to generate ${ text } ` ) ;
183
204
return ;
184
- case ' SKIPPED' :
205
+ case PROCESS_STATUS . SKIPPED :
185
206
logger . warn ( `❗ Skipped generating ${ text } ` ) ;
186
207
return ;
187
208
}
@@ -191,12 +212,6 @@ class Beats {
191
212
}
192
213
193
214
async #attachErrorClusters( ) {
194
- if ( ! this . test_run_id ) {
195
- return ;
196
- }
197
- if ( ! this . config . targets ) {
198
- return ;
199
- }
200
215
if ( this . result . status !== 'FAIL' ) {
201
216
return ;
202
217
}
0 commit comments