Skip to content

Commit

Permalink
Sending test cases results
Browse files Browse the repository at this point in the history
  • Loading branch information
Fgerthoffert committed Nov 25, 2024
1 parent 806d4b3 commit 000922c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/commands/zencrepes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,17 @@ class JahiaTestrailReporter extends Command {
let dependencies = JSON.parse(flags.dependencies)
let name = flags.name
let version = flags.version
let jahiaFullVersion = ''
let moduleVersion = ''
if (flags.moduleFilepath !== undefined) {
const versionFile: any = fs.readFileSync(flags.moduleFilepath)
const versions: UtilsVersions = JSON.parse(versionFile)
if (versions.jahia.fullVersion !== '') {
jahiaFullVersion = versions.jahia.fullVersion
}
if (versions.module.id !== '' && versions.module.version !== '') {
moduleVersion = `${versions.module.id}-${versions.module.version}`
}
if (versions.jahia.build === '') {
dependencies.push({name: 'Jahia', version: versions.jahia.version})
} else {
Expand All @@ -103,6 +111,31 @@ class JahiaTestrailReporter extends Command {
name = versions.module.id
}

// Get all individual test cases in an array
const testCases: any = []
for (const r of report.reports) {
for (const suite of r.testsuites) {
for (const test of suite.tests) {
testCases.push({
id: getId(test.name, flags.version, dependencies),
name: test.name,
suite: suite.name,
duration: test.time,
state: test.status,
jahia: jahiaFullVersion,
module: moduleVersion,
caseTotal: 1, // Hack to fit in Zencrepes ZUI existing data model
caseSuccess: test.status === 'PASS' ? 1 : 0,
caseFailure: test.status === 'FAIL' ? 1 : 0,
createdAt: r.timestamp === undefined ? new Date().toISOString() : new Date(r.timestamp).toISOString(),
})
}
}
}
// const testCases = report.reports.reduce((acc: any, report: any) => {
// console.log(report)
// }, [])

// From the report object, format the payload to be sent to ZenCrepes webhook (zqueue)
const zcPayload: ZenCrepesStateNode = {
id: getId(name, flags.version, dependencies),
Expand All @@ -112,6 +145,7 @@ class JahiaTestrailReporter extends Command {
createdAt: new Date().toISOString(),
state: report.failures === 0 ? 'PASS' : 'FAIL',
url: flags.runUrl,
cases: testCases,
runTotal: report.tests,
runSuccess: report.tests - report.failures,
runFailure: report.failures,
Expand Down
11 changes: 11 additions & 0 deletions src/global.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface JRReport {
skipped: number;
pending: number;
time: number;
timestamp?: string;
testsuites: JRTestsuite[];
}

Expand All @@ -42,6 +43,15 @@ export interface JRRun {
reports: JRReport[];
}

// A run is composed of multiple junit files
export interface JRCase {
id: string;
name: string;
suite: string;
duration: number;
statis: string;
}

export interface ZenCrepesDependency {
id: string;
name: string;
Expand All @@ -58,6 +68,7 @@ export interface ZenCrepesStateNode {
dependencies: ZenCrepesDependency[];
createdAt: string;
state: string;
cases: JRCase[];
url: string;
runTotal: number;
runSuccess: number;
Expand Down

0 comments on commit 000922c

Please sign in to comment.