@@ -123,6 +123,20 @@ const runTests = async (): Promise<void> => {
123
123
}
124
124
} ;
125
125
126
+ const skippedTests : string [ ] = [ ] ;
127
+ const clearTestResults = ( test : TestConfig ) => {
128
+ skippedTests . push ( test . name ) ;
129
+
130
+ Object . keys ( results ) . forEach ( ( branch : string ) => {
131
+ Object . keys ( results [ branch ] ) . forEach ( ( metric : string ) => {
132
+ if ( ! metric . startsWith ( test . name ) ) {
133
+ return ;
134
+ }
135
+ delete results [ branch ] [ metric ] ;
136
+ } ) ;
137
+ } ) ;
138
+ } ;
139
+
126
140
// Collect results while tests are being executed
127
141
server . addTestResultListener ( ( testResult ) => {
128
142
const { isCritical = true } = testResult ;
@@ -151,7 +165,7 @@ const runTests = async (): Promise<void> => {
151
165
await launchApp ( 'android' , appPackage , config . ACTIVITY_PATH , launchArgs ) ;
152
166
153
167
const { promise, resetTimeout} = withFailTimeout (
154
- new Promise < void > ( ( resolve ) => {
168
+ new Promise < void > ( ( resolve , reject ) => {
155
169
const removeListener = server . addTestDoneListener ( ( ) => {
156
170
Logger . success ( iterationText ) ;
157
171
@@ -201,9 +215,14 @@ const runTests = async (): Promise<void> => {
201
215
removeListener ( ) ;
202
216
// something went wrong, let's wait a little bit and try again
203
217
await sleep ( 5000 ) ;
204
- // simply restart the test
205
- await runTestIteration ( appPackage , iterationText , branch , launchArgs ) ;
206
- resolve ( ) ;
218
+ try {
219
+ // simply restart the test
220
+ await runTestIteration ( appPackage , iterationText , branch , launchArgs ) ;
221
+ resolve ( ) ;
222
+ } catch ( e ) {
223
+ // okay, give up and throw the exception further
224
+ reject ( e ) ;
225
+ }
207
226
} ,
208
227
} ) ;
209
228
} ) ,
@@ -244,88 +263,103 @@ const runTests = async (): Promise<void> => {
244
263
server . setTestConfig ( test as TestConfig ) ;
245
264
server . setReadyToAcceptTestResults ( false ) ;
246
265
247
- const warmupText = `Warmup for test '${ test ?. name } ' [${ testIndex + 1 } /${ tests . length } ]` ;
248
-
249
- // For each warmup we allow the warmup to fail three times before we stop the warmup run:
250
- const errorCountWarmupRef = {
251
- errorCount : 0 ,
252
- allowedExceptions : 3 ,
253
- } ;
254
-
255
- // by default we do 2 warmups:
256
- // - first warmup to pass a login flow
257
- // - second warmup to pass an actual flow and cache network requests
258
- const iterations = 2 ;
259
- for ( let i = 0 ; i < iterations ; i ++ ) {
260
- try {
261
- // Warmup the main app:
262
- await runTestIteration ( config . MAIN_APP_PACKAGE , `[MAIN] ${ warmupText } . Iteration ${ i + 1 } /${ iterations } ` , config . BRANCH_MAIN ) ;
263
-
264
- // Warmup the delta app:
265
- await runTestIteration ( config . DELTA_APP_PACKAGE , `[DELTA] ${ warmupText } . Iteration ${ i + 1 } /${ iterations } ` , config . BRANCH_DELTA ) ;
266
- } catch ( e ) {
267
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
268
- Logger . error ( `Warmup failed with error: ${ e } ` ) ;
269
-
270
- errorCountWarmupRef . errorCount ++ ;
271
- i -- ; // repeat warmup again
272
-
273
- if ( errorCountWarmupRef . errorCount === errorCountWarmupRef . allowedExceptions ) {
274
- Logger . error ( "There was an error running the warmup and we've reached the maximum number of allowed exceptions. Stopping the test run." ) ;
275
- throw e ;
266
+ try {
267
+ const warmupText = `Warmup for test '${ test ?. name } ' [${ testIndex + 1 } /${ tests . length } ]` ;
268
+
269
+ // For each warmup we allow the warmup to fail three times before we stop the warmup run:
270
+ const errorCountWarmupRef = {
271
+ errorCount : 0 ,
272
+ allowedExceptions : 3 ,
273
+ } ;
274
+
275
+ // by default we do 2 warmups:
276
+ // - first warmup to pass a login flow
277
+ // - second warmup to pass an actual flow and cache network requests
278
+ const iterations = 2 ;
279
+ for ( let i = 0 ; i < iterations ; i ++ ) {
280
+ try {
281
+ // Warmup the main app:
282
+ await runTestIteration ( config . MAIN_APP_PACKAGE , `[MAIN] ${ warmupText } . Iteration ${ i + 1 } /${ iterations } ` , config . BRANCH_MAIN ) ;
283
+
284
+ // Warmup the delta app:
285
+ await runTestIteration ( config . DELTA_APP_PACKAGE , `[DELTA] ${ warmupText } . Iteration ${ i + 1 } /${ iterations } ` , config . BRANCH_DELTA ) ;
286
+ } catch ( e ) {
287
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
288
+ Logger . error ( `Warmup failed with error: ${ e } ` ) ;
289
+
290
+ MeasureUtils . stop ( 'error-warmup' ) ;
291
+ server . clearAllTestDoneListeners ( ) ;
292
+
293
+ errorCountWarmupRef . errorCount ++ ;
294
+ i -- ; // repeat warmup again
295
+
296
+ if ( errorCountWarmupRef . errorCount === errorCountWarmupRef . allowedExceptions ) {
297
+ Logger . error ( "There was an error running the warmup and we've reached the maximum number of allowed exceptions. Stopping the test run." ) ;
298
+ throw e ;
299
+ }
276
300
}
277
301
}
278
- }
279
302
280
- server . setReadyToAcceptTestResults ( true ) ;
281
-
282
- // For each test case we allow the test to fail three times before we stop the test run:
283
- const errorCountRef = {
284
- errorCount : 0 ,
285
- allowedExceptions : 3 ,
286
- } ;
287
-
288
- // We run each test multiple time to average out the results
289
- for ( let testIteration = 0 ; testIteration < config . RUNS ; testIteration ++ ) {
290
- const onError = ( e : Error ) => {
291
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
292
- Logger . error ( `Unexpected error during test execution: ${ e } . ` ) ;
293
- MeasureUtils . stop ( 'error' ) ;
294
- server . clearAllTestDoneListeners ( ) ;
295
- errorCountRef . errorCount += 1 ;
296
- if ( testIteration === 0 || errorCountRef . errorCount === errorCountRef . allowedExceptions ) {
297
- Logger . error ( "There was an error running the test and we've reached the maximum number of allowed exceptions. Stopping the test run." ) ;
298
- // If the error happened on the first test run, the test is broken
299
- // and we should not continue running it. Or if we have reached the
300
- // maximum number of allowed exceptions, we should stop the test run.
301
- throw e ;
302
- }
303
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
304
- Logger . warn ( `There was an error running the test. Continuing the test run. Error: ${ e } ` ) ;
305
- } ;
303
+ server . setReadyToAcceptTestResults ( true ) ;
306
304
307
- const launchArgs = {
308
- mockNetwork : true ,
305
+ // For each test case we allow the test to fail three times before we stop the test run:
306
+ const errorCountRef = {
307
+ errorCount : 0 ,
308
+ allowedExceptions : 3 ,
309
309
} ;
310
310
311
- const iterationText = `Test '${ test ?. name } ' [${ testIndex + 1 } /${ tests . length } ], iteration [${ testIteration + 1 } /${ config . RUNS } ]` ;
312
- const mainIterationText = `[MAIN] ${ iterationText } ` ;
313
- const deltaIterationText = `[DELTA] ${ iterationText } ` ;
314
- try {
315
- // Run the test on the main app:
316
- await runTestIteration ( config . MAIN_APP_PACKAGE , mainIterationText , config . BRANCH_MAIN , launchArgs ) ;
317
-
318
- // Run the test on the delta app:
319
- await runTestIteration ( config . DELTA_APP_PACKAGE , deltaIterationText , config . BRANCH_DELTA , launchArgs ) ;
320
- } catch ( e ) {
321
- onError ( e as Error ) ;
311
+ // We run each test multiple time to average out the results
312
+ for ( let testIteration = 0 ; testIteration < config . RUNS ; testIteration ++ ) {
313
+ const onError = ( e : Error ) => {
314
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
315
+ Logger . error ( `Unexpected error during test execution: ${ e } . ` ) ;
316
+ MeasureUtils . stop ( 'error' ) ;
317
+ server . clearAllTestDoneListeners ( ) ;
318
+ errorCountRef . errorCount += 1 ;
319
+ if ( testIteration === 0 || errorCountRef . errorCount === errorCountRef . allowedExceptions ) {
320
+ Logger . error ( "There was an error running the test and we've reached the maximum number of allowed exceptions. Stopping the test run." ) ;
321
+ // If the error happened on the first test run, the test is broken
322
+ // and we should not continue running it. Or if we have reached the
323
+ // maximum number of allowed exceptions, we should stop the test run.
324
+ throw e ;
325
+ }
326
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
327
+ Logger . warn ( `There was an error running the test. Continuing the test run. Error: ${ e } ` ) ;
328
+ } ;
329
+
330
+ const launchArgs = {
331
+ mockNetwork : true ,
332
+ } ;
333
+
334
+ const iterationText = `Test '${ test ?. name } ' [${ testIndex + 1 } /${ tests . length } ], iteration [${ testIteration + 1 } /${ config . RUNS } ]` ;
335
+ const mainIterationText = `[MAIN] ${ iterationText } ` ;
336
+ const deltaIterationText = `[DELTA] ${ iterationText } ` ;
337
+ try {
338
+ // Run the test on the main app:
339
+ await runTestIteration ( config . MAIN_APP_PACKAGE , mainIterationText , config . BRANCH_MAIN , launchArgs ) ;
340
+
341
+ // Run the test on the delta app:
342
+ await runTestIteration ( config . DELTA_APP_PACKAGE , deltaIterationText , config . BRANCH_DELTA , launchArgs ) ;
343
+ } catch ( e ) {
344
+ onError ( e as Error ) ;
345
+ }
322
346
}
347
+ } catch ( exception ) {
348
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
349
+ Logger . warn ( `Test ${ test ?. name } can not be finished due to error: ${ exception } ` ) ;
350
+ clearTestResults ( test as TestConfig ) ;
323
351
}
324
352
}
325
353
326
354
// Calculate statistics and write them to our work file
327
355
Logger . info ( 'Calculating statics and writing results' ) ;
328
- compare ( results . main , results . delta , `${ config . OUTPUT_DIR } /output.md` , 'all' , metricForTest ) ;
356
+ await compare ( results . main , results . delta , {
357
+ outputFile : `${ config . OUTPUT_DIR } /output.md` ,
358
+ outputFormat : 'all' ,
359
+ metricForTest,
360
+ skippedTests,
361
+ } ) ;
362
+ Logger . info ( 'Finished calculating statics and writing results, stopping the test server' ) ;
329
363
330
364
await server . stop ( ) ;
331
365
} ;
0 commit comments