Files
team/e2e-tests/playwright/report.webhookgen.js
Harrison HealeyandGitHub daec1283e5 MM-69003 Mostly share ESLint config between web app and E2E tests (#36767)
* Switch Cypress to use shared ESLint config

* Run --fix in Cypress

* Manually fix remaining lint issues in Cypress

* Switch Playwright to use shared ESLint config

* Run --fix in Playwright

* Manually fix remaining lint issues in Playwright

* Install and cache web app deps during Cypress CI builds

This also caches the types and client package. That isn't needed currently
since it uses prepackaged versions of those, but I imagine we might change
that at some point.

* Run e2e-tests-check when ESLint plugin is updated

* Change E2E test GHA caching to cache all of web app node_modules

* Fix mismatch between cache save and restore

* Try bumping cache keys

* Copy step to install dependencies to server.run_cypress.sh

I don't know how this must've worked before, but if this fixes the issue,
it seems like neither Cypress nor Playwright actually use the cached
depenendencies.

* Try disabling caching entirely for Cypress tests

* Try bypassing makefile?

* Try also manually building dependencies in run_specs.sh

I don't know why this appears to duplicate run_cypress.sh and
run_playwright.sh, both of which are called run_test.sh which
might not be used any more as best I can tell.

* Try installing the web app dependencies in yet another place

* Disable the extra steps in server.prepare.sh specifically for Cypress

* Revert changes to update cache key and disable web app depenedency cache on Cypress builds
2026-06-09 20:50:58 +00:00

97 lines
3.9 KiB
JavaScript
Executable File

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
const fs = require('fs');
const dayjs = require('dayjs');
const duration = require('dayjs/plugin/duration');
dayjs.extend(duration);
const {TYPE, SERVER_TYPE, BRANCH, PULL_REQUEST, BUILD_ID, MM_ENV, MM_DOCKER_IMAGE, MM_DOCKER_TAG, RELEASE_DATE} =
process.env;
const resultsFile = 'results/reporter/results.json';
const summaryFile = 'results/summary.json';
const results = JSON.parse(fs.readFileSync(resultsFile, 'utf8'));
const summary = JSON.parse(fs.readFileSync(summaryFile, 'utf8'));
const passRate = (summary.passed * 100) / (summary.passed + summary.failed);
const totalSpecs = summary.passed + summary.failed;
const playwrightVersion = results.config.version;
const playwrightDuration = dayjs.duration(results.stats.duration, 'millisecond').format('HH:mm:ss');
function generateTitle() {
let dockerImageLink = '';
let releaseDate = '';
if (MM_DOCKER_IMAGE && MM_DOCKER_TAG) {
dockerImageLink = ` with [${MM_DOCKER_IMAGE}:${MM_DOCKER_TAG}](https://hub.docker.com/r/mattermostdevelopment/${MM_DOCKER_IMAGE}/tags?name=${MM_DOCKER_TAG})`;
}
if (RELEASE_DATE) {
releaseDate = ` for ${RELEASE_DATE}`;
}
let title = '';
switch (TYPE) {
case 'PR':
title = `E2E for Pull Request Build: [${BRANCH}](${PULL_REQUEST})${dockerImageLink}`;
break;
case 'RELEASE':
title = `E2E for Release Build${dockerImageLink}${releaseDate}`;
break;
case 'MASTER':
title = `E2E for Master Nightly Build (Prod tests)${dockerImageLink}`;
break;
case 'MASTER_UNSTABLE':
title = `E2E for Master Nightly Build (Unstable tests)${dockerImageLink}`;
break;
case 'CLOUD':
title = `E2E for Cloud Build (Prod tests)${dockerImageLink}${releaseDate}`;
break;
case 'CLOUD_UNSTABLE':
title = `E2E for Cloud Build (Unstable tests)${dockerImageLink}`;
break;
default:
title = `E2E for Build${dockerImageLink}`;
}
return title;
}
function generateWebhookBody() {
let testResult;
const testResults = [
{status: 'Passed', priority: 'none', cutOff: 100, color: '#43A047'},
{status: 'Failed', priority: 'low', cutOff: 98, color: '#FFEB3B'},
{status: 'Failed', priority: 'medium', cutOff: 95, color: '#FF9800'},
{status: 'Failed', priority: 'high', cutOff: 0, color: '#F44336'},
];
for (let i = 0; i < testResults.length; i++) {
if (passRate >= testResults[i].cutOff) {
testResult = testResults[i];
break;
}
}
const summaryField = `${passRate.toFixed(2)}% (${summary.passed}/${totalSpecs}) | ${playwrightDuration} | playwright@${playwrightVersion}`;
const serverTypeField = SERVER_TYPE ? '\nTest server: ' + SERVER_TYPE : '';
const mmEnvField = MM_ENV ? '\nTest server override: ' + MM_ENV : '';
const rollingReleaseMatchRegex = BUILD_ID?.match(/-rolling(?<version>[^-]+)-/);
const rollingReleaseFrom = rollingReleaseMatchRegex?.groups?.version;
const rollingReleaseFromField = rollingReleaseFrom ? `\nRolling release upgrade from: ${rollingReleaseFrom}` : '';
return {
username: 'Playwright UI Test',
icon_url: 'https://mattermost.com/wp-content/uploads/2022/02/icon_WS.png',
attachments: [
{
color: testResult.color,
author_name: 'Webapp End-to-end Testing (Playwright)',
author_icon: 'https://mattermost.com/wp-content/uploads/2022/02/icon_WS.png',
author_link: 'https://www.mattermost.com',
title: generateTitle(),
text: `${summaryField}${serverTypeField}${rollingReleaseFromField}${mmEnvField}`,
},
],
};
}
const webhookBody = generateWebhookBody();
process.stdout.write(JSON.stringify(webhookBody));