Skip to content

Commit

Permalink
feat: add multi testcase meta tag support (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaswong79 authored Sep 30, 2022
1 parent 0abd28e commit acb89a2
Showing 1 changed file with 41 additions and 29 deletions.
70 changes: 41 additions & 29 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,38 +161,50 @@ class TestcafeTestrailReporter {
testStatus = Status.Failed;
}

let caseId = 0;
const caseIdList: number[] = [];
if (meta[this.config.caseMeta]) {
caseId = Number(meta[this.config.caseMeta].replace("C", "").trim());
}

if (caseId > 0) {
const errorLog = testRunInfo.errs
.map((x: Record<string, unknown>) => {
const formatted = formatError(x).replace(
// eslint-disable-next-line no-control-regex
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
""
if (typeof meta[this.config.caseMeta] === "string") {
caseIdList.push(
parseInt(meta[this.config.caseMeta].replace("C", "").trim(), 10)
);
} else {
for (let i = 0; i < meta[this.config.caseMeta].length; i++) {
caseIdList.push(
Number(meta[this.config.caseMeta][i].replace("C", "").trim())
);

return formatted;
})
.join("\n");
let testDuration;
if (testRunInfo.durationMs > 0) {
testDuration = (testRunInfo.durationMs / 1000).toString() + "s";
}
this.results.push({
case_id: caseId,
status_id: testStatus.value,
comment: `Test ${testStatus.text}\n${errorLog}`,
elapsed: testDuration,
});
if (testRunInfo.screenshots.length) {
this.screenshots[caseId] = testRunInfo.screenshots;
}
}
if (testRunInfo.videos?.length) {
this.videos[caseId] = testRunInfo.videos;
}

if (caseIdList.length > 0) {
for (let i = 0; i < caseIdList.length; i++) {
const errorLog = testRunInfo.errs
.map((x: Record<string, unknown>) => {
const formatted = formatError(x).replace(
// eslint-disable-next-line no-control-regex
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
""
);

return formatted;
})
.join("\n");
let testDuration;
if (testRunInfo.durationMs > 0) {
testDuration = (testRunInfo.durationMs / 1000).toString() + "s";
}
this.results.push({
case_id: caseIdList[i],
status_id: testStatus.value,
comment: `Test ${testStatus.text}\n${errorLog}`,
elapsed: testDuration,
});
if (testRunInfo.screenshots.length) {
this.screenshots[caseIdList[i]] = testRunInfo.screenshots;
}
if (testRunInfo.videos?.length) {
this.videos[caseIdList[i]] = testRunInfo.videos;
}
}
} else {
console.log(
Expand Down

0 comments on commit acb89a2

Please sign in to comment.