From 6f941afbddfaee330606c62eb1bdd0d1902e618e Mon Sep 17 00:00:00 2001 From: David Calhoun Date: Tue, 10 Dec 2024 10:56:31 -0500 Subject: [PATCH] ci: Log processes using the Appium port --- .../__device-tests__/helpers/appium-local.js | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/packages/react-native-editor/__device-tests__/helpers/appium-local.js b/packages/react-native-editor/__device-tests__/helpers/appium-local.js index a73937f38e419..86d57c820feff 100644 --- a/packages/react-native-editor/__device-tests__/helpers/appium-local.js +++ b/packages/react-native-editor/__device-tests__/helpers/appium-local.js @@ -6,6 +6,41 @@ const childProcess = require( 'child_process' ); // Spawns an appium process. const start = ( { port = 4723, flags } ) => new Promise( ( resolve, reject ) => { + // Log all processes using the same port + childProcess.exec( `lsof -i :${ port }`, ( err, stdout, stderr ) => { + if ( err ) { + // eslint-disable-next-line no-console + console.error( `>>>> Error executing lsof: ${ err }` ); + return; + } + if ( stderr ) { + // eslint-disable-next-line no-console + console.error( `>>>> stderr: ${ stderr }` ); + return; + } + // eslint-disable-next-line no-console + console.log( `>>>> Processes using port ${ port }:\n${ stdout }` ); + } ); + + // Kill all processes using the same port + childProcess.exec( + `lsof -t -i :${ port } | xargs kill -9`, + ( err, stdout, stderr ) => { + if ( err ) { + // eslint-disable-next-line no-console + console.error( `>>>> Error killing processes: ${ err }` ); + return; + } + if ( stderr ) { + // eslint-disable-next-line no-console + console.error( `>>>> stderr: ${ stderr }` ); + return; + } + // eslint-disable-next-line no-console + console.log( `>>>> Killed processes using port ${ port }` ); + } + ); + const args = [ '--port', port.toString(),