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

Release 5.0.14 #173

Merged
merged 6 commits into from
Oct 5, 2023
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
6 changes: 3 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
"sourceType": "module",
"project": "./tsconfig.eslint.json"
},
"globals": {
"expectAsync": true
Expand All @@ -19,8 +20,6 @@
"jasmine": true
},
"rules": {
"indent": ["error", 2],
"max-len": ["error", 120],
"valid-jsdoc": ["error", { "requireReturn": false }],
"consistent-return": 0,
"@typescript-eslint/no-plusplus": 0,
Expand All @@ -35,6 +34,7 @@
"@typescript-eslint/dot-notation": 0,
"@typescript-eslint/ban-ts-comment": 0,
"@typescript-eslint/no-var-requires": 0,
"@typescript-eslint/no-floating-promises": 2,
"max-classes-per-file": 0
}
}
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @AmsterGet @Bam6ycha
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### Added
- `Promise.allSettled` polyfill to support NodeJS 10
### Fixed
- Reporting is down on error with collect request on reporting start
- Can not read property `realId` of undefined during reporting, resolves [#99](https://github.com/reportportal/agent-js-playwright/issues/99)

## [5.0.13] - 2023-08-28
### Added
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.0.13
5.0.14-SNAPSHOT
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,
}),
),
),
);
};
}
47 changes: 27 additions & 20 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 @@ -115,11 +116,11 @@ class RPClient {
return RestClient.request('GET', url, {}, { headers: this.headers });
}

triggerStatisticsEvent() {
async triggerStatisticsEvent() {
if (process.env.REPORTPORTAL_CLIENT_JS_NO_ANALYTICS) {
return;
}
this.statistics.trackEvent();
await this.statistics.trackEvent();
}

/**
Expand Down Expand Up @@ -206,7 +207,7 @@ class RPClient {
);
});
}
this.triggerStatisticsEvent();
this.triggerStatisticsEvent().catch(console.error);
return {
tempId,
promise: this.map[tempId].promiseStart,
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
12 changes: 12 additions & 0 deletions spec/statistics.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,17 @@ describe('Statistics', () => {

expect(axios.post).toHaveBeenCalledOnceWith(url, baseRequestValidation);
});

it('Should properly handle errors if any', async () => {
const statistics = new Statistics(eventName, agentParams);
const errorMessage = 'Error message';

spyOn(axios, 'post').and.throwError(errorMessage);
spyOn(console, 'error');

await statistics.trackEvent();

expect(console.error).toHaveBeenCalledWith(errorMessage);
});
});
});
30 changes: 17 additions & 13 deletions statistics/statistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,24 @@
}

async trackEvent() {
const requestBody = {
client_id: await getClientId(),
events: [
{
name: this.eventName,
params: this.eventParams,
},
],
};
try {
const requestBody = {
client_id: await getClientId(),
events: [
{
name: this.eventName,
params: this.eventParams,
},
],
};

await axios.post(
`https://www.google-analytics.com/mp/collect?measurement_id=${MEASUREMENT_ID}&api_secret=${API_KEY}`,
requestBody,
);
await axios.post(
`https://www.google-analytics.com/mp/collect?measurement_id=${MEASUREMENT_ID}&api_secret=${API_KEY}`,
requestBody,
);
} catch (error) {
console.error(error.message);

Check warning on line 47 in statistics/statistics.js

View workflow job for this annotation

GitHub Actions / test (10)

Unexpected console statement

Check warning on line 47 in statistics/statistics.js

View workflow job for this annotation

GitHub Actions / test (12)

Unexpected console statement

Check warning on line 47 in statistics/statistics.js

View workflow job for this annotation

GitHub Actions / test (14)

Unexpected console statement

Check warning on line 47 in statistics/statistics.js

View workflow job for this annotation

GitHub Actions / test (16)

Unexpected console statement

Check warning on line 47 in statistics/statistics.js

View workflow job for this annotation

GitHub Actions / test (18)

Unexpected console statement

Check warning on line 47 in statistics/statistics.js

View workflow job for this annotation

GitHub Actions / test (20)

Unexpected console statement
}
}
}

Expand Down
Loading