Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: support specifying the test case ID in the `annotation #691

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions qase-playwright/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# [email protected]

## What's new

Support specifying the test case ID in the `annotation`.

```ts
test('test',
{
annotation: { type: 'QaseID', description: '1' },
},
async ({ page }) => {
await page.goto('https://example.com');
});
```

# [email protected]

## What's new
Expand Down
2 changes: 1 addition & 1 deletion qase-playwright/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "playwright-qase-reporter",
"version": "2.0.13",
"version": "2.0.14",
"description": "Qase TMS Playwright Reporter",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
39 changes: 26 additions & 13 deletions qase-playwright/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ export class PlaywrightQaseReporter implements Reporter {
*/
private static qaseIds: Map<string, number[]> = new Map<string, number[]>();

/**
* @type {Map<string, number[]>}
* @private
*/
private qaseTestWithOldAnnotation: Map<string, number[]> = new Map<string, number[]>();

/**
* @param {TestCase} test
* @returns {string[]}
Expand Down Expand Up @@ -408,15 +402,13 @@ export class PlaywrightQaseReporter implements Reporter {
}
}

if (testCaseMetadata.ids.length > 0) {
const ids = this.extractQaseIdsFromAnnotation(test.annotations);
if (ids.length > 0) {
testResult.testops_id = ids;
} else if (testCaseMetadata.ids.length > 0) {
testResult.testops_id = testCaseMetadata.ids;
} else {
const ids = PlaywrightQaseReporter.qaseIds.get(test.title) ?? null;
testResult.testops_id = ids;
if (ids) {
const path = `${test.location.file}:${test.location.line}:${test.location.column}`;
this.qaseTestWithOldAnnotation.set(path, ids);
}
testResult.testops_id = PlaywrightQaseReporter.qaseIds.get(test.title) ?? null;
}

testResult.signature = this.getSignature(suites, testCaseMetadata.parameters, testResult.testops_id ?? []);
Expand Down Expand Up @@ -495,4 +487,25 @@ export class PlaywrightQaseReporter implements Reporter {
}
return title;
}

/**
* @param annotation
* @returns {number[]}
* @private
*/
private extractQaseIdsFromAnnotation(annotation: { type: string, description?: string }[]): number[] {
const ids: number[] = [];
for (const item of annotation) {
if (item.type.toLowerCase() === 'qaseid' && item.description) {
if (item.description.includes(',')) {
ids.push(...item.description.split(',').map((id) => parseInt(id)));
continue;
}

ids.push(parseInt(item.description));
}
}

return ids;
}
}
Loading