Skip to content

Commit bac5fb2

Browse files
improve report after maestro test run
1 parent 4c076a7 commit bac5fb2

2 files changed

Lines changed: 165 additions & 2 deletions

File tree

src/providers/maestro.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,8 +1820,23 @@ export default class Maestro extends BaseProvider<MaestroOptions> {
18201820
}
18211821
} else {
18221822
const failedRuns = status.runs.filter((run) => run.success !== 1);
1823-
setTitle(`maestro · ✘ ${failedRuns.length} failed`);
1824-
logger.error(`${failedRuns.length} test run(s) failed`);
1823+
const failedFlows = status.runs
1824+
.flatMap((run) => run.flows ?? [])
1825+
.filter(
1826+
(flow) =>
1827+
(flow.status === 'DONE' && flow.success !== 1) ||
1828+
flow.status === 'FAILED' ||
1829+
(flow.error_messages && flow.error_messages.length > 0),
1830+
);
1831+
if (failedFlows.length > 0) {
1832+
setTitle(`maestro · ✘ ${failedFlows.length} failed`);
1833+
logger.error(
1834+
`${failedFlows.length} flow(s) failed across ${failedRuns.length} run(s)`,
1835+
);
1836+
} else {
1837+
setTitle(`maestro · ✘ ${failedRuns.length} failed`);
1838+
logger.error(`${failedRuns.length} test run(s) failed`);
1839+
}
18251840
}
18261841

18271842
if (this.options.report && this.options.reportOutputDir) {

tests/providers/maestro.test.ts

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Maestro, {
55
} from '../../src/providers/maestro';
66
import MaestroOptions from '../../src/models/maestro_options';
77
import TestingBotError from '../../src/models/testingbot_error';
8+
import logger from '../../src/logger';
89
import fs from 'node:fs';
910
import path from 'node:path';
1011
import 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

Comments
 (0)