Skip to content

Commit

Permalink
add method to calculate test case id
Browse files Browse the repository at this point in the history
  • Loading branch information
epszaw committed Aug 14, 2023
1 parent 5dcc4aa commit 2a6e165
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
1 change: 0 additions & 1 deletion packages/allure-cucumberjs/src/CucumberJSAllureReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ export class CucumberJSAllureFormatter extends Formatter {
currentTest.name = pickle.name;
currentTest.fullName = fullName;
currentTest.testCaseId = testCaseId;
currentTest.historyId = testCaseId;

currentTest.addLabel(LabelName.HOST, this.hostname);
currentTest.addLabel(LabelName.LANGUAGE, "javascript");
Expand Down
3 changes: 2 additions & 1 deletion packages/allure-hermione/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ const hermioneAllureReporter = (hermione: Hermione, opts: AllureReportOptions) =

currentTest.name = test.title;
currentTest.fullName = test.fullTitle();
currentTest.historyId = md5(test.fullTitle());
currentTest.stage = Stage.RUNNING;

currentTest.addLabel(LabelName.HOST, hostnameLabel);
Expand Down Expand Up @@ -341,6 +340,8 @@ const hermioneAllureReporter = (hermione: Hermione, opts: AllureReportOptions) =
handleTestError(test, test.err);
}

currentTest.calculateTestCaseId();
currentTest.calculateHistoryId();
currentTest.stage = Stage.FINISHED;
currentTest.endTest(Date.now());
loadedTests.delete(testId());
Expand Down
34 changes: 25 additions & 9 deletions packages/allure-js-commons/src/AllureTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,38 @@ export class AllureTest extends ExecutableItemWrapper {
this.addLink(url, name, LinkType.TMS);
}

calculateTestCaseId(): void {
if (!this.testResult.fullName) {
return;
}

const paramsString = this.testResult.parameters
.filter((p) => !p?.excluded)
.sort((a, b) => a.name?.localeCompare(b?.name) || a.value?.localeCompare(b?.value))
.map((p) => p.name)
.join(",");

this.testCaseId = md5(`${this.testResult.fullName}:${paramsString}`);
}

calculateHistoryId(): void {
const tcId = this.testResult.testCaseId
? this.testResult.testCaseId
: this.testResult.fullName
? md5(this.testResult.fullName)
: null;

if (tcId) {
const paramsString = this.testResult.parameters
.filter((p) => !p?.excluded)
.sort((a, b) => a.name?.localeCompare(b?.name) || a.value?.localeCompare(b?.value))
.map((p) => `${p.name ?? "null"}:${p.value ?? "null"}`)
.join(",");

const paramsHash = md5(paramsString);
this.historyId = `${tcId}:${paramsHash}`;
if (!tcId) {
return;
}

const paramsString = this.testResult.parameters
.filter((p) => !p?.excluded)
.sort((a, b) => a.name?.localeCompare(b?.name) || a.value?.localeCompare(b?.value))
.map((p) => `${p.name ?? "null"}:${p.value ?? "null"}`)
.join(",");
const paramsHash = md5(paramsString);

this.historyId = `${tcId}:${paramsHash}`;
}
}

0 comments on commit 2a6e165

Please sign in to comment.