From 9c0a755db99016d3ef09d5b2db998f4582385a2e Mon Sep 17 00:00:00 2001 From: Dmitrii Gridnev Date: Mon, 23 Sep 2024 16:04:10 +0200 Subject: [PATCH] feature: support `ignore` metadata 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; }, ); ``` --- qase-testcafe/changelog.md | 20 +++++++++++++++++++- qase-testcafe/package.json | 2 +- qase-testcafe/src/qase.ts | 21 +++++++++++++++++++-- qase-testcafe/src/reporter.ts | 18 +++++++++++++++++- 4 files changed, 56 insertions(+), 5 deletions(-) diff --git a/qase-testcafe/changelog.md b/qase-testcafe/changelog.md index 74c48844..9e15bb6a 100644 --- a/qase-testcafe/changelog.md +++ b/qase-testcafe/changelog.md @@ -1,3 +1,20 @@ +# qase-testcafe@2.0.3 + +## 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; + }, +); +``` + # qase-testcafe@2.0.2 ## What's new @@ -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(); diff --git a/qase-testcafe/package.json b/qase-testcafe/package.json index 48393930..a7cc12ee 100644 --- a/qase-testcafe/package.json +++ b/qase-testcafe/package.json @@ -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", diff --git a/qase-testcafe/src/qase.ts b/qase-testcafe/src/qase.ts index c811c085..1dacd853 100644 --- a/qase-testcafe/src/qase.ts +++ b/qase-testcafe/src/qase.ts @@ -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 @@ -71,16 +72,30 @@ export class qase { * Don't forget to call `create` method after setting all the necessary parameters * @param {Record} 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) => { + public static groupParameters = (values: Record) => { 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 @@ -97,6 +112,7 @@ export class qase { QaseFields: this._qaseFields, QaseParameters: this._qaseParameters, QaseGroupParameters: this._qaseGroupParameters, + QaseIgnore: this._qaseIgnore, }; this._qaseID = ''; @@ -104,6 +120,7 @@ export class qase { this._qaseFields = ''; this._qaseParameters = ''; this._qaseGroupParameters = ''; + this._qaseIgnore = ''; return meta; }; diff --git a/qase-testcafe/src/reporter.ts b/qase-testcafe/src/reporter.ts index 2085fe59..e2936f58 100644 --- a/qase-testcafe/src/reporter.ts +++ b/qase-testcafe/src/reporter.ts @@ -54,6 +54,7 @@ enum metadataEnum { parameters = 'QaseParameters', groupParameters = 'QaseGroupParameters', oldID = 'CID', + ignore = 'QaseIgnore', } interface MetadataType { @@ -62,6 +63,7 @@ interface MetadataType { [metadataEnum.fields]: Record; [metadataEnum.parameters]: Record; [metadataEnum.groupParameters]: Record; + [metadataEnum.ignore]: boolean; } export interface TestRunInfoType { @@ -162,6 +164,12 @@ export class TestcafeQaseReporter { meta: Record, formatError: (error: any, prefix: string) => string, ) => { + 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 @@ -170,7 +178,6 @@ export class TestcafeQaseReporter { )) .join('\n'); - const metadata = this.getMeta(meta); await this.reporter.addTestResult({ author: null, execution: { @@ -222,6 +229,7 @@ export class TestcafeQaseReporter { QaseFields: {}, QaseParameters: {}, QaseGroupParameters: {}, + QaseIgnore: false, }; if (meta[metadataEnum.oldID] !== undefined && meta[metadataEnum.oldID] !== '') { @@ -246,6 +254,14 @@ export class TestcafeQaseReporter { metadata.QaseParameters = JSON.parse(meta[metadataEnum.parameters]) as Record; } + if (meta[metadataEnum.groupParameters] !== undefined && meta[metadataEnum.groupParameters] !== '') { + metadata.QaseGroupParameters = JSON.parse(meta[metadataEnum.groupParameters]) as Record; + } + + if (meta[metadataEnum.ignore] !== undefined && meta[metadataEnum.ignore] !== '') { + metadata.QaseIgnore = meta[metadataEnum.ignore] === 'true'; + } + return metadata; }