Files
mattermostest/e2e/modules/environment.js
Devin Binnie dcbb8b7a91 Fix bad path name for user data dir, upgrade node-abi (#3406)
* Fix bad path name for user data dir, upgrade node-abi

* Run windows e2e

* Enable Windows tests and fix linux e2e crash

* chore: remove redundant dependencies and environment variables in e2e workflow

* fix: resolve Linux GPU process initialization errors in GitHub Actions

* Fix linux tests

* Fix lint

* fix: Enhance GPU handling to prevent process crashes in E2E tests

This commit addresses GPU-related stability issues in our E2E test environment by:

1. Updating GPU helper utility with more comprehensive disabling methods
2. Adding environment variables to force software rendering
3. Configuring Electron to use in-process GPU rendering
4. Adding additional Linux dependencies for better GPU support
5. Expanding command-line flags to mitigate GPU process crashes

The changes include modifications to:
- e2e/utils/gpu-helper.js
- e2e/modules/environment.js
- .github/workflows/e2e-functional-template.yml
- .github/actions/install-os-dependencies/action.yaml

* Fix linux tests

* Fix linux tests

* Fix linux tests

* Fix linux tests

* Fix linux tests

* Revert "chore: remove redundant dependencies and environment variables in e2e workflow"

This reverts commit 6a8eb0cbee155c3fd3f26df8d45af8c1f5cf2f12.

* run tests with xvfb-run --auto-servernum

* change ubuntu-runner to use latest

* change ubuntu-runner to use 24.04 version

* fix linux tests

* fix linux tests

* add preload test script

* add preload test script

* add preload test script

* update preload script

* reset all changes made to fix linux e2e error

* reset all changes made to fix linux e2e error

* reset all changes made to fix linux e2e error

* fix linux package instalation

* fix chrome sandbox permission issue

* bump electron version to 36.1.0

* Revert "bump electron version to 36.1.0"

This reverts commit 4a9bf858754c0c1909b3626f703578913adf3714.

* install dbus and declare DBUS_SYSTEM_BUS_ADDRESS

* fix dbus error

* fix dbus error

* fix dbus error

* fix dbus error

* fix: Try the community suggestion

-  https://github.com/actions/runner-images/issues/12127#issuecomment-2854346891

* change libasound2 to libasound2t64

* use gcc-12-aarch64-linux-gnu instead of gcc-aarch64-linux-gnu

* remove multilib

* fix xvfb crash

* fix: add PW_CHROMIUM_ARGS

* fix: add --disable-gpu-sandbox to the e2e run command

* fix: windows job

* pass version to electron rebuild

* fix post install script under /e2e

* Revert "fix post install script under /e2e"

This reverts commit 01efeed2e5038684c0aea5bb0be837b7041be8ca.

* skip postinstall scipt for windows job

* hardcode electron version in the e2e/package.json

* update script

* Revert "update script"

This reverts commit 078d197e44dc78972876a977f4a91182d89024b6.

* update script

* reset

* upgrade electron/rebuild package

* Revert "upgrade electron/rebuild package"

This reverts commit 25b144df05152b0bc112db6473263bfd68850874.

* Patch electron/rebuild

* Fix macOS test

---------

Co-authored-by: yasserfaraazkhan <attitude3cena.yf@gmail.com>
Co-authored-by: Mattermost Build <build@mattermost.com>
2025-06-19 10:39:16 -04:00

340 lines
10 KiB
JavaScript

// Copyright (c) 2015-2016 Yuya Ochiai
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
'use strict';
const {execSync} = require('child_process');
const fs = require('fs');
const path = require('path');
const chai = require('chai');
const {ipcRenderer} = require('electron');
const {_electron: electron} = require('playwright');
const ps = require('ps-node');
const {SHOW_SETTINGS_WINDOW} = require('src/common/communication');
const {asyncSleep, mkDirAsync, rmDirAsync, unlinkAsync} = require('./utils');
chai.should();
const sourceRootDir = path.join(__dirname, '../..');
const electronBinaryPath = (() => {
if (process.platform === 'darwin') {
return path.join(sourceRootDir, 'node_modules/electron/dist/Electron.app/Contents/MacOS/Electron');
}
const exeExtension = (process.platform === 'win32') ? '.exe' : '';
return path.join(sourceRootDir, 'node_modules/electron/dist/electron' + exeExtension);
})();
const userDataDir = path.join(sourceRootDir, 'e2e/testUserData');
const configFilePath = path.join(userDataDir, 'config.json');
const downloadsFilePath = path.join(userDataDir, 'downloads.json');
const downloadsLocation = path.join(userDataDir, 'Downloads');
const boundsInfoPath = path.join(userDataDir, 'bounds-info.json');
const appUpdatePath = path.join(userDataDir, 'app-update.yml');
const exampleURL = 'http://example.com/';
const mattermostURL = process.env.MM_TEST_SERVER_URL || 'http://localhost:8065/';
if (process.platform === 'win32') {
const robot = require('robotjs');
robot.mouseClick();
}
const exampleServer = {
name: 'example',
url: exampleURL,
order: 0,
tabs: [
{
name: 'TAB_MESSAGING',
order: 0,
isOpen: true,
},
{
name: 'TAB_FOCALBOARD',
order: 1,
},
{
name: 'TAB_PLAYBOOKS',
order: 2,
},
],
lastActiveTab: 0,
};
const githubServer = {
name: 'github',
url: 'https://github.com/',
order: 1,
tabs: [
{
name: 'TAB_MESSAGING',
order: 0,
isOpen: true,
},
{
name: 'TAB_FOCALBOARD',
order: 1,
isOpen: true,
},
{
name: 'TAB_PLAYBOOKS',
order: 2,
isOpen: true,
},
],
lastActiveTab: 0,
};
const demoConfig = {
version: 3,
teams: [exampleServer, githubServer],
showTrayIcon: false,
trayIconTheme: 'light',
minimizeToTray: false,
notifications: {
flashWindow: 0,
bounceIcon: false,
bounceIconType: 'informational',
},
showUnreadBadge: true,
useSpellChecker: true,
enableHardwareAcceleration: true,
autostart: true,
hideOnStart: false,
spellCheckerLocales: [],
darkMode: false,
lastActiveTeam: 0,
startInFullscreen: false,
autoCheckForUpdates: true,
appLanguage: 'en',
logLevel: 'silly',
};
const demoMattermostConfig = {
...demoConfig,
teams: [{
...exampleServer,
url: mattermostURL,
}, githubServer],
};
const cmdOrCtrl = process.platform === 'darwin' ? 'command' : 'control';
module.exports = {
sourceRootDir,
configFilePath,
downloadsFilePath,
downloadsLocation,
userDataDir,
boundsInfoPath,
appUpdatePath,
exampleURL,
mattermostURL,
demoConfig,
demoMattermostConfig,
cmdOrCtrl,
async clearElectronInstances() {
return new Promise((resolve, reject) => {
ps.lookup({
command: process.platform === 'darwin' ? 'Electron' : 'electron',
}, (err, resultList) => {
if (err) {
reject(err);
}
resultList.forEach((process) => {
if (process && process.command === electronBinaryPath && !process.arguments.some((arg) => arg.includes('electron-mocha'))) {
ps.kill(process.pid);
}
});
resolve();
});
});
},
cleanTestConfig() {
[configFilePath, downloadsFilePath, boundsInfoPath].forEach((file) => {
try {
fs.unlinkSync(file);
} catch (err) {
if (err.code !== 'ENOENT') {
// eslint-disable-next-line no-console
console.error(err);
}
}
});
},
async cleanTestConfigAsync() {
await Promise.all(
[configFilePath, downloadsFilePath, boundsInfoPath].map((file) => {
return unlinkAsync(file);
}),
);
},
cleanDataDir() {
try {
fs.rmdirSync(userDataDir, {recursive: true});
} catch (err) {
if (err.code !== 'ENOENT') {
// eslint-disable-next-line no-console
console.error(err);
}
}
},
cleanDataDirAsync() {
return rmDirAsync(userDataDir);
},
createTestUserDataDir() {
if (!fs.existsSync(userDataDir)) {
fs.mkdirSync(userDataDir);
}
},
clipboard(textToCopy) {
switch (process.platform) {
case 'linux':
execSync(`echo "${textToCopy}" | xsel --clipboard`);
break;
case 'win32':
execSync(`echo ${textToCopy} | clip`);
break;
case 'darwin':
execSync(`pbcopy <<< ${textToCopy}`);
break;
}
},
async createTestUserDataDirAsync() {
await mkDirAsync(userDataDir);
},
async getApp(args = []) {
const options = {
downloadsPath: downloadsLocation,
env: {
...process.env,
RESOURCES_PATH: userDataDir,
},
executablePath: electronBinaryPath,
args: [`${path.join(sourceRootDir, 'e2e/dist')}`, `--user-data-dir=${userDataDir}`, '--disable-dev-shm-usage', '--disable-dev-mode', '--disable-gpu', '--no-sandbox', ...args],
};
return electron.launch(options).then(async (eapp) => {
await eapp.evaluate(async ({app}) => {
const promise = new Promise((resolve) => {
app.on('e2e-app-loaded', () => {
resolve();
});
});
return promise;
});
return eapp;
});
},
async getServerMap(app) {
const map = {};
await Promise.all(app.windows().
filter((win) => !win.url().includes('mattermost-desktop://')).
map(async (win) => {
return win.evaluate(async () => {
if (!window.testHelper) {
return null;
}
const info = await window.testHelper.getViewInfoForTest();
return {viewName: `${info.serverName}___${info.viewType}`, webContentsId: info.webContentsId};
}).then((result) => {
if (result) {
map[result.viewName] = {win, webContentsId: result.webContentsId};
}
});
}));
return map;
},
async loginToMattermost(window) {
await asyncSleep(1000);
await window.waitForSelector('#input_loginId');
await window.waitForSelector('#input_password-input');
await window.waitForSelector('#saveSetting');
let username = process.env.MM_TEST_USERNAME;
switch (process.platform) {
case 'darwin':
username = 'success+sysadmin+macos@simulator.amazonses.com';
break;
case 'linux':
username = 'success+sysadmin+linux@simulator.amazonses.com';
break;
case 'win32':
username = 'success+sysadmin+windows@simulator.amazonses.com';
break;
default:
throw new Error('Unsupported platform');
}
await window.type('#input_loginId', username);
await window.type('#input_password-input', process.env.MM_TEST_PASSWORD);
await window.click('#saveSetting');
},
async openDownloadsDropdown(app) {
const mainWindow = app.windows().find((window) => window.url().includes('index'));
await mainWindow.waitForLoadState();
await mainWindow.bringToFront();
const dlButtonLocator = await mainWindow.waitForSelector('.DownloadsDropdownButton');
await dlButtonLocator.click();
await asyncSleep(500);
const downloadsWindow = app.windows().find((window) => window.url().includes('downloadsDropdown.html'));
await downloadsWindow.waitForLoadState();
await downloadsWindow.bringToFront();
await downloadsWindow.isVisible('.DownloadsDropdown');
return downloadsWindow;
},
async downloadsDropdownIsOpen(app) {
const downloadsWindow = app.windows().find((window) => window.url().includes('downloadsDropdown.html'));
const result = await downloadsWindow.isVisible('.DownloadsDropdown');
return result;
},
addClientCommands(client) {
client.addCommand('loadSettingsPage', function async() {
ipcRenderer.send(SHOW_SETTINGS_WINDOW);
});
client.addCommand('isNodeEnabled', function async() {
return this.execute(() => {
try {
if (require('child_process')) {
return true;
}
return false;
} catch (e) {
return false;
}
}).then((requireResult) => {
return requireResult.value;
});
});
client.addCommand('waitForAppOptionsAutoSaved', function async() {
const ID_APP_OPTIONS_SAVE_INDICATOR = '#appOptionsSaveIndicator';
const TIMEOUT = 5000;
return this.
waitForVisible(ID_APP_OPTIONS_SAVE_INDICATOR, TIMEOUT).
waitForVisible(ID_APP_OPTIONS_SAVE_INDICATOR, TIMEOUT, true);
});
},
// execute the test only when `condition` is true
shouldTest(it, condition) {
return condition ? it : it.skip;
},
isOneOf(platforms) {
return (platforms.indexOf(process.platform) !== -1);
},
};