33 * Test script for creating lockdown service, starting CoreDeviceProxy, and creating tunnel
44 * This script demonstrates the tunnel creation workflow for all connected devices
55 */
6- import { logger } from '@appium/support' ;
6+ import { logger , node } from '@appium/support' ;
77import _ from 'lodash' ;
88/* eslint-disable import/no-unresolved */
99import {
@@ -18,9 +18,6 @@ import {
1818import { strongbox } from '@appium/strongbox' ;
1919import path from 'path' ;
2020import fs from 'fs' ;
21- import { fileURLToPath } from 'url' ;
22-
23- const __filename = fileURLToPath ( import . meta. url ) ;
2421
2522const log = logger . getLogger ( 'TunnelCreation' ) ;
2623const TUNNEL_REGISTRY_PORT = 'tunnelRegistryPort' ;
@@ -287,8 +284,13 @@ class TunnelCreator {
287284 }
288285}
289286
290- // Helper function to parse string arguments
291- const parseArg = ( args , flagName ) => {
287+ /**
288+ * Helper function to parse string arguments
289+ * @param {string[] } args - Array of command line arguments
290+ * @param {string } flagName - Name of the flag to parse (e.g. '--udid')
291+ * @returns {string|undefined } The value of the flag if found, undefined otherwise
292+ */
293+ function parseArg ( args , flagName ) {
292294 const equalsArg = args . find ( ( arg ) => arg . startsWith ( `${ flagName } =` ) ) ;
293295 if ( equalsArg ) {
294296 const value = equalsArg . split ( '=' ) [ 1 ] ;
@@ -305,32 +307,7 @@ const parseArg = (args, flagName) => {
305307 return undefined ;
306308} ;
307309
308- /**
309- * Calculates the path to the current module's root folder
310- *
311- * @returns {string } The full path to module root
312- * @throws {Error } If the current module root folder cannot be determined
313- */
314- const getModuleRoot = _ . memoize ( function getModuleRoot ( ) {
315- let currentDir = path . dirname ( path . resolve ( __filename ) ) ;
316- let isAtFsRoot = false ;
317- while ( ! isAtFsRoot ) {
318- const manifestPath = path . join ( currentDir , 'package.json' ) ;
319- try {
320- if (
321- fs . existsSync ( manifestPath ) &&
322- JSON . parse ( fs . readFileSync ( manifestPath , 'utf8' ) ) . name === 'appium-xcuitest-driver'
323- ) {
324- return currentDir ;
325- }
326- } catch { }
327- currentDir = path . dirname ( currentDir ) ;
328- isAtFsRoot = currentDir . length <= path . dirname ( currentDir ) . length ;
329- }
330- throw new Error ( 'Cannot find the root folder of the appium-xcuitest-driver Node.js module' ) ;
331- } ) ;
332-
333- const BOOTSTRAP_PATH = getModuleRoot ( ) ;
310+ const BOOTSTRAP_PATH = node . getModuleRootSync ( 'appium-xcuitest-driver' , import . meta. url ) ;
334311
335312/**
336313 */
0 commit comments