Skip to content

Commit e222a62

Browse files
committed
address comments
Signed-off-by: Ash Wu <hsatac@gmail.com>
1 parent 2c32bf1 commit e222a62

2 files changed

Lines changed: 10 additions & 22 deletions

File tree

packages/build-tools/src/steps/functions/__tests__/maestroResultParser.test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,18 +1075,17 @@ describe('mergeJUnitReports', () => {
10751075
).rejects.toThrow(/no \*\.xml files/);
10761076
});
10771077

1078-
it('throws when no parseable testcases are found across inputs', async () => {
1079-
// Malformed XML with no parseable <testsuite> / <testcase>. Without a
1080-
// throw here, mergeJUnitReports would silently emit an empty merged
1081-
// document and Phase 3's copyLatestAttemptXml fallback (which only
1082-
// triggers on throw) would never run.
1078+
it('throws on invalid XML so caller can fall back to copyLatestAttemptXml', async () => {
1079+
// Without a throw, mergeJUnitReports would silently emit an empty merged
1080+
// document and the copy-latest fallback (which only triggers on throw)
1081+
// would never run.
10831082
vol.fromJSON({
10841083
'/tmp/r/android-maestro-junit-attempt-0.xml': 'not xml at all',
10851084
});
10861085

10871086
await expect(
10881087
mergeJUnitReports({ sourceDir: '/tmp/r', outputPath: '/tmp/final.xml' })
1089-
).rejects.toThrow(/no parseable testcases/);
1088+
).rejects.toThrow(/invalid XML/);
10901089
});
10911090

10921091
it('throws when every input has <testsuites> but no <testcase> elements', async () => {

packages/build-tools/src/steps/functions/maestroResultParser.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -449,23 +449,19 @@ export async function mergeJUnitReports(args: {
449449
}))
450450
);
451451
const fileGroups: FileGroup[] = [];
452-
const skippedFiles: string[] = [];
453452
for (const { filename, content } of contents) {
454453
if (XMLValidator.validate(content) !== true) {
455-
skippedFiles.push(filename);
456-
continue;
454+
throw new Error(`mergeJUnitReports: invalid XML in ${filename}`);
457455
}
458456
let parsed: any;
459457
try {
460458
parsed = xmlParser.parse(content);
461-
} catch {
462-
skippedFiles.push(filename);
463-
continue;
459+
} catch (err) {
460+
throw new Error(`mergeJUnitReports: failed to parse ${filename}`, { cause: err });
464461
}
465462
const testsuites = parsed?.testsuites?.testsuite;
466463
if (!Array.isArray(testsuites)) {
467-
skippedFiles.push(filename);
468-
continue;
464+
throw new Error(`mergeJUnitReports: no <testsuite> array in ${filename}`);
469465
}
470466
const match = filename.match(ATTEMPT_PATTERN);
471467
const attemptIndex = match ? parseInt(match[1], 10) : 0;
@@ -486,18 +482,11 @@ export async function mergeJUnitReports(args: {
486482
}
487483
}
488484
if (testcasesByName.size === 0) {
489-
skippedFiles.push(filename);
490-
continue;
485+
throw new Error(`mergeJUnitReports: no parseable testcases in ${filename}`);
491486
}
492487
fileGroups.push({ attemptIndex, filename, content, testcasesByName });
493488
}
494489

495-
if (skippedFiles.length > 0) {
496-
throw new Error(
497-
`mergeJUnitReports: no parseable testcases found in ${skippedFiles.join(', ')}`
498-
);
499-
}
500-
501490
// Single attempt: copy the original XML so suite-level metadata (testsuite
502491
// attributes, <system-out>, etc.) survives. The rebuild path below would
503492
// collapse those to a single attribute-less <testsuite>.

0 commit comments

Comments
 (0)