From 2837b764bd9a24f1c89438dc77c33bb1e3cb3d84 Mon Sep 17 00:00:00 2001 From: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Date: Mon, 12 Sep 2022 10:43:19 -0400 Subject: [PATCH] E2E omnibus fixes (#2249) * Add environment variable for E2E test server * Fix auto updater test * Kill macOS processes after test as well * No dot * Just do it for all of them * Force focus of main window on tests * Fix a focus issue, try win.show() instead * Another windows hack * Oops can't spell Co-authored-by: Mattermod --- e2e/modules/environment.js | 27 ++++++++++++++++++++------- e2e/specs/popup.test.js | 2 +- e2e/specs/settings.test.js | 2 ++ webpack.config.base.js | 6 +++++- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/e2e/modules/environment.js b/e2e/modules/environment.js index d226fc9b..e6b0818b 100644 --- a/e2e/modules/environment.js +++ b/e2e/modules/environment.js @@ -29,8 +29,14 @@ const electronBinaryPath = (() => { const userDataDir = path.join(sourceRootDir, 'e2e/testUserData/'); const configFilePath = path.join(userDataDir, 'config.json'); const boundsInfoPath = path.join(userDataDir, 'bounds-info.json'); +const appUpdatePath = path.join(userDataDir, 'app-update.yml'); const exampleURL = 'http://example.com/'; -const mattermostURL = 'http://localhost:8065/'; +const mattermostURL = process.env.MM_TEST_SERVER_URL || 'http://localhost:8065/'; + +if (process.platform === 'win32') { + const robot = require('robotjs'); + robot.mouseClick(); +} const exampleTeam = { name: 'example', @@ -115,6 +121,7 @@ module.exports = { configFilePath, userDataDir, boundsInfoPath, + appUpdatePath, exampleURL, mattermostURL, demoConfig, @@ -122,13 +129,9 @@ module.exports = { cmdOrCtrl, async clearElectronInstances() { - if (process.platform !== 'win32') { - return Promise.resolve(); - } - return new Promise((resolve, reject) => { ps.lookup({ - command: 'electron', + command: process.platform === 'darwin' ? 'Electron' : 'electron', }, (err, resultList) => { if (err) { reject(err); @@ -175,6 +178,10 @@ module.exports = { async getApp(args = []) { const options = { + env: { + ...process.env, + RESOURCES_PATH: userDataDir, + }, executablePath: electronBinaryPath, args: [`${path.join(sourceRootDir, 'dist')}`, `--data-dir=${userDataDir}`, '--disable-dev-mode', ...args], }; @@ -188,8 +195,14 @@ module.exports = { // options.chromeDriverArgs.push('remote-debugging-port=9222'); //} return electron.launch(options).then(async (app) => { - // Make sure the app has time to fully load + // Make sure the app has time to fully load and that the window is focused await asyncSleep(1000); + const mainWindow = app.windows().find((window) => window.url().includes('index')); + const browserWindow = await app.browserWindow(mainWindow); + await browserWindow.evaluate((win) => { + win.show(); + return true; + }); return app; }); }, diff --git a/e2e/specs/popup.test.js b/e2e/specs/popup.test.js index 22e27528..6852f223 100644 --- a/e2e/specs/popup.test.js +++ b/e2e/specs/popup.test.js @@ -105,7 +105,7 @@ describe('popup', function desc() { const githubLink = await firstServer.waitForSelector('a.theme.markdown__link:has-text("GitHub account")'); githubLink.click(); const popupWindow = await this.app.waitForEvent('window'); - popupWindow.focus(); + await popupWindow.bringToFront(); const currentURL = popupWindow.url(); // Try and go back diff --git a/e2e/specs/settings.test.js b/e2e/specs/settings.test.js index 35115012..7915ad54 100644 --- a/e2e/specs/settings.test.js +++ b/e2e/specs/settings.test.js @@ -5,6 +5,7 @@ 'use strict'; const fs = require('fs'); +const path = require('path'); const {SHOW_SETTINGS_WINDOW} = require('../../src/common/communication'); @@ -20,6 +21,7 @@ describe('Settings', function desc() { env.createTestUserDataDir(); env.cleanTestConfig(); fs.writeFileSync(env.configFilePath, JSON.stringify(config)); + fs.writeFileSync(env.appUpdatePath, ''); await asyncSleep(1000); this.app = await env.getApp(); }); diff --git a/webpack.config.base.js b/webpack.config.base.js index 23401c18..604f6340 100644 --- a/webpack.config.base.js +++ b/webpack.config.base.js @@ -13,17 +13,21 @@ const webpack = require('webpack'); const VERSION = childProcess.execSync('git rev-parse --short HEAD').toString(); const isProduction = process.env.NODE_ENV === 'production'; +const isTest = process.env.NODE_ENV === 'test'; const isRelease = process.env.CIRCLE_BRANCH && process.env.CIRCLE_BRANCH.startsWith('release-'); const codeDefinitions = { __HASH_VERSION__: !isRelease && JSON.stringify(VERSION), - __CAN_UPGRADE__: JSON.stringify(process.env.CAN_UPGRADE === 'true'), + __CAN_UPGRADE__: isTest || JSON.stringify(process.env.CAN_UPGRADE === 'true'), __IS_NIGHTLY_BUILD__: JSON.stringify(process.env.CIRCLE_BRANCH === 'nightly'), __IS_MAC_APP_STORE__: JSON.stringify(process.env.IS_MAC_APP_STORE === 'true'), __SKIP_ONBOARDING_SCREENS__: JSON.stringify(process.env.MM_DESKTOP_BUILD_SKIPONBOARDINGSCREENS === 'true'), __DISABLE_GPU__: JSON.stringify(process.env.MM_DESKTOP_BUILD_DISABLEGPU === 'true'), }; codeDefinitions['process.env.NODE_ENV'] = JSON.stringify(process.env.NODE_ENV); +if (isTest) { + codeDefinitions['process.resourcesPath'] = 'process.env.RESOURCES_PATH'; +} module.exports = {