-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace example with proper report parsing
- Loading branch information
Showing
8 changed files
with
392 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,147 @@ | ||
import { | ||
ReportsReportCheckedRequirement, | ||
ReportsReportRequirementsCheckedConditionEvaluationReport, | ||
ReportsReportTestRunReport, | ||
ReportsReportTestSuiteActionReport, | ||
ReportsReportTestSuiteReport, | ||
} from "../types/TestRunReport"; | ||
import { Capability, Report, exampleReport } from "./capabilityTypes"; | ||
|
||
const parseTestSuite = (testSuite: ReportsReportTestSuiteActionReport) => { | ||
console.log("Parse test suite", testSuite); | ||
if (!testSuite.test_suite) return null; | ||
const capabilities = testSuite.test_suite.capability_evaluations.map( | ||
(c): Capability => ({ | ||
name: `${c.capability_id} - ${c.participant_id}`, | ||
requirements: [], | ||
childCapabilities: [], | ||
result: c.verified ? "pass" : "fail", | ||
import { | ||
Capability, | ||
Check, | ||
CheckResult, | ||
Report, | ||
Requirement, | ||
} from "./capabilityTypes"; | ||
import * as jp from "jsonpath"; | ||
|
||
const flattenChecks = ( | ||
r: ReportsReportCheckedRequirement, | ||
root: ReportsReportTestSuiteActionReport | ||
): Check[] => { | ||
const expandCheck = (checkLocation: string, result: CheckResult): Check => { | ||
const l = jp.parse(checkLocation); | ||
const check = jp.value(root, jp.stringify(l)); | ||
const step = jp.value(root, jp.stringify(l.slice(0, -2))); | ||
const _case = jp.value(root, jp.stringify(l.slice(0, -4))); | ||
const scenario = jp.value(root, jp.stringify(l.slice(0, -6))); | ||
|
||
return { | ||
scenario: { | ||
name: scenario.name, | ||
docUrl: scenario.documentation_url, | ||
}, | ||
case: { | ||
name: _case.name, | ||
docUrl: _case.documentation_url, | ||
}, | ||
step: { | ||
name: step.name, | ||
docUrl: step.documentation_url, | ||
}, | ||
name: check.name, | ||
result, | ||
detailsUrl: "", // TODO Add details page + navigation | ||
}; | ||
}; | ||
|
||
const res = [ | ||
...r.passed_checks.map((c) => expandCheck(c, "pass")), | ||
|
||
...r.failed_checks.map((c) => expandCheck(c, "fail")), | ||
]; | ||
return res; | ||
}; | ||
|
||
const flattenRequirements = ( | ||
requirementsChecked: ReportsReportRequirementsCheckedConditionEvaluationReport, | ||
root: ReportsReportTestSuiteReport | ||
): Requirement[] => { | ||
return [ | ||
...requirementsChecked.passed_requirements.map((pr) => ({ | ||
name: pr.requirement_id, | ||
checks: flattenChecks(pr, root), | ||
})), | ||
|
||
...requirementsChecked.failed_requirements.map((fr) => ({ | ||
name: fr.requirement_id, | ||
checks: flattenChecks(fr, root), | ||
})), | ||
|
||
...requirementsChecked.untested_requirements.map((ur) => ({ | ||
name: ur, | ||
checks: [], | ||
})), | ||
]; | ||
}; | ||
|
||
const getCapability = ( | ||
testSuite: ReportsReportTestSuiteReport | ||
): Capability[] => { | ||
return testSuite.capability_evaluations | ||
.map((ce) => { | ||
const c = ce.condition_evaluation; | ||
if (c.requirements_checked) { | ||
return { | ||
name: ce.capability_id, | ||
result: ce.verified ? "pass" : "fail", | ||
requirements: flattenRequirements(c.requirements_checked, testSuite), | ||
childCapabilities: [], | ||
participant_id: ce.participant_id, | ||
}; | ||
} else if (c.capability_verified) { | ||
return { | ||
name: ce.capability_id, | ||
result: ce.verified ? "pass" : "fail", | ||
requirements: [], | ||
childCapabilities: [], // TODO: Add child capabilities | ||
participant_id: ce.participant_id, | ||
}; | ||
} else { | ||
return null; | ||
} | ||
}) | ||
); | ||
console.log("Parsed capbilities", capabilities); | ||
.filter((x) => !!x) as Capability[]; | ||
}; | ||
|
||
const parseActions = ( | ||
node?: ReportsReportTestSuiteActionReport | ||
): Capability[] => { | ||
if (!node) return []; | ||
|
||
try { | ||
if (node.test_suite) { | ||
return [ | ||
...getCapability(node.test_suite), | ||
...node.test_suite.actions.map((a) => parseActions(a)), | ||
].flat(); | ||
} else if (node.test_scenario) { | ||
return []; | ||
} else if (node.action_generator) { | ||
return node.action_generator.actions | ||
.map((a) => { | ||
return parseActions(a); | ||
}) | ||
.flat(); | ||
} else { | ||
// TODO Improve | ||
console.error("Unknown state"); | ||
return []; | ||
} | ||
} catch (err) { | ||
console.error(err); | ||
return []; | ||
} | ||
}; | ||
|
||
export const parseReport = (report: ReportsReportTestRunReport): Report => { | ||
// FixMe: Actually parse the report | ||
const startTime = new Date().getTime(); | ||
console.log("Input Report", report); | ||
const parsed = parseTestSuite(report.report); | ||
const parsed = {capability: parseActions(report.report)[0]}; | ||
console.log("Parsed report", parsed); | ||
return exampleReport; | ||
console.info( | ||
"[performance] Report rendered in ", | ||
new Date().getTime() - startTime, | ||
"ms" | ||
); | ||
return parsed; | ||
}; |
Oops, something went wrong.