Add test results to CI Table

This commit is contained in:
Tim Jacomb
2020-08-04 09:27:31 +01:00
committed by Fredrik Adelöw
parent c85e952300
commit 547604d973
2 changed files with 104 additions and 0 deletions
+27
View File
@@ -103,6 +103,32 @@ export class JenkinsApi {
return results;
}
private getTestReport(
jenkinsResult: any,
): {
total: number;
passed: number;
skipped: number;
failed: number;
testUrl: string;
} {
return jenkinsResult.actions
.filter(
(action: any) =>
action._class === 'hudson.tasks.junit.TestResultAction',
)
.map((action: any) => {
return {
total: action.totalCount,
passed: action.totalCount - action.failCount - action.skipCount,
skipped: action.skipCount,
failed: action.failCount,
testUrl: `${jenkinsResult.url}${action.urlName}/`,
};
})
.pop();
}
mapJenkinsBuildToCITable(
jenkinsResult: any,
jobScmInfo?: any,
@@ -142,6 +168,7 @@ export class JenkinsApi {
return this.retry(jobName);
},
source: source,
tests: this.getTestReport(jenkinsResult),
};
}
@@ -44,6 +44,61 @@ export type CITableBuildInfo = {
onRestartClick: () => void;
};
const FailCount = ({ count }: { count: number }): JSX.Element | null => {
if (count !== 0) {
return <>{count} failed</>;
}
return null;
};
const SkippedCount = ({ count }: { count: number }): JSX.Element | null => {
if (count !== 0) {
return <></>;
}
return null;
};
const FailSkippedWidget = ({
skipped,
failed,
}: {
skipped: number;
failed: number;
}): JSX.Element | null => {
if (skipped === 0 && failed === 0) {
return null;
}
if (skipped !== 0 && failed !== 0) {
return (
<>
{' '}
(<FailCount count={failed} />, <SkippedCount count={skipped} />)
</>
);
}
if (failed !== 0) {
return (
<>
{' '}
(<FailCount count={failed} />)
</>
);
}
if (skipped !== 0) {
return (
<>
{' '}
(<SkippedCount count={skipped} />)
</>
);
}
return null;
};
const generatedColumns: TableColumn[] = [
{
title: 'Build',
@@ -78,6 +133,28 @@ const generatedColumns: TableColumn[] = [
);
},
},
{
title: 'Tests',
render: (row: Partial<CITableBuildInfo>) => {
return (
<>
<p>
{row.tests && (
<Link href={row.tests.testUrl || ''} target="_blank">
{row.tests.passed} / {row.tests.total} passed
<FailSkippedWidget
skipped={row.tests.skipped}
failed={row.tests.failed}
/>
</Link>
)}
{!row.tests && 'n/a'}
</p>
</>
);
},
},
{
title: 'Actions',
render: (row: Partial<CITableBuildInfo>) => (