Add createCheck to display test results in GitHub UI

pull/97/head
David Finol 2021-02-22 15:49:04 -06:00
parent c838b9cba9
commit 94d2fc0be4
4 changed files with 99 additions and 97 deletions

File diff suppressed because one or more lines are too long

View File

@ -15,6 +15,7 @@ class ReportConverter {
meta.duration = Number(run._attributes.duration); meta.duration = Number(run._attributes.duration);
meta.addTests(ReportConverter.convertSuite(run['test-suite'])); meta.addTests(ReportConverter.convertSuite(run['test-suite']));
core.info(`meta length ${meta.suites.length}`);
return meta; return meta;
} }
@ -40,6 +41,7 @@ class ReportConverter {
result.push(...ReportConverter.convertTests(suites._attributes.fullname, tests)); result.push(...ReportConverter.convertTests(suites._attributes.fullname, tests));
} }
core.info(`result length ${result.length}`);
return result; return result;
} }

View File

@ -24,15 +24,15 @@ class ResultsCheck {
// Prepare run summary // Prepare run summary
const runSummary = new RunMeta('Test Results'); const runSummary = new RunMeta('Test Results');
runs.forEach(suite => { runs.forEach(run => {
runSummary.total += suite.total; runSummary.total += run.total;
runSummary.passed += suite.passed; runSummary.passed += run.passed;
runSummary.skipped += suite.skipped; runSummary.skipped += run.skipped;
runSummary.failed += suite.failed; runSummary.failed += run.failed;
runSummary.duration += suite.duration; runSummary.duration += run.duration;
core.info(suite.suites.length); core.info(`Run suites length ${run.suites.length}`);
suite.suites.forEach(s => { run.suites.forEach(suite => {
runSummary.addTests(s.tests); runSummary.addTests(suite.tests);
}); });
}); });

View File

@ -1,118 +1,118 @@
import {components} from '@octokit/openapi-types/generated/types'; import { components } from '@octokit/openapi-types/generated/types';
export function timeHelper(seconds: number): string { export function timeHelper(seconds: number): string {
return `${seconds.toFixed(3)}s`; return `${seconds.toFixed(3)}s`;
} }
export abstract class Meta { export abstract class Meta {
title: string; title: string;
duration = 0; duration = 0;
constructor(title: string) { constructor(title: string) {
this.title = title; this.title = title;
} }
abstract get summary(): string; abstract get summary(): string;
abstract get mark(): string; abstract get mark(): string;
} }
export class RunMeta extends Meta { export class RunMeta extends Meta {
total = 0; total = 0;
passed = 0; passed = 0;
skipped = 0; skipped = 0;
failed = 0; failed = 0;
tests: TestMeta[] = []; tests: TestMeta[] = [];
suites: RunMeta[] = []; suites: RunMeta[] = [];
extractAnnotations(): Annotation[] { extractAnnotations(): Annotation[] {
const result = [] as Annotation[]; const result = [] as Annotation[];
for (const suite of this.suites) { for (const suite of this.suites) {
result.push(...suite.extractAnnotations()); result.push(...suite.extractAnnotations());
} }
for (const test of this.tests) { for (const test of this.tests) {
if (test.annotation !== undefined) { if (test.annotation !== undefined) {
result.push(test.annotation); result.push(test.annotation);
} }
} }
return result; return result;
}
addTests(testsToAdd: TestMeta[]): void {
testsToAdd.forEach(test => {
this.addTest(test);
});
}
addTest(test: TestMeta): void {
if (test.suite === undefined) {
return;
}
if (test.suite === this.title) {
this.total++;
this.duration += test.duration;
this.tests.push(test);
if (test.result === 'Passed') this.passed++;
else if (test.result === 'Failed') this.failed++;
else this.skipped++;
return;
} }
addTests(children: TestMeta[]): void { let target = this.suites.find(s => s.title === test.suite);
for (const child of children) { if (target === undefined) {
this.addTest(child); target = new RunMeta(test.suite);
} this.suites.push(target);
} }
addTest(test: TestMeta): void { target.addTest(test);
if (test.suite === undefined) { }
return;
}
if (test.suite === this.title) {
this.total++;
this.duration += test.duration;
this.tests.push(test);
if (test.result === 'Passed') this.passed++;
else if (test.result === 'Failed') this.failed++;
else this.skipped++;
return;
}
let target = this.suites.find(s => s.title === test.suite); get summary(): string {
if (target === undefined) { const result = this.failed > 0 ? 'Failed' : 'Passed';
target = new RunMeta(test.suite); const sPart = this.skipped > 0 ? `, skipped: ${this.skipped}` : '';
this.suites.push(target); const fPart = this.failed > 0 ? `, failed: ${this.failed}` : '';
} const dPart = ` in ${timeHelper(this.duration)}`;
return `${this.mark} ${this.title} - ${this.passed}/${this.total}${sPart}${fPart} - ${result}${dPart}`;
}
target.addTest(test); get mark(): string {
} if (this.failed > 0) return '❌️';
else if (this.skipped === 0) return '✔️';
get summary(): string { return '⚠️';
const result = this.failed > 0 ? 'Failed' : 'Passed'; }
const sPart = this.skipped > 0 ? `, skipped: ${this.skipped}` : '';
const fPart = this.failed > 0 ? `, failed: ${this.failed}` : '';
const dPart = ` in ${timeHelper(this.duration)}`;
return `${this.mark} ${this.title} - ${this.passed}/${this.total}${sPart}${fPart} - ${result}${dPart}`;
}
get mark(): string {
if (this.failed > 0) return '❌️';
else if (this.skipped === 0) return '✔️';
return '⚠️';
}
} }
export class TestMeta extends Meta { export class TestMeta extends Meta {
suite: string; suite: string;
result: string | undefined; result: string | undefined;
annotation: Annotation | undefined; annotation: Annotation | undefined;
constructor(suite: string, title: string) { constructor(suite: string, title: string) {
super(title); super(title);
this.suite = suite; this.suite = suite;
} }
isSkipped(): boolean { isSkipped(): boolean {
return this.result === 'Skipped'; return this.result === 'Skipped';
} }
isFailed(): boolean { isFailed(): boolean {
return this.result === 'Failed'; return this.result === 'Failed';
} }
get summary(): string { get summary(): string {
const dPart = this.isSkipped() const dPart = this.isSkipped()
? '' ? ''
: ` in ${timeHelper(this.duration)}`; : ` in ${timeHelper(this.duration)}`;
return `${this.mark} **${this.title}** - ${this.result}${dPart}`; return `${this.mark} **${this.title}** - ${this.result}${dPart}`;
} }
get mark(): string { get mark(): string {
if (this.isFailed()) return '❌️'; if (this.isFailed()) return '❌️';
else if (this.isSkipped()) return '⚠️'; else if (this.isSkipped()) return '⚠️';
return '✔️'; return '✔️';
} }
} }
export type Annotation = components['schemas']['check-annotation']; export type Annotation = components['schemas']['check-annotation'];