Skip to content

Commit

Permalink
Merge pull request #193 from reportportal/develop
Browse files Browse the repository at this point in the history
Release 5.1.2
  • Loading branch information
AliakseiLiasnitski authored Feb 20, 2024
2 parents 2e9c766 + 0508342 commit 6df9f62
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 36 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
### Fixed
- Execution sequence for retried tests [#134](https://github.com/reportportal/agent-js-playwright/issues/134).

## [5.1.1] - 2024-01-23
### Added
Expand Down
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ Library is used only for implementors of custom listeners for ReportPortal.

## Already implemented listeners:

* [Jest integration](https://github.com/reportportal/agent-js-jest)
* [Playwright integration](https://github.com/reportportal/agent-js-playwright)
* [Cypress integration](https://github.com/reportportal/agent-js-cypress)
* [Jest integration](https://github.com/reportportal/agent-js-jest)
* [Mocha integration](https://github.com/reportportal/agent-js-mocha)
* [Jasmine integration](https://github.com/reportportal/agent-js-jasmine)
* [Nightwatch integration](https://github.com/reportportal/agent-js-nightwatch)
* [Cucumber integration](https://github.com/reportportal/agent-js-cucumber)
* [Codecept integration](https://github.com/reportportal/agent-js-codecept)
* [Webdriverio integration](https://github.com/reportportal/agent-js-webdriverio)
* [Postman integration](https://github.com/reportportal/agent-js-postman)
* [Cucumber integration](https://github.com/reportportal/agent-js-cucumber)
* [Vitest integration](https://github.com/reportportal/agent-js-vitest)
* [Jasmine integration](https://github.com/reportportal/agent-js-jasmine)
* [TestCafe integration](https://github.com/reportportal/agent-js-testcafe)
* [Webdriverio integration](https://github.com/reportportal/agent-js-webdriverio)
* [Playwright integration](https://github.com/reportportal/agent-js-playwright)
* [Codecept integration](https://github.com/reportportal/agent-js-codecept)
* [Nightwatch integration](https://github.com/reportportal/agent-js-nightwatch)

Examples for test framework integrations from the list above described in [examples](https://github.com/reportportal/examples-js) repository.

Expand Down Expand Up @@ -61,7 +62,7 @@ When creating a client instance, you need to specify the following options:
| headers | Optional | {} | The object with custom headers for internal http client. |
| debug | Optional | false | This flag allows seeing the logs of the client. Useful for debugging. |
| isLaunchMergeRequired | Optional | false | Allows client to merge launches into one at the end of the run via saving their UUIDs to the temp files at filesystem . At the end of the run launches can be merged using `mergeLaunches` method. Temp file format: `rplaunch-${launch_uuid}.tmp`. |
| restClientConfig | Optional | Not set | The object with `agent` property for configure [http(s)](https://nodejs.org/api/https.html#https_https_request_url_options_callback) client, may contain other client options eg. `timeout`. For debugging and displaying logs you can set `debug: true` |
| restClientConfig | Optional | Not set | `axios` like http client [config](https://github.com/axios/axios#request-config). May contain `agent` property for configure [http(s)](https://nodejs.org/api/https.html#https_https_request_url_options_callback) client, and other client options eg. `timeout`. For debugging and displaying logs you can set `debug: true`. |
| launchUuidPrint | Optional | false | Whether to print the current launch UUID. |
| launchUuidPrintOutput | Optional | 'STDOUT' | Launch UUID printing output. Possible values: 'STDOUT', 'STDERR'. Works only if `launchUuidPrint` set to `true`. |
| token | Deprecated | Not set | Use `apiKey` instead. |
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.1.1
5.1.2-SNAPSHOT
40 changes: 26 additions & 14 deletions lib/report-portal-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class RPClient {
});
this.statistics = new Statistics(EVENT_NAME, agentParams);
this.launchUuid = '';
this.nonRetriedItemMap = new Map();
this.itemRetriesChainMap = new Map();
this.itemRetriesChainKeyMapByTempId = new Map();
}

// eslint-disable-next-line valid-jsdoc
Expand All @@ -67,10 +68,27 @@ class RPClient {
}
}

calculateNonRetriedItemMapKey(launchId, parentId, name, itemId = '') {
calculateItemRetriesChainMapKey(launchId, parentId, name, itemId = '') {
return `${launchId}__${parentId}__${name}__${itemId}`;
}

// eslint-disable-next-line valid-jsdoc
/**
*
* @Private
*/
cleanItemRetriesChain(tempIds) {
tempIds.forEach((id) => {
const key = this.itemRetriesChainKeyMapByTempId.get(id);

if (key) {
this.itemRetriesChainMap.delete(key);
}

this.itemRetriesChainKeyMapByTempId.delete(id);
});
}

getUniqId() {
return UniqId();
}
Expand Down Expand Up @@ -488,20 +506,17 @@ class RPClient {
parentPromise = parentObj.promiseStart;
}

const itemKey = this.calculateNonRetriedItemMapKey(
const itemKey = this.calculateItemRetriesChainMapKey(
launchTempId,
parentTempId,
testItemDataRQ.name,
testItemDataRQ.uniqueId,
);
const firstNonRetriedItemPromise = testItemDataRQ.retry && this.nonRetriedItemMap.get(itemKey);
if (firstNonRetriedItemPromise) {
parentPromise = Promise.all([parentPromise, firstNonRetriedItemPromise]);
}
const executionItemPromise = testItemDataRQ.retry && this.itemRetriesChainMap.get(itemKey);

const tempId = this.getUniqId();
this.map[tempId] = this.getNewItemObj((resolve, reject) => {
parentPromise.then(
(executionItemPromise || parentPromise).then(
() => {
const realLaunchId = this.map[launchTempId].realId;
let url = 'item/';
Expand All @@ -515,7 +530,6 @@ class RPClient {
(response) => {
this.logDebug(`Success start item with tempId ${tempId}`, response);
this.map[tempId].realId = response.id;
this.nonRetriedItemMap.delete(itemKey);
resolve(response);
},
(error) => {
Expand All @@ -531,10 +545,8 @@ class RPClient {
);
});
this.map[parentMapId].children.push(tempId);

if (!testItemDataRQ.retry) {
this.nonRetriedItemMap.set(itemKey, this.map[tempId].promiseStart);
}
this.itemRetriesChainKeyMapByTempId.set(tempId, itemKey);
this.itemRetriesChainMap.set(itemKey, this.map[tempId].promiseStart);

return {
tempId,
Expand Down Expand Up @@ -602,7 +614,7 @@ class RPClient {
}
});
}

this.cleanItemRetriesChain(itemObj.children);
this.cleanMap(itemObj.children);

this.logDebug(`Finish test item with tempId ${itemTempId}`, finishTestItemRQ);
Expand Down
23 changes: 10 additions & 13 deletions spec/report-portal-client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ describe('ReportPortal javascript client', () => {
});
});

describe('calculateNonRetriedItemMapKey', () => {
describe('calculateItemRetriesChainMapKey', () => {
it("should return correct parameter's string", () => {
const client = new RPClient({
apiKey: 'test',
project: 'test',
endpoint: 'https://abc.com',
});

const str = client.calculateNonRetriedItemMapKey('lId', 'pId', 'name', 'itemId');
const str = client.calculateItemRetriesChainMapKey('lId', 'pId', 'name', 'itemId');

expect(str).toEqual('lId__pId__name__itemId');
});
Expand All @@ -83,7 +83,7 @@ describe('ReportPortal javascript client', () => {
endpoint: 'https://abc.com',
});

const str = client.calculateNonRetriedItemMapKey('lId', 'pId', 'name');
const str = client.calculateItemRetriesChainMapKey('lId', 'pId', 'name');

expect(str).toEqual('lId__pId__name__');
});
Expand Down Expand Up @@ -725,17 +725,17 @@ describe('ReportPortal javascript client', () => {
promiseStart: Promise.resolve(),
},
};
spyOn(client.nonRetriedItemMap, 'get').and.resolveTo();
spyOn(client.itemRetriesChainMap, 'get').and.resolveTo();
spyOn(client.restClient, 'create').and.resolveTo({});
spyOn(client, 'getUniqId').and.returnValue('4n5pxq24kpiob12og9');

const result = client.startTestItem({ retry: true }, 'id1', 'id');
const result = client.startTestItem({ retry: false }, 'id1', 'id');

expect(result.tempId).toEqual('4n5pxq24kpiob12og9');
return expectAsync(result.promise).toBeResolved();
});

it('should call nonRetriedItemMap if retry is false', () => {
it('should get previous try promise from itemRetriesChainMap if retry is true', () => {
const client = new RPClient({
apiKey: 'startLaunchTest',
endpoint: 'https://rp.us/api/v1',
Expand All @@ -754,17 +754,14 @@ describe('ReportPortal javascript client', () => {
promiseStart: Promise.resolve(),
},
};
spyOn(client, 'calculateNonRetriedItemMapKey').and.returnValue('id1__name__');
spyOn(client, 'calculateItemRetriesChainMapKey').and.returnValue('id1__name__');
spyOn(client, 'getUniqId').and.returnValue('4n5pxq24kpiob12og9');
spyOn(client.map['4n5pxq24kpiob12og9'], 'promiseStart').and.resolveTo();
spyOn(client.nonRetriedItemMap, 'set');
spyOn(client.itemRetriesChainMap, 'get');

client.startTestItem({ retry: false }, 'id1');
client.startTestItem({ retry: true }, 'id1');

expect(client.nonRetriedItemMap.set).toHaveBeenCalledWith(
'id1__name__',
client.map['4n5pxq24kpiob12og9'].promiseStart,
);
expect(client.itemRetriesChainMap.get).toHaveBeenCalledWith('id1__name__');
});
});

Expand Down

0 comments on commit 6df9f62

Please sign in to comment.