Skip to content

Commit

Permalink
MM-25527 Improve Cypress reporting to accommodate master/release/PR i…
Browse files Browse the repository at this point in the history
…n partial/full view (mattermost#5579)

* improve Cypress reporting to accommodate master/release/PR in partial/full view

* fix lint errors

Co-authored-by: Saturnino Abril <[email protected]>
  • Loading branch information
saturninoabril and Saturnino Abril committed May 26, 2020
1 parent 7a65be3 commit f41b533
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 22 deletions.
8 changes: 4 additions & 4 deletions e2e/save_report.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* For saving reports to Automation dashboard
* - DASHBOARD_ENABLE, DASHBOARD_ENDPOINT and DASHBOARD_TOKEN
* For sending hooks to Mattermost channels
* - WEBHOOK_URL and DIAGNOSTIC_WEBHOOK_URL
* - FULL_REPORT, WEBHOOK_URL and DIAGNOSTIC_WEBHOOK_URL
* Test type
* - TYPE=[type], e.g. "DAILY", "PR", "RELEASE"
* - TYPE=[type], e.g. "MASTER", "PR", "RELEASE"
*/

const {merge} = require('mochawesome-merge');
Expand Down Expand Up @@ -82,8 +82,8 @@ const saveReport = async () => {
}

// Send diagnostic report via webhook
// Send on "DAILY" type only
if (TYPE === 'DAILY' && DIAGNOSTIC_WEBHOOK_URL && DIAGNOSTIC_USER_ID && DIAGNOSTIC_TEAM_ID) {
// Send on "RELEASE" type only
if (TYPE === 'RELEASE' && DIAGNOSTIC_WEBHOOK_URL && DIAGNOSTIC_USER_ID && DIAGNOSTIC_TEAM_ID) {
const data = generateDiagnosticReport(summary, {userId: DIAGNOSTIC_USER_ID, teamId: DIAGNOSTIC_TEAM_ID});
await sendReport('test info for diagnostic analysis', DIAGNOSTIC_WEBHOOK_URL, data);
}
Expand Down
88 changes: 70 additions & 18 deletions e2e/utils/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

/* eslint-disable no-console */

const os = require('os');
const axios = require('axios');
const fse = require('fs-extra');

Expand Down Expand Up @@ -92,7 +93,15 @@ const result = [
];

function generateTestReport(summary, isUploadedToS3, reportLink) {
const {BRANCH, BROWSER} = process.env;
const {
BRANCH,
BROWSER,
BUILD_TAG,
FULL_REPORT,
HEADLESS,
PULL_REQUEST,
TYPE,
} = process.env;
const {statsFieldValue, stats} = summary;

let testResult;
Expand All @@ -112,29 +121,72 @@ function generateTestReport(summary, isUploadedToS3, reportLink) {
};
}

let dockerImageLink;
if (BUILD_TAG) {
dockerImageLink = `[mattermost-enterprise-edition:${BUILD_TAG}](https://hub.docker.com/r/mattermost/mattermost-enterprise-edition/tags?name=${BUILD_TAG})`;
}

let title;

switch (TYPE) {
case 'PR':
title = `E2E for Pull Request Build: [${BRANCH}](${PULL_REQUEST}) with ${BUILD_TAG ? dockerImageLink : ''}`;
break;
case 'RELEASE':
title = `E2E for Release Build with ${BUILD_TAG ? dockerImageLink : ''}`;
break;
case 'MASTER':
title = `E2E for Master Nightly Build (Prod tests) with ${BUILD_TAG ? dockerImageLink : ''}`;
break;
case 'MASTER_UNSTABLE':
title = `E2E for Master Nightly Build (Unstable tests) with ${BUILD_TAG ? dockerImageLink : ''}`;
break;
default:
title = 'Cypress UI Test';
}

if (FULL_REPORT) {
return {
username: 'Cypress UI Test',
icon_url: 'https://www.mattermost.org/wp-content/uploads/2016/04/icon.png',
attachments: [{
color: testResult.color,
author_name: 'Cypress UI Test',
author_icon: 'https://www.mattermost.org/wp-content/uploads/2016/04/icon.png',
author_link: 'https://www.mattermost.com',
title,
fields: [
{
short: false,
title: 'Environment',
value: `Branch: **${BRANCH}**, Browser: **${BROWSER}**`,
},
awsS3Fields,
{
short: false,
title: `Key metrics (required support: ${testResult.priority})`,
value: statsFieldValue,
},
],
}],
};
}

let quickSummary = `${stats.passPercent.toFixed(2)}% (${stats.passes}/${stats.tests}) in ${stats.suites} suites`;
if (isUploadedToS3) {
quickSummary = `[${quickSummary}](${reportLink})`;
}

return {
username: 'Cypress UI Test',
icon_url: 'https://www.mattermost.org/wp-content/uploads/2016/04/icon.png',
attachments: [{
color: testResult.color,
author_name: 'Cypress UI Test',
author_name: 'Webapp End-to-end Testing',
author_icon: 'https://www.mattermost.org/wp-content/uploads/2016/04/icon.png',
author_link: 'https://www.mattermost.com',
title: `Cypress UI Test Automation ${testResult.status}!`,
fields: [
{
short: false,
title: 'Environment',
value: `Branch: **${BRANCH}**, Browser: **${BROWSER}**`,
},
awsS3Fields,
{
short: false,
title: `Key metrics (required support: ${testResult.priority})`,
value: statsFieldValue,
},
],
image_url: 'https://pbs.twimg.com/profile_images/1044345247440896001/pXI1GDHW_bigger.jpg',
author_link: 'https://www.mattermost.com/',
title,
text: `${quickSummary} | ${(stats.duration / (60 * 1000)).toFixed(2)} mins | ${os.type()} ${BROWSER} (${HEADLESS === 'false' ? 'headed' : 'headless'})`,
}],
};
}
Expand Down

0 comments on commit f41b533

Please sign in to comment.