Skip to content

Commit

Permalink
feature: support ignore metadata
Browse files Browse the repository at this point in the history
If the test case has the `ignore` tag, the reporter will not send the result to the Qase
TMS.

```ts
const q = qase.ignore().create();
test.meta({ ...q })(
  'test',
  async (t) => {
    await t;
  },
);
```
  • Loading branch information
gibiw committed Sep 23, 2024
1 parent ac6d423 commit 8c380ed
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 5 deletions.
20 changes: 19 additions & 1 deletion qase-testcafe/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# [email protected]

## What's new

Support `ignore` metadata for test cases. If the test case has the `ignore` tag, the reporter will not send the result to the Qase
TMS.

```ts
const q = qase.ignore().create();
test.meta({ ...q })(
'test',
async (t) => {
await t;
},
);
```

# [email protected]

## What's new
Expand All @@ -8,7 +25,8 @@ Improved error collection. The error stack trace contains more useful debugging

## What's new

Support group parameters for test cases. You can specify the group parameters in the test case using the following format:
Support group parameters for test cases. You can specify the group parameters in the test case using the following
format:

```ts
const q = qase.groupParameters({ 'param01': 'value01', 'param02': 'value02' }).create();
Expand Down
2 changes: 1 addition & 1 deletion qase-testcafe/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "testcafe-reporter-qase",
"version": "2.0.2",
"version": "2.0.3",
"description": "Qase TMS TestCafe Reporter",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
21 changes: 19 additions & 2 deletions qase-testcafe/src/qase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export class qase {
private static _qaseFields = '';
private static _qaseParameters = '';
private static _qaseGroupParameters = '';
private static _qaseIgnore = '';

/**
* Set a Qase ID for the test case
Expand Down Expand Up @@ -71,16 +72,30 @@ export class qase {
* Don't forget to call `create` method after setting all the necessary parameters
* @param {Record<string, string>} values
* @example
* const q = qase.group_parameters({ 'severity': 'high', 'priority': 'medium' }).create();
* const q = qase.groupParameters({ 'severity': 'high', 'priority': 'medium' }).create();
* test.meta(q)('Test case title', async t => { ... });
* or
* test.meta({userField: 123, ...q})('Test case title', async t => { ... });
*/
public static group_parameters = (values: Record<string, string>) => {
public static groupParameters = (values: Record<string, string>) => {
this._qaseGroupParameters = this.toNormalizeRecord(values);
return this;
};

/**
* Set a ignore flag for the test case
* Don't forget to call `create` method after setting all the necessary parameters
* @example
* const q = qase.ignore().create();
* test.meta(q)('Test case title', async t => { ... });
* or
* test.meta({userField: 123, ...q})('Test case title', async t => { ... });
*/
public static ignore = () => {
this._qaseIgnore = 'true';
return this;
};

/**
* Create a Qase metadata
* Call this method after setting all the necessary parameters
Expand All @@ -97,13 +112,15 @@ export class qase {
QaseFields: this._qaseFields,
QaseParameters: this._qaseParameters,
QaseGroupParameters: this._qaseGroupParameters,
QaseIgnore: this._qaseIgnore,
};

this._qaseID = '';
this._qaseTitle = '';
this._qaseFields = '';
this._qaseParameters = '';
this._qaseGroupParameters = '';
this._qaseIgnore = '';

return meta;
};
Expand Down
18 changes: 17 additions & 1 deletion qase-testcafe/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ enum metadataEnum {
parameters = 'QaseParameters',
groupParameters = 'QaseGroupParameters',
oldID = 'CID',
ignore = 'QaseIgnore',
}

interface MetadataType {
Expand All @@ -62,6 +63,7 @@ interface MetadataType {
[metadataEnum.fields]: Record<string, string>;
[metadataEnum.parameters]: Record<string, string>;
[metadataEnum.groupParameters]: Record<string, string>;
[metadataEnum.ignore]: boolean;
}

export interface TestRunInfoType {
Expand Down Expand Up @@ -162,6 +164,12 @@ export class TestcafeQaseReporter {
meta: Record<string, string>,
formatError: (error: any, prefix: string) => string,

Check warning on line 165 in qase-testcafe/src/reporter.ts

View workflow job for this annotation

GitHub Actions / Project qase-testcafe - Node 16

Unexpected any. Specify a different type

Check warning on line 165 in qase-testcafe/src/reporter.ts

View workflow job for this annotation

GitHub Actions / Project qase-testcafe - Node 16

Unexpected any. Specify a different type

Check warning on line 165 in qase-testcafe/src/reporter.ts

View workflow job for this annotation

GitHub Actions / Project qase-testcafe - Node 18

Unexpected any. Specify a different type

Check warning on line 165 in qase-testcafe/src/reporter.ts

View workflow job for this annotation

GitHub Actions / Project qase-testcafe - Node 18

Unexpected any. Specify a different type
) => {
const metadata = this.getMeta(meta);

if (metadata[metadataEnum.ignore]) {
return;
}

const errorLog = testRunInfo.errs
.map((error, index) => formatError(error, `${index + 1} `).replace(
// eslint-disable-next-line no-control-regex
Expand All @@ -170,7 +178,6 @@ export class TestcafeQaseReporter {
))
.join('\n');

const metadata = this.getMeta(meta);
await this.reporter.addTestResult({
author: null,
execution: {
Expand Down Expand Up @@ -222,6 +229,7 @@ export class TestcafeQaseReporter {
QaseFields: {},
QaseParameters: {},
QaseGroupParameters: {},
QaseIgnore: false,
};

if (meta[metadataEnum.oldID] !== undefined && meta[metadataEnum.oldID] !== '') {
Expand All @@ -246,6 +254,14 @@ export class TestcafeQaseReporter {
metadata.QaseParameters = JSON.parse(meta[metadataEnum.parameters]) as Record<string, string>;
}

if (meta[metadataEnum.groupParameters] !== undefined && meta[metadataEnum.groupParameters] !== '') {
metadata.QaseGroupParameters = JSON.parse(meta[metadataEnum.groupParameters]) as Record<string, string>;
}

if (meta[metadataEnum.ignore] !== undefined && meta[metadataEnum.ignore] !== '') {
metadata.QaseIgnore = meta[metadataEnum.ignore] === 'true';
}

return metadata;
}

Expand Down

0 comments on commit 8c380ed

Please sign in to comment.