@@ -5,6 +5,7 @@ import Maestro, {
55} from '../../src/providers/maestro' ;
66import MaestroOptions from '../../src/models/maestro_options' ;
77import TestingBotError from '../../src/models/testingbot_error' ;
8+ import logger from '../../src/logger' ;
89import fs from 'node:fs' ;
910import path from 'node:path' ;
1011import axios from 'axios' ;
@@ -4627,6 +4628,153 @@ flows:
46274628
46284629 consoleSpy . mockRestore ( ) ;
46294630 } ) ;
4631+
4632+ it ( 'should report failed flow count and run count when flows fail' , async ( ) => {
4633+ const consoleSpy = jest . spyOn ( console , 'log' ) . mockImplementation ( ) ;
4634+ const errorSpy = jest . spyOn ( logger , 'error' ) . mockImplementation ( ) ;
4635+
4636+ const responseWithMultipleFailedFlows = {
4637+ data : {
4638+ runs : [
4639+ {
4640+ id : 5678 ,
4641+ status : 'DONE' ,
4642+ capabilities : { deviceName : 'Pixel 9' , platformName : 'Android' } ,
4643+ success : 0 ,
4644+ flows : [
4645+ { id : 1 , name : 'a.yaml' , status : 'DONE' , success : 1 } ,
4646+ { id : 2 , name : 'b.yaml' , status : 'DONE' , success : 0 } ,
4647+ { id : 3 , name : 'c.yaml' , status : 'DONE' , success : 0 } ,
4648+ { id : 4 , name : 'd.yaml' , status : 'FAILED' , success : 0 } ,
4649+ ] ,
4650+ } ,
4651+ ] ,
4652+ success : false ,
4653+ completed : true ,
4654+ } ,
4655+ } ;
4656+ axios . get = jest . fn ( ) . mockResolvedValue ( responseWithMultipleFailedFlows ) ;
4657+
4658+ await maestro [ 'waitForCompletion' ] ( ) ;
4659+
4660+ expect ( errorSpy ) . toHaveBeenCalledWith (
4661+ '3 flow(s) failed across 1 run(s)' ,
4662+ ) ;
4663+
4664+ consoleSpy . mockRestore ( ) ;
4665+ errorSpy . mockRestore ( ) ;
4666+ } ) ;
4667+
4668+ it ( 'should aggregate failed flow counts across multiple failed runs' , async ( ) => {
4669+ const consoleSpy = jest . spyOn ( console , 'log' ) . mockImplementation ( ) ;
4670+ const errorSpy = jest . spyOn ( logger , 'error' ) . mockImplementation ( ) ;
4671+
4672+ const responseMultipleFailingRuns = {
4673+ data : {
4674+ runs : [
4675+ {
4676+ id : 1 ,
4677+ status : 'DONE' ,
4678+ capabilities : { deviceName : 'Pixel 9' , platformName : 'Android' } ,
4679+ success : 0 ,
4680+ flows : [
4681+ { id : 1 , name : 'a.yaml' , status : 'DONE' , success : 0 } ,
4682+ { id : 2 , name : 'b.yaml' , status : 'DONE' , success : 1 } ,
4683+ ] ,
4684+ } ,
4685+ {
4686+ id : 2 ,
4687+ status : 'DONE' ,
4688+ capabilities : { deviceName : 'iPhone 15' , platformName : 'iOS' } ,
4689+ success : 0 ,
4690+ flows : [
4691+ { id : 3 , name : 'c.yaml' , status : 'DONE' , success : 0 } ,
4692+ { id : 4 , name : 'd.yaml' , status : 'FAILED' , success : 0 } ,
4693+ ] ,
4694+ } ,
4695+ ] ,
4696+ success : false ,
4697+ completed : true ,
4698+ } ,
4699+ } ;
4700+ axios . get = jest . fn ( ) . mockResolvedValue ( responseMultipleFailingRuns ) ;
4701+
4702+ await maestro [ 'waitForCompletion' ] ( ) ;
4703+
4704+ expect ( errorSpy ) . toHaveBeenCalledWith (
4705+ '3 flow(s) failed across 2 run(s)' ,
4706+ ) ;
4707+
4708+ consoleSpy . mockRestore ( ) ;
4709+ errorSpy . mockRestore ( ) ;
4710+ } ) ;
4711+
4712+ it ( 'should fall back to run count when failed run has no flows' , async ( ) => {
4713+ const consoleSpy = jest . spyOn ( console , 'log' ) . mockImplementation ( ) ;
4714+ const errorSpy = jest . spyOn ( logger , 'error' ) . mockImplementation ( ) ;
4715+
4716+ const responseRunFailedNoFlows = {
4717+ data : {
4718+ runs : [
4719+ {
4720+ id : 5678 ,
4721+ status : 'DONE' ,
4722+ capabilities : { deviceName : 'Pixel 9' , platformName : 'Android' } ,
4723+ success : 0 ,
4724+ } ,
4725+ ] ,
4726+ success : false ,
4727+ completed : true ,
4728+ } ,
4729+ } ;
4730+ axios . get = jest . fn ( ) . mockResolvedValue ( responseRunFailedNoFlows ) ;
4731+
4732+ await maestro [ 'waitForCompletion' ] ( ) ;
4733+
4734+ expect ( errorSpy ) . toHaveBeenCalledWith ( '1 test run(s) failed' ) ;
4735+
4736+ consoleSpy . mockRestore ( ) ;
4737+ errorSpy . mockRestore ( ) ;
4738+ } ) ;
4739+
4740+ it ( 'should treat flows with error_messages as failed even if success is 1' , async ( ) => {
4741+ const consoleSpy = jest . spyOn ( console , 'log' ) . mockImplementation ( ) ;
4742+ const errorSpy = jest . spyOn ( logger , 'error' ) . mockImplementation ( ) ;
4743+
4744+ const responseFlowWithErrors = {
4745+ data : {
4746+ runs : [
4747+ {
4748+ id : 5678 ,
4749+ status : 'DONE' ,
4750+ capabilities : { deviceName : 'Pixel 9' , platformName : 'Android' } ,
4751+ success : 0 ,
4752+ flows : [
4753+ {
4754+ id : 1 ,
4755+ name : 'flaky.yaml' ,
4756+ status : 'DONE' ,
4757+ success : 1 ,
4758+ error_messages : [ 'Element not found' ] ,
4759+ } ,
4760+ ] ,
4761+ } ,
4762+ ] ,
4763+ success : false ,
4764+ completed : true ,
4765+ } ,
4766+ } ;
4767+ axios . get = jest . fn ( ) . mockResolvedValue ( responseFlowWithErrors ) ;
4768+
4769+ await maestro [ 'waitForCompletion' ] ( ) ;
4770+
4771+ expect ( errorSpy ) . toHaveBeenCalledWith (
4772+ '1 flow(s) failed across 1 run(s)' ,
4773+ ) ;
4774+
4775+ consoleSpy . mockRestore ( ) ;
4776+ errorSpy . mockRestore ( ) ;
4777+ } ) ;
46304778 } ) ;
46314779
46324780 describe ( 'extractErrorMessage' , ( ) => {
0 commit comments