From c71004d974444e8cb84dc03343ff6df63b6ede69 Mon Sep 17 00:00:00 2001 From: VickyStash Date: Wed, 21 Feb 2024 10:04:44 +0100 Subject: [PATCH 1/4] [TS migration] Migrate 'installApp.js' test --- tests/e2e/testRunner.js | 4 ++-- tests/e2e/utils/installApp.js | 25 ------------------------- tests/e2e/utils/installApp.ts | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+), 27 deletions(-) delete mode 100644 tests/e2e/utils/installApp.js create mode 100644 tests/e2e/utils/installApp.ts diff --git a/tests/e2e/testRunner.js b/tests/e2e/testRunner.js index cbdb22de6c63..dfdd5238a39b 100644 --- a/tests/e2e/testRunner.js +++ b/tests/e2e/testRunner.js @@ -213,8 +213,8 @@ const runTests = async () => { let progressLog = Logger.progressInfo('Installing apps and reversing port'); - await installApp('android', config.MAIN_APP_PACKAGE, mainAppPath); - await installApp('android', config.DELTA_APP_PACKAGE, deltaAppPath); + await installApp(config.MAIN_APP_PACKAGE, mainAppPath, 'android'); + await installApp(config.DELTA_APP_PACKAGE, deltaAppPath, 'android'); await reversePort(); progressLog.done(); diff --git a/tests/e2e/utils/installApp.js b/tests/e2e/utils/installApp.js deleted file mode 100644 index 50fc8602762e..000000000000 --- a/tests/e2e/utils/installApp.js +++ /dev/null @@ -1,25 +0,0 @@ -import execAsync from './execAsync'; -import * as Logger from './logger'; - -/** - * Installs the app on the currently connected device for the given platform. - * It removes the app first if it already exists, so it's a clean installation. - * - * @param {String} platform - * @param {String} packageName - * @param {String} path - * @returns {Promise} - */ -export default function (platform = 'android', packageName, path) { - if (platform !== 'android') { - throw new Error(`installApp() missing implementation for platform: ${platform}`); - } - - // Uninstall first, then install - return execAsync(`adb uninstall ${packageName}`) - .catch((e) => { - // Ignore errors - Logger.warn('Failed to uninstall app:', e); - }) - .finally(() => execAsync(`adb install ${path}`)); -} diff --git a/tests/e2e/utils/installApp.ts b/tests/e2e/utils/installApp.ts new file mode 100644 index 000000000000..4bb2f312b834 --- /dev/null +++ b/tests/e2e/utils/installApp.ts @@ -0,0 +1,24 @@ +import type {ExecException} from 'child_process'; +import execAsync from './execAsync'; +import * as Logger from './logger'; + +/** + * Installs the app on the currently connected device for the given platform. + * It removes the app first if it already exists, so it's a clean installation. + */ +export default function (packageName: string, path: string, platform = 'android'): Promise { + if (platform !== 'android') { + throw new Error(`installApp() missing implementation for platform: ${platform}`); + } + + // Uninstall first, then install + return ( + execAsync(`adb uninstall ${packageName}`) + .catch((error: ExecException) => { + // Ignore errors + Logger.warn('Failed to uninstall app:', error); + }) + // eslint-disable-next-line @typescript-eslint/no-misused-promises + .finally(() => execAsync(`adb install ${path}`)) + ); +} From 0101e8e5c8075b91f09c66dc3ab17829a7a3db90 Mon Sep 17 00:00:00 2001 From: VickyStash Date: Wed, 21 Feb 2024 13:26:20 +0100 Subject: [PATCH 2/4] Minor code improvement --- tests/e2e/testRunner.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/e2e/testRunner.js b/tests/e2e/testRunner.js index dfdd5238a39b..5eb8dba7b48b 100644 --- a/tests/e2e/testRunner.js +++ b/tests/e2e/testRunner.js @@ -213,8 +213,8 @@ const runTests = async () => { let progressLog = Logger.progressInfo('Installing apps and reversing port'); - await installApp(config.MAIN_APP_PACKAGE, mainAppPath, 'android'); - await installApp(config.DELTA_APP_PACKAGE, deltaAppPath, 'android'); + await installApp(config.MAIN_APP_PACKAGE, mainAppPath); + await installApp(config.DELTA_APP_PACKAGE, deltaAppPath); await reversePort(); progressLog.done(); From 94583c95d1697a8fcce3122b5bf488e34fd18122 Mon Sep 17 00:00:00 2001 From: VickyStash Date: Thu, 22 Feb 2024 10:40:57 +0100 Subject: [PATCH 3/4] Replace module.exports with export --- tests/e2e/utils/logger.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/tests/e2e/utils/logger.js b/tests/e2e/utils/logger.js index d0770b7aa8e4..6a39b4c10328 100644 --- a/tests/e2e/utils/logger.js +++ b/tests/e2e/utils/logger.js @@ -66,12 +66,4 @@ const error = (...args) => { log(...lines); }; -module.exports = { - log, - info, - warn, - note, - error, - success, - writeToLogFile, -}; +export {log, info, warn, note, error, success, writeToLogFile}; From 919ccd0bea01cd36837a56de87c296769676aa0a Mon Sep 17 00:00:00 2001 From: VickyStash Date: Mon, 26 Feb 2024 08:41:03 +0100 Subject: [PATCH 4/4] Improve return type --- tests/e2e/utils/installApp.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/e2e/utils/installApp.ts b/tests/e2e/utils/installApp.ts index 4bb2f312b834..b443344e6f02 100644 --- a/tests/e2e/utils/installApp.ts +++ b/tests/e2e/utils/installApp.ts @@ -1,12 +1,13 @@ import type {ExecException} from 'child_process'; import execAsync from './execAsync'; +import type {PromiseWithAbort} from './execAsync'; import * as Logger from './logger'; /** * Installs the app on the currently connected device for the given platform. * It removes the app first if it already exists, so it's a clean installation. */ -export default function (packageName: string, path: string, platform = 'android'): Promise { +export default function (packageName: string, path: string, platform = 'android'): PromiseWithAbort { if (platform !== 'android') { throw new Error(`installApp() missing implementation for platform: ${platform}`); }