Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing many test suites on file #9

Closed
wants to merge 21 commits into from
68 changes: 40 additions & 28 deletions src/junitParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ interface JUnitSuite {
}
interface JUnitReport {
testsuite?: JUnitSuite;
testsuites?: { testsuite?: JUnitSuite };
testsuites?: { testsuite?: JUnitSuite | JUnitSuite[] };
atlowChemi marked this conversation as resolved.
Show resolved Hide resolved
}

async function parseFile(file: string, projectTokenDictionaryStrs: string[]) {
Expand All @@ -70,26 +70,36 @@ async function parseFile(file: string, projectTokenDictionaryStrs: string[]) {
const data: string = fs.readFileSync(file, 'utf8');
const parser = new XMLParser({ allowBooleanAttributes: true, ignoreAttributes: false, attributeNamePrefix: '' });
const report = parser.parse(data) as Partial<JUnitReport>;

return parseSuite(report, file, projectTokenDictionaryStrs);
const testsuites = castArray(report.testsuites?.testsuite);
const result: InternalTestResult[] = [];
for (const testsuite of testsuites) {
await parseSuite(file, projectTokenDictionaryStrs, testsuite as JUnitSuite, result);
}
return result;
ETtestim marked this conversation as resolved.
Show resolved Hide resolved
}

async function parseSuite(report: JUnitReport, fileName: string, projectTokenDictionaryStrs: string[]) {
const testsuite = report.testsuite || report.testsuites?.testsuite;
const result: InternalTestResult = { fileName, name: testsuite?.name, totalCount: 0, skipped: 0, failedEvaluating: parseInt(testsuite?.['failure-evaluating'] || '0') || 0, annotations: [] };
async function parseSuite(fileName: string, projectTokenDictionaryStrs: string[], testsuite: JUnitSuite, result: InternalTestResult[]) {
const testSuiteResult: InternalTestResult = {
fileName,
name: testsuite?.name,
totalCount: 0,
skipped: 0,
failedEvaluating: parseInt(testsuite?.['failure-evaluating'] || '0') || 0,
annotations: [],
};
if (!testsuite?.testcase) {
return result;
return result.push(testSuiteResult);
}

const testCases = castArray(testsuite.testcase);
const testListInfo = await getTestStatusesFromPublicAPI(testCases, projectTokenDictionaryStrs);

for (const { failure, skipped, name, ['system-out']: systemOut, classname } of testCases) {
result.totalCount++;
testSuiteResult.totalCount++;
const success = !failure;

if (typeof skipped !== 'undefined') {
result.skipped++;
testSuiteResult.skipped++;
}

const isTestimTest = systemOut?.startsWith('https://app.testim.io/#/project');
Expand All @@ -101,7 +111,7 @@ async function parseSuite(report: JUnitReport, fileName: string, projectTokenDic
annotation_level = testStatus === 'evaluating' ? 'warning' : 'failure';
}

result.annotations.push({
testSuiteResult.annotations.push({
testStatus,
isTestimTest,
annotation_level,
Expand All @@ -113,7 +123,7 @@ async function parseSuite(report: JUnitReport, fileName: string, projectTokenDic
start_line: 1,
});
}
return result;
return result.push(testSuiteResult);
}

async function parseTestReports(checkName: string, summary: string, reportPathsGlob: string, projectTokenDictionaryStrs: string[]) {
Expand All @@ -123,24 +133,26 @@ async function parseTestReports(checkName: string, summary: string, reportPathsG
const globber = await glob.create(reportPathsGlob);
for await (const file of globber.globGenerator()) {
core.info(`Parsing report file: ${file}`);

const { totalCount, skipped, annotations, failedEvaluating, name, fileName } = await parseFile(file, projectTokenDictionaryStrs);
if (totalCount === 0) {
continue;
const suites = await parseFile(file, projectTokenDictionaryStrs);
for (const suite of suites) {
ETtestim marked this conversation as resolved.
Show resolved Hide resolved
const { totalCount, skipped, annotations, failedEvaluating, name, fileName } = suite;
if (totalCount === 0) {
continue;
}
const failed = annotations.filter(an => an.annotation_level !== 'notice').length;
const passed = totalCount - failed - skipped;
testResults.push({
summary,
checkName: name || checkName,
fileName,
totalCount,
skipped,
failedEvaluating,
annotations,
failed,
passed,
});
}
const failed = annotations.filter(an => an.annotation_level !== 'notice').length;
const passed = totalCount - failed - skipped;
testResults.push({
summary,
checkName: name || checkName,
fileName,
totalCount,
skipped,
failedEvaluating,
annotations,
failed,
passed,
});
}

return testResults;
Expand Down