From f1b584f840633b835b0315d8ca9dfcbe43aa172d Mon Sep 17 00:00:00 2001 From: Dzmitry Kosarau Date: Sat, 14 Oct 2023 17:16:49 +0500 Subject: [PATCH] EPMRPP-78272 || Move new reportingApi to promises --- .prettierignore | 2 + CHANGELOG.md | 2 +- README.md | 137 +++++------ package.json | 20 +- .../reporter/finishTestItemReporting.spec.ts | 75 +++++-- src/__tests__/utils.spec.ts | 25 --- src/index.ts | 2 +- src/promises/index.ts | 1 + src/promises/reportingApi.ts | 212 ++++++++++++++++++ src/reporter.ts | 27 +-- src/reportingApi.ts | 123 ++++++++-- src/utils.ts | 3 - 12 files changed, 468 insertions(+), 161 deletions(-) create mode 100644 .prettierignore create mode 100644 src/promises/index.ts create mode 100644 src/promises/reportingApi.ts diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..60700ed --- /dev/null +++ b/.prettierignore @@ -0,0 +1,2 @@ +# Ignore all md files +*.md diff --git a/CHANGELOG.md b/CHANGELOG.md index fe1e124..e59c72c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ ### Added -- Add ability to provide `attributes`,`status`,`description`,`testCaseId` for test using `testInfo.attach` +- `ReportingApi` from `@reportportal/agent-js-playwright/promises` methods (***addAttributes, setDescription, setTestCaseId, setStatus***, and all methods for setting custom statuses for test or suite) now using ***testInfo.attach*** method to attach custom data to test case. ## [5.1.4] - 2023-10-05 ## Changed diff --git a/README.md b/README.md index ca66321..1750852 100644 --- a/README.md +++ b/README.md @@ -102,69 +102,6 @@ test('basic test', async ({ page }, testInfo) => { }); ``` -Also, we can attach `attributes`,`status`,`description`,`testCaseId` - -`Description` -```typescript -import { test, expect } from '@playwright/test'; -import { RPTestInfo } from '@reportportal/agent-js-playwright' - -test('basic test', async ({ page }, testInfo) => { - await testInfo.attach(RPTestInfo.description, { body: 'Description', contentType: 'plain/text' }); - - expect(true).toBe(true); -}); -``` -Description provided this way will be merged with description provided by `ReportingAPI`. - -`Attributes` -```typescript -import { test, expect } from '@playwright/test'; -import { RPTestInfo } from '@reportportal/agent-js-playwright' - -test('basic test', async ({ page }, testInfo) => { - await testInfo.attach(RPTestInfo.status, { body: JSON.stringify([ - { - key: 'testKey', - value: 'testValue', - }, - { - value: 'testValueTwo', - } - ]), - contentType: 'application/json' }); - - expect(true).toBe(true); -}); -``` -Attributes provided this way will be merged with Attributes provided by `ReportingAPI`. - -`Status` -```typescript -import { test, expect } from '@playwright/test'; -import { RPTestInfo } from '@reportportal/agent-js-playwright' - -test('basic test', async ({ page }, testInfo) => { - await testInfo.attach(RPTestInfo.status, { body: 'passed', contentType:'text/plain'}) - - expect(true).toBe(true); -}); -``` -Status provided this way will be replaced by status provided by `ReportingAPI`. You can provide as many statuses as you want, but only the last will be applied. - -`testCaseId` -```typescript -import { test, expect } from '@playwright/test'; -import { RPTestInfo } from '@reportportal/agent-js-playwright' - -test('basic test', async ({ page }, testInfo) => { - await testInfo.attach(RPTestInfo.testCaseId, { body: 'testCaseId', contentType:'text/plain'}) - - expect(true).toBe(true); -}); -``` -TestCaseId provided this way will be replaced by testCaseId provided by `ReportingAPI`. - *Note:* attachment path can be provided instead of body. As an alternative to this approach the [`ReportingAPI`](#log) methods can be used. @@ -193,9 +130,11 @@ As an alternative to this approach the [`ReportingAPI`](#log) methods can be use This reporter provides Reporting API to use it directly in tests to send some additional data to the report. -To start using the `ReportingApi` in tests, just import it from `'@reportportal/agent-js-playwright'`: +To start using the `ReportingApi` in tests, just import it from `'@reportportal/agent-js-playwright'` or `'@reportportal/agent-js-playwright/promises'`: ```javascript import { ReportingApi } from '@reportportal/agent-js-playwright'; +// or +import { ReportingApi } from '@reportportal/agent-js-playwright/promises' ``` #### Reporting API methods @@ -225,6 +164,27 @@ test('should have the correct attributes', () => { }); ``` +`ReportingApi.addAttributes(attributes: Array, suite?: string):Promise;`
+**required**: `attributes`
+**optional**: `suite`
+Example: +```javascript +import { ReportingApi } from '@reportportal/agent-js-playwright/promises' + +test('should have the correct attributes', async () => { + await ReportingApi.addAttributes([ + { + key: 'testKey', + value: 'testValue', + }, + { + value: 'testValueTwo', + }, + ]); + expect(true).toBe(true); +}); +``` + ##### setTestCaseId Set test case id to the current test ([About test case id](https://reportportal.io/docs/Test-case-ID%3Ewhat-is-it-test-case-id)). Should be called inside of corresponding test.
`ReportingApi.setTestCaseId(id: string, suite?: string);`
@@ -239,6 +199,19 @@ test('should have the correct testCaseId', () => { }); ``` +`ReportingApi.setTestCaseId(id: string, suite?: string):Promise;`
+**required**: `id`
+**optional**: `suite`
+Example: +```javascript +import { ReportingApi } from '@reportportal/agent-js-playwright/promises' + +test('should have the correct testCaseId', async () => { + await ReportingApi.setTestCaseId('itemTestCaseId'); + expect(true).toBe(true); +}); +``` + ##### log Send logs to report portal for the current test. Should be called inside of corresponding test.
`ReportingApi.log(level: LOG_LEVELS, message: string, file?: Attachment, suite?: string);`
@@ -346,6 +319,19 @@ test('should have status FAILED', () => { }); ``` +`ReportingApi.setStatus(status: string, suite?: string):Promise;`
+**required**: `status`
+**optional**: `suite`
+```javascript +import { ReportingApi } from '@reportportal/agent-js-playwright/promises' + +test('should have status FAILED', async () => { + await ReportingApi.setStatus('failed'); + + expect(true).toBe(true); +}); +``` + ##### setStatusFailed, setStatusPassed, setStatusSkipped, setStatusStopped, setStatusInterrupted, setStatusCancelled Assign corresponding status to the current test item. Should be called inside of corresponding test.
`ReportingApi.setStatusFailed(suite?: string);`
@@ -365,6 +351,29 @@ test('should call ReportingApi to set statuses', () => { ReportingAPI.setStatusInterrupted(); ReportingAPI.setStatusCancelled(); }); + +``` +`ReportingApi.setStatusFailed(suite?: string):Promise;`
+`ReportingApi.setStatusPassed(suite?: string):Promise;`
+`ReportingApi.setStatusSkipped(suite?: string):Promise;`
+`ReportingApi.setStatusStopped(suite?: string):Promise;`
+`ReportingApi.setStatusInterrupted(suite?: string):Promise;`
+`ReportingApi.setStatusCancelled(suite?: string):Promise;`
+**optional**: `suite`
+Example: +```javascript +import { ReportingApi } from '@reportportal/agent-js-playwright/promises' + +test('should call ReportingApi to set statuses', async () => { + await Promise.all[ + ReportingAPI.setStatusFailed(); + ReportingAPI.setStatusPassed(), + ReportingAPI.setStatusSkipped(), + ReportingAPI.setStatusStopped(), + ReportingAPI.setStatusInterrupted(), + ReportingAPI.setStatusCancelled() + ] +}); ``` ##### setLaunchStatus diff --git a/package.json b/package.json index b822edd..d93348b 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,24 @@ "name": "@reportportal/agent-js-playwright", "version": "5.1.4", "description": "Agent to integrate Playwright with ReportPortal.", - "main": "build/index.js", - "types": "build/index.d.ts", + "exports": { + ".": { + "node": "./build/index.js", + "import": "./build/index.js", + "require": "./build/index.js", + "default": "./build/index.js", + "types": "./build/index.d.ts" + }, + "./promises": { + "node": "./build/promises/index.js", + "default": "./build/promises/index.js", + "require": "./build/promises/index.js", + "import": "./build/promises/index.js", + "types": "./build/promises/index.d.ts" + } + }, + "types": "./build/index.d.ts", + "main": "./build/index.js", "scripts": { "build": "npm run clean && tsc", "clean": "rimraf ./build", diff --git a/src/__tests__/reporter/finishTestItemReporting.spec.ts b/src/__tests__/reporter/finishTestItemReporting.spec.ts index 8911e6c..2e1da07 100644 --- a/src/__tests__/reporter/finishTestItemReporting.spec.ts +++ b/src/__tests__/reporter/finishTestItemReporting.spec.ts @@ -101,8 +101,30 @@ describe('finish test reporting', () => { description: 'description', }; - // @ts-ignore - await reporter.onTestEnd({ ...testCase, outcome: () => 'expected' }, result); + await reporter.onTestEnd( + { + ...testCase, + outcome: () => 'expected', + results: [ + // @ts-ignore + { + attachments: [ + { + name: RPTestInfo.attributes, + body: Buffer.from(JSON.stringify([{ key: 'key', value: 'value' }])), + contentType: 'application/json', + }, + { + name: RPTestInfo.description, + body: Buffer.from('description'), + contentType: 'text/plain', + }, + ], + }, + ], + }, + result, + ); expect(reporter.client.finishTestItem).toHaveBeenCalledTimes(3); expect(reporter.client.finishTestItem).toHaveBeenNthCalledWith( @@ -126,7 +148,30 @@ describe('finish test reporting', () => { issue: { issueType: 'NOT_ISSUE' }, }; // @ts-ignore - await reporter.onTestEnd({ ...testCase, outcome: () => 'skipped' }, result); + await reporter.onTestEnd( + { + ...testCase, + outcome: () => 'skipped', + results: [ + // @ts-ignore + { + attachments: [ + { + name: RPTestInfo.attributes, + body: Buffer.from(JSON.stringify([{ key: 'key', value: 'value' }])), + contentType: 'application/json', + }, + { + name: RPTestInfo.description, + body: Buffer.from('description'), + contentType: 'text/plain', + }, + ], + }, + ], + }, + result, + ); expect(reporter.client.finishTestItem).toHaveBeenCalledTimes(3); expect(reporter.client.finishTestItem).toHaveBeenNthCalledWith( @@ -195,22 +240,6 @@ describe('finish test reporting', () => { test('client.finishTestItem should call reporter.client.finishTestItem with correct values', async () => { const result = { status: 'passed' }; - reporter.testItems = new Map([ - [ - `${testCase.id}`, - { - id: 'testItemId', - name: 'name', - description: 'savedTestItemDescription', - status: STATUSES.PASSED, - attributes: [ - { value: 'savedTestItemAttrValue' }, - { key: 'savedTestItemAttrKey', value: 'savedTestItemAttrValue', system: false }, - ], - }, - ], - ]); - await reporter.onTestEnd( { ...testCase, @@ -263,20 +292,18 @@ describe('finish test reporting', () => { const finishStepObject: FinishTestItemObjType = { endTime: reporter.client.helpers.now(), - status: STATUSES.PASSED, + status: STATUSES.INTERRUPTED, attributes: [ { key: 'key1', value: 'value1', system: false }, { key: 'key2', value: 'value2', system: false }, - { value: 'savedTestItemAttrValue' }, - { key: 'savedTestItemAttrKey', value: 'savedTestItemAttrValue', system: false }, ], - description: 'savedTestItemDescription\nDescription', + description: 'Description', testCaseId: 'testCaseId', }; expect(reporter.client.finishTestItem).toHaveBeenNthCalledWith( 1, - 'testItemId', + 'tempTestItemId', finishStepObject, ); }); diff --git a/src/__tests__/utils.spec.ts b/src/__tests__/utils.spec.ts index 95b5f8e..c3f4036 100644 --- a/src/__tests__/utils.spec.ts +++ b/src/__tests__/utils.spec.ts @@ -28,7 +28,6 @@ import { isErrorLog, calculateRpStatus, getAdditionalInfo, - getDescription, } from '../utils'; import fs from 'fs'; import path from 'path'; @@ -531,28 +530,4 @@ describe('testing utils', () => { expect(additionalInfo).toEqual(expectedResult); }); }); - - describe('getDescription', () => { - test('It should return one description joined by \n', () => { - const description1 = 'description1'; - const description2 = 'description2'; - - const expectedResult = 'description1\ndescription2'; - - const description = getDescription(description1, description2); - - expect(expectedResult).toBe(description); - }); - - test('It should return one description joined by \n in case when empty string was provided', () => { - const description1 = 'description1'; - const description2 = ''; - - const expectedResult = 'description1'; - - const description = getDescription(description1, description2); - - expect(expectedResult).toBe(description); - }); - }); }); diff --git a/src/index.ts b/src/index.ts index 25da34e..8e49b49 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ import { RPReporter } from './reporter'; export { ReportingApi } from './reportingApi'; export { LOG_LEVELS, STATUSES } from './constants'; -export { RPTestInfo } from './constants'; +export { ReportPortalConfig } from './models'; export default RPReporter; diff --git a/src/promises/index.ts b/src/promises/index.ts new file mode 100644 index 0000000..206037a --- /dev/null +++ b/src/promises/index.ts @@ -0,0 +1 @@ +export { ReportingApi } from './reportingApi'; diff --git a/src/promises/reportingApi.ts b/src/promises/reportingApi.ts new file mode 100644 index 0000000..9a0608d --- /dev/null +++ b/src/promises/reportingApi.ts @@ -0,0 +1,212 @@ +/* + * Copyright 2021 EPAM Systems + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +import { EVENTS } from '@reportportal/client-javascript/lib/constants/events'; +import { sendEventToReporter } from '../utils'; +import { Attribute } from '../models'; +import { STATUSES, LOG_LEVELS, RPTestInfo } from '../constants'; +import { Attachment } from '../models/reporting'; +import { test } from '@playwright/test'; + +export const ReportingApi = { + addAttributes: (attrs: Attribute[], suite?: string): Promise => { + if (suite) { + sendEventToReporter(EVENTS.ADD_ATTRIBUTES, attrs, suite); + + return Promise.resolve(); + } + + return test.info().attach(RPTestInfo.attributes, { + body: JSON.stringify(attrs), + contentType: 'application/json', + }); + }, + + setDescription: (description: string, suite?: string): Promise => { + if (suite) { + sendEventToReporter(EVENTS.SET_DESCRIPTION, description, suite); + + return Promise.resolve(); + } + + return test.info().attach(RPTestInfo.description, { + body: description, + contentType: 'text/plain', + }); + }, + setTestCaseId: (testCaseId: string, suite?: string): Promise => { + if (suite) { + sendEventToReporter(EVENTS.SET_TEST_CASE_ID, testCaseId, suite); + + return Promise.resolve(); + } + + return test.info().attach(RPTestInfo.testCaseId, { + body: testCaseId, + contentType: 'text/plain', + }); + }, + setStatus: (status: keyof typeof STATUSES, suite?: string): Promise => { + if (suite) { + sendEventToReporter(EVENTS.SET_STATUS, status, suite); + + return Promise.resolve(); + } + + return test.info().attach(RPTestInfo.status, { + body: status, + contentType: 'text/plain', + }); + }, + setStatusPassed: (suite?: string): Promise => { + if (suite) { + sendEventToReporter(EVENTS.SET_STATUS, STATUSES.PASSED, suite); + + return Promise.resolve(); + } + + return test.info().attach(RPTestInfo.status, { + body: STATUSES.PASSED, + contentType: 'text/plain', + }); + }, + setStatusFailed: (suite?: string): Promise => { + if (suite) { + sendEventToReporter(EVENTS.SET_STATUS, STATUSES.FAILED, suite); + + return Promise.resolve(); + } + + return test + .info() + .attach(RPTestInfo.status, { body: STATUSES.FAILED, contentType: 'text/plain' }); + }, + setStatusSkipped: (suite?: string): Promise => { + if (suite) { + sendEventToReporter(EVENTS.SET_STATUS, STATUSES.SKIPPED, suite); + + return Promise.resolve(); + } + + return test + .info() + .attach(RPTestInfo.status, { body: STATUSES.SKIPPED, contentType: 'text/plain' }); + }, + setStatusStopped: (suite?: string): Promise => { + if (suite) { + sendEventToReporter(EVENTS.SET_STATUS, STATUSES.STOPPED, suite); + + return Promise.resolve(); + } + + return test + .info() + .attach(RPTestInfo.status, { body: STATUSES.STOPPED, contentType: 'text/plain' }); + }, + setStatusInterrupted: (suite?: string): Promise => { + if (suite) { + sendEventToReporter(EVENTS.SET_STATUS, STATUSES.INTERRUPTED, suite); + + return Promise.resolve(); + } + + return test + .info() + .attach(RPTestInfo.status, { body: STATUSES.INTERRUPTED, contentType: 'text/plain' }); + }, + setStatusCancelled: (suite?: string): Promise => { + if (suite) { + sendEventToReporter(EVENTS.SET_STATUS, STATUSES.CANCELLED, suite); + + return Promise.resolve(); + } + + return test + .info() + .attach(RPTestInfo.status, { body: STATUSES.CANCELLED, contentType: 'text/plain' }); + }, + setStatusInfo: (suite?: string): Promise => { + if (suite) { + sendEventToReporter(EVENTS.SET_STATUS, STATUSES.INFO, suite); + + return Promise.resolve(); + } + + return test + .info() + .attach(RPTestInfo.status, { body: STATUSES.INFO, contentType: 'text/plain' }); + }, + setStatusWarn: (suite?: string): Promise => { + if (suite) { + sendEventToReporter(EVENTS.SET_STATUS, STATUSES.WARN, suite); + + return Promise.resolve(); + } + + return test + .info() + .attach(RPTestInfo.status, { body: STATUSES.WARN, contentType: 'text/plain' }); + }, + + setLaunchStatus: (status: keyof typeof STATUSES): void => + sendEventToReporter(EVENTS.SET_LAUNCH_STATUS, status), + setLaunchStatusPassed: (): void => sendEventToReporter(EVENTS.SET_LAUNCH_STATUS, STATUSES.PASSED), + setLaunchStatusFailed: (): void => sendEventToReporter(EVENTS.SET_LAUNCH_STATUS, STATUSES.FAILED), + setLaunchStatusSkipped: (): void => + sendEventToReporter(EVENTS.SET_LAUNCH_STATUS, STATUSES.SKIPPED), + setLaunchStatusStopped: (): void => + sendEventToReporter(EVENTS.SET_LAUNCH_STATUS, STATUSES.STOPPED), + setLaunchStatusInterrupted: (): void => + sendEventToReporter(EVENTS.SET_LAUNCH_STATUS, STATUSES.INTERRUPTED), + setLaunchStatusCancelled: (): void => + sendEventToReporter(EVENTS.SET_LAUNCH_STATUS, STATUSES.CANCELLED), + setLaunchStatusInfo: (): void => sendEventToReporter(EVENTS.SET_LAUNCH_STATUS, STATUSES.INFO), + setLaunchStatusWarn: (): void => sendEventToReporter(EVENTS.SET_LAUNCH_STATUS, STATUSES.WARN), + + log: ( + level: LOG_LEVELS = LOG_LEVELS.INFO, + message = '', + file?: Attachment, + suite?: string, + ): void => sendEventToReporter(EVENTS.ADD_LOG, { level, message, file }, suite), + launchLog: (level: LOG_LEVELS = LOG_LEVELS.INFO, message = '', file?: Attachment): void => + sendEventToReporter(EVENTS.ADD_LAUNCH_LOG, { level, message, file }), + trace: (message: string, file?: Attachment, suite?: string): void => + ReportingApi.log(LOG_LEVELS.TRACE, message, file, suite), + debug: (message: string, file?: Attachment, suite?: string): void => + ReportingApi.log(LOG_LEVELS.DEBUG, message, file, suite), + info: (message: string, file?: Attachment, suite?: string): void => + ReportingApi.log(LOG_LEVELS.INFO, message, file, suite), + warn: (message: string, file?: Attachment, suite?: string): void => + ReportingApi.log(LOG_LEVELS.WARN, message, file, suite), + error: (message: string, file?: Attachment, suite?: string): void => + ReportingApi.log(LOG_LEVELS.ERROR, message, file, suite), + fatal: (message: string, file?: Attachment, suite?: string): void => + ReportingApi.log(LOG_LEVELS.FATAL, message, file, suite), + launchTrace: (message: string, file?: Attachment): void => + ReportingApi.launchLog(LOG_LEVELS.TRACE, message, file), + launchDebug: (message: string, file?: Attachment): void => + ReportingApi.launchLog(LOG_LEVELS.DEBUG, message, file), + launchInfo: (message: string, file?: Attachment): void => + ReportingApi.launchLog(LOG_LEVELS.INFO, message, file), + launchWarn: (message: string, file?: Attachment): void => + ReportingApi.launchLog(LOG_LEVELS.WARN, message, file), + launchError: (message: string, file?: Attachment): void => + ReportingApi.launchLog(LOG_LEVELS.ERROR, message, file), + launchFatal: (message: string, file?: Attachment): void => + ReportingApi.launchLog(LOG_LEVELS.FATAL, message, file), +}; diff --git a/src/reporter.ts b/src/reporter.ts index cb26f19..19b4bd0 100644 --- a/src/reporter.ts +++ b/src/reporter.ts @@ -41,7 +41,6 @@ import { getAgentInfo, getAttachments, getCodeRef, - getDescription, getSystemAttributes, isErrorLog, isFalse, @@ -346,8 +345,6 @@ export class RPReporter implements Reporter { ...(status && { status }), ...(logs && { logs }), // TODO: may be send it on suite start }); - - this.suitesInfo.delete(currentSuiteTitle); } return projectName; @@ -455,22 +452,20 @@ export class RPReporter implements Reporter { return Promise.resolve(); } - const additionalInfo = getAdditionalInfo(test); - const { - id: testItemId, attributes, description, - testCaseId, status: predefinedStatus, - } = savedTestItem; + testCaseId, + } = getAdditionalInfo(test); + + const { id: testItemId } = savedTestItem; let withoutIssue; - let testDescription = getDescription(description, additionalInfo.description); + let testDescription = description; const calculatedStatus = calculateRpStatus(test.outcome(), result.status, test.annotations); - const status = predefinedStatus || additionalInfo.status || calculatedStatus; - const calculatedTestCaseId = testCaseId || additionalInfo.testCaseId; - const mergedAttributes = additionalInfo.attributes.concat(attributes ?? []); + const status = predefinedStatus || calculatedStatus; + if (status === STATUSES.SKIPPED) { withoutIssue = isFalse(this.config.skippedIssue); } @@ -497,9 +492,7 @@ export class RPReporter implements Reporter { level: LOG_LEVELS.ERROR, message: stacktrace, }); - testDescription = getDescription(description, additionalInfo.description).concat( - `\n\`\`\`error\n${stacktrace}\n\`\`\``, - ); + testDescription = description.concat(`\n\`\`\`error\n${stacktrace}\n\`\`\``); } [...this.nestedSteps.entries()].forEach(([key, value]) => { @@ -521,9 +514,9 @@ export class RPReporter implements Reporter { endTime: this.client.helpers.now(), status, ...(withoutIssue && { issue: { issueType: 'NOT_ISSUE' } }), - ...(mergedAttributes.length !== 0 && { attributes: mergedAttributes }), + ...(attributes.length !== 0 && { attributes }), ...(testDescription && { description: testDescription }), - ...(calculatedTestCaseId && { testCaseId: calculatedTestCaseId }), + ...(testCaseId && { testCaseId }), }; const { promise } = this.client.finishTestItem(testItemId, finishTestItemObj); diff --git a/src/reportingApi.ts b/src/reportingApi.ts index e36ccd9..32d6cf1 100644 --- a/src/reportingApi.ts +++ b/src/reportingApi.ts @@ -21,31 +21,106 @@ import { Attribute } from './models'; import { STATUSES, LOG_LEVELS } from './constants'; import { Attachment } from './models/reporting'; +const getDepreciationMessage = (methodName: string): string => + `This method is deprecated. Use ${methodName} from @reportportal/agent-js-playwright/promises instead`; + export const ReportingApi = { - addAttributes: (attrs: Attribute[], suite?: string): void => - sendEventToReporter(EVENTS.ADD_ATTRIBUTES, attrs, suite), - setDescription: (description: string, suite?: string): void => - sendEventToReporter(EVENTS.SET_DESCRIPTION, description, suite), - setTestCaseId: (testCaseId: string, suite?: string): void => - sendEventToReporter(EVENTS.SET_TEST_CASE_ID, testCaseId, suite), - setStatus: (status: keyof typeof STATUSES, suite?: string): void => - sendEventToReporter(EVENTS.SET_STATUS, status, suite), - setStatusPassed: (suite?: string): void => - sendEventToReporter(EVENTS.SET_STATUS, STATUSES.PASSED, suite), - setStatusFailed: (suite?: string): void => - sendEventToReporter(EVENTS.SET_STATUS, STATUSES.FAILED, suite), - setStatusSkipped: (suite?: string): void => - sendEventToReporter(EVENTS.SET_STATUS, STATUSES.SKIPPED, suite), - setStatusStopped: (suite?: string): void => - sendEventToReporter(EVENTS.SET_STATUS, STATUSES.STOPPED, suite), - setStatusInterrupted: (suite?: string): void => - sendEventToReporter(EVENTS.SET_STATUS, STATUSES.INTERRUPTED, suite), - setStatusCancelled: (suite?: string): void => - sendEventToReporter(EVENTS.SET_STATUS, STATUSES.CANCELLED, suite), - setStatusInfo: (suite?: string): void => - sendEventToReporter(EVENTS.SET_STATUS, STATUSES.INFO, suite), - setStatusWarn: (suite?: string): void => - sendEventToReporter(EVENTS.SET_STATUS, STATUSES.WARN, suite), + /** + * @deprecated Use `addAttributes` from `@reportportal/agent-js-playwright/promises` instead + */ + addAttributes: (attrs: Attribute[], suite?: string): void => { + console.warn(getDepreciationMessage('addAttributes')); + sendEventToReporter(EVENTS.ADD_ATTRIBUTES, attrs, suite); + }, + + /** + * @deprecated Use `setDescription` from `@reportportal/agent-js-playwright/promises` instead + */ + setDescription: (description: string, suite?: string): void => { + console.warn(getDepreciationMessage('setDescription')); + sendEventToReporter(EVENTS.SET_DESCRIPTION, description, suite); + }, + + /** + * @deprecated Use `setTestCaseId` from `@reportportal/agent-js-playwright/promises` instead + */ + setTestCaseId: (testCaseId: string, suite?: string): void => { + console.warn(getDepreciationMessage('setTestCaseId')); + sendEventToReporter(EVENTS.SET_TEST_CASE_ID, testCaseId, suite); + }, + + /** + * @deprecated Use `setStatus` from `@reportportal/agent-js-playwright/promises` instead + */ + setStatus: (status: keyof typeof STATUSES, suite?: string): void => { + console.warn(getDepreciationMessage('setStatus')); + sendEventToReporter(EVENTS.SET_STATUS, status, suite); + }, + + /** + * @deprecated Use `setStatusPassed` from `@reportportal/agent-js-playwright/promises` instead + */ + setStatusPassed: (suite?: string): void => { + console.warn(getDepreciationMessage('setStatusPassed')); + sendEventToReporter(EVENTS.SET_STATUS, STATUSES.PASSED, suite); + }, + + /** + * @deprecated Use `setStatusFailed` from `@reportportal/agent-js-playwright/promises` instead + */ + setStatusFailed: (suite?: string): void => { + console.warn(getDepreciationMessage('setStatusPassed')); + sendEventToReporter(EVENTS.SET_STATUS, STATUSES.FAILED, suite); + }, + + /** + * @deprecated Use `setStatusSkipped` from `@reportportal/agent-js-playwright/promises` instead + */ + setStatusSkipped: (suite?: string): void => { + console.warn(getDepreciationMessage('setStatusSkipped')); + sendEventToReporter(EVENTS.SET_STATUS, STATUSES.SKIPPED, suite); + }, + + /** + * @deprecated Use `setStatusStopped` from `@reportportal/agent-js-playwright/promises` instead + */ + setStatusStopped: (suite?: string): void => { + console.warn(getDepreciationMessage('setStatusStopped')); + sendEventToReporter(EVENTS.SET_STATUS, STATUSES.STOPPED, suite); + }, + + /** + * @deprecated Use `setStatusInterrupted` from `@reportportal/agent-js-playwright/promises` instead + */ + setStatusInterrupted: (suite?: string): void => { + console.warn(getDepreciationMessage('setStatusInterrupted')); + sendEventToReporter(EVENTS.SET_STATUS, STATUSES.INTERRUPTED, suite); + }, + + /** + * @deprecated Use `setStatusCancelled` from `@reportportal/agent-js-playwright/promises` instead + */ + setStatusCancelled: (suite?: string): void => { + console.warn(getDepreciationMessage('setStatusCancelled')); + sendEventToReporter(EVENTS.SET_STATUS, STATUSES.CANCELLED, suite); + }, + + /** + * @deprecated Use `setStatusInfo` from `@reportportal/agent-js-playwright/promises` instead + */ + setStatusInfo: (suite?: string): void => { + console.warn(getDepreciationMessage('setStatusInfo')); + sendEventToReporter(EVENTS.SET_STATUS, STATUSES.INFO, suite); + }, + + /** + * @deprecated Use `setStatusWarn` from `@reportportal/agent-js-playwright/promises` instead + */ + setStatusWarn: (suite?: string): void => { + console.warn(getDepreciationMessage('setStatusWarn')); + sendEventToReporter(EVENTS.SET_STATUS, STATUSES.WARN, suite); + }, + setLaunchStatus: (status: keyof typeof STATUSES): void => sendEventToReporter(EVENTS.SET_LAUNCH_STATUS, status), setLaunchStatusPassed: (): void => sendEventToReporter(EVENTS.SET_LAUNCH_STATUS, STATUSES.PASSED), diff --git a/src/utils.ts b/src/utils.ts index 68eb07e..ede7415 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -209,6 +209,3 @@ export const getAdditionalInfo = (test: TestCase): TestAdditionalInfo => { initialValue, ); }; - -export const getDescription = (...descriptions: string[]): string => - descriptions.filter(Boolean).join('\n');