Skip to content

Commit

Permalink
EPMRPP-84778 || Fix realId of undefined (#171)
Browse files Browse the repository at this point in the history
* EPMRPP-84778 || Fix realId of undefined

* EPMRPP-84778 || Add Promise.allSettled polyfill

- This was added to support NodeJS 10
  • Loading branch information
Bam6ycha authored Oct 4, 2023
1 parent 92bc1d1 commit 63b2e8e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 17 deletions.
19 changes: 19 additions & 0 deletions lib/polyfills.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! Was added to support NodeJS 10.
if (!Promise.allSettled) {
Promise.allSettled = function (promises) {
return Promise.all(
promises.map((p) =>
Promise.resolve(p).then(
(value) => ({
status: 'fulfilled',
value,
}),
(error) => ({
status: 'rejected',
reason: error,
}),
),
),
);
};
}
41 changes: 24 additions & 17 deletions lib/report-portal-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { getClientConfig } = require('./commons/config');
const Statistics = require('../statistics/statistics');
const { EVENT_NAME } = require('../statistics/constants');
const { RP_STATUSES } = require('./constants/statuses');
require('./polyfills');

const MULTIPART_BOUNDARY = Math.floor(Math.random() * 10000000000).toString();

Expand Down Expand Up @@ -581,32 +582,38 @@ class RPClient {

itemObj.finishSend = true;
this.logDebug(`Finish all children for test item with tempId ${itemTempId}`);
Promise.all(
Promise.allSettled(
itemObj.children.map((itemId) => this.map[itemId] && this.map[itemId].promiseFinish),
).then(
() => {
)
.then((results) => {
if (this.debug) {
results.forEach((result, index) => {
if (result.status === 'fulfilled') {
this.logDebug(
`Successfully finish child with tempId ${itemObj.children[index]}
of test item with tempId ${itemTempId}`,
);
} else {
this.logDebug(
`Failed to finish child with tempId ${itemObj.children[index]}
of test item with tempId ${itemTempId}`,
);
}
});
}

this.cleanMap(itemObj.children);
this.logDebug(
`All children for test item with tempId ${itemTempId} successfully finished.`,
);

this.logDebug(`Finish test item with tempId ${itemTempId}`, finishTestItemRQ);
this.finishTestItemPromiseStart(
itemObj,
itemTempId,
Object.assign(finishTestItemData, { launchUuid: this.launchUuid }),
);
},
() => {
this.cleanMap(itemObj.children);
})
.catch(() => {
this.logDebug(`Error finish children of test item with tempId ${itemTempId}`);
this.logDebug(`Finish test item with tempId ${itemTempId}`, finishTestItemRQ);
this.finishTestItemPromiseStart(
itemObj,
itemTempId,
Object.assign(finishTestItemData, { launchUuid: this.launchUuid }),
);
},
);
});

return {
tempId: itemTempId,
Expand Down

0 comments on commit 63b2e8e

Please sign in to comment.