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 ignore metadata #690

Merged
merged 1 commit into from
Sep 23, 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
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 @@
parameters = 'QaseParameters',
groupParameters = 'QaseGroupParameters',
oldID = 'CID',
ignore = 'QaseIgnore',
}

interface MetadataType {
Expand All @@ -62,6 +63,7 @@
[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 @@ -160,8 +162,14 @@
title: string,
testRunInfo: TestRunInfoType,
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 @@
))
.join('\n');

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

if (meta[metadataEnum.oldID] !== undefined && meta[metadataEnum.oldID] !== '') {
Expand All @@ -246,6 +254,14 @@
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
Loading