Skip to content
This repository has been archived by the owner on Aug 28, 2022. It is now read-only.

Commit

Permalink
fix(allure-reporter.ts): passing test through pragma methods
Browse files Browse the repository at this point in the history
Fixes a bug that would fetch a test before it was added to the test array.
  • Loading branch information
ryparker committed Dec 23, 2020
1 parent 71522a0 commit c8a35f6
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions src/allure-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export default class AllureReporter {
const serializedTestCode = test.fn.toString();
const {code, comments, pragmas} = this.extractCodeDetails(serializedTestCode);

this.setAllureReportPragmas(pragmas);
this.setAllureReportPragmas(currentTest, pragmas);

currentTest.description = `${comments}\n### Test\n\`\`\`typescript\n${code}\n\`\`\`\n`;
}
Expand Down Expand Up @@ -330,48 +330,42 @@ export default class AllureReporter {
return match ? match[0].trimStart() : '';
}

private setAllureReportPragmas(pragmas: Record<string, string|string[]>) {
private setAllureReportPragmas(currentTest: AllureTest, pragmas: Record<string, string|string[]>) {
for (let [pragma, value] of Object.entries(pragmas)) {
if (value instanceof String && value.includes(',')) {
value = value.split(',');
}

if (Array.isArray(value)) {
value.forEach(v => {
this.setAllureLabelsAndLinks(pragma, v);
this.setAllureLabelsAndLinks(currentTest, pragma, v);
});
}

if (!Array.isArray(value)) {
this.setAllureLabelsAndLinks(pragma, value);
this.setAllureLabelsAndLinks(currentTest, pragma, value);
}
}
}

private setAllureLabelsAndLinks(labelName: string, value: string) {
if (!this.currentTest) {
throw new Error('setAllureLabelsAndLinks called while no test is running.');
}

const test = this.currentTest;

private setAllureLabelsAndLinks(currentTest: AllureTest, labelName: string, value: string) {
switch (labelName) {
case 'issue':
test.addLink(`${this.jiraUrl}${value}`, value, LinkType.ISSUE);
currentTest.addLink(`${this.jiraUrl}${value}`, value, LinkType.ISSUE);
break;
case 'tms':
test.addLink(`${this.tmsUrl}${value}`, value, LinkType.TMS);
currentTest.addLink(`${this.tmsUrl}${value}`, value, LinkType.TMS);
break;
case 'tag':
case 'tags':
test.addLabel(LabelName.TAG, value);
currentTest.addLabel(LabelName.TAG, value);
break;
case 'milestone':
test.addLabel(labelName, value);
test.addLabel('epic', value);
currentTest.addLabel(labelName, value);
currentTest.addLabel('epic', value);
break;
default:
test.addLabel(labelName, value);
currentTest.addLabel(labelName, value);
break;
}
}
Expand Down

0 comments on commit c8a35f6

Please sign in to comment.