Skip to content

Commit

Permalink
feature: add qase.comment annotation
Browse files Browse the repository at this point in the history
Tests marked with it will be reported with the specified comment in the Qase.

Implement #590
  • Loading branch information
gibiw committed Jun 14, 2024
1 parent 4bd5480 commit 0366306
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
14 changes: 14 additions & 0 deletions qase-playwright/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# [email protected]

## What's new

Added new annotation `qase.comment()`.
Tests marked with it will be reported with the specified comment in the Qase.

```js
test('test', async ({ page }) => {
qase.comment("Custom comment");
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.3",
"version": "2.0.4",
"description": "Qase TMS Playwright Reporter",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
17 changes: 17 additions & 0 deletions qase-playwright/src/playwright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface MetadataMessage {
parameters?: Record<string, string>;
ignore?: boolean;
suite?: string;
comment?: string;
}

/**
Expand Down Expand Up @@ -199,6 +200,22 @@ qase.suite = function(value: string) {
return this;
};

/**
* Set a comment for the test case
* @param {string} value
* @example
* test('test', async ({ page }) => {
* qase.comment("Comment");
* await page.goto('https://example.com');
* });
*/
qase.comment = function(value: string) {
addMetadata({
comment: value,
});
return this;
};

const addMetadata = (metadata: MetadataMessage): void => {
test.info().attach('qase-metadata.json', {
contentType: ReporterContentType,
Expand Down
24 changes: 23 additions & 1 deletion qase-playwright/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface TestCaseMetadata {
attachments: Attachment[];
ignore: boolean;
suite: string;
comment: string;
}

export type PlaywrightQaseOptionsType = ConfigType;
Expand Down Expand Up @@ -100,6 +101,7 @@ export class PlaywrightQaseReporter implements Reporter {
attachments: [],
ignore: false,
suite: '',
comment: '',
};
const attachments: Attachment[] = [];

Expand Down Expand Up @@ -137,6 +139,10 @@ export class PlaywrightQaseReporter implements Reporter {
metadata.suite = message.suite;
}

if (message.comment) {
metadata.comment = message.comment;
}

continue;
}

Expand Down Expand Up @@ -314,6 +320,22 @@ export class PlaywrightQaseReporter implements Reporter {

const error = result.error ? PlaywrightQaseReporter.transformError(result.error) : null;
const suites = testCaseMetadata.suite != '' ? [testCaseMetadata.suite] : PlaywrightQaseReporter.transformSuiteTitle(test);

let message: string | null = null;
if (testCaseMetadata.comment !== '') {
message = testCaseMetadata.comment;
}

if (error) {
if (message) {
message += '\n\n';
} else {
message = '';
}

message += error.message;
}

const testResult: TestResultType = {
attachments: testCaseMetadata.attachments,
author: null,
Expand All @@ -329,7 +351,7 @@ export class PlaywrightQaseReporter implements Reporter {
},
fields: testCaseMetadata.fields,
id: uuidv4(),
message: error === null ? null : error.message,
message: message,
muted: false,
params: testCaseMetadata.parameters,
relations: {
Expand Down

0 comments on commit 0366306

Please sign in to comment.