File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import path from 'node:path';
66import {
77 ensureAndroidEmulatorBooted ,
88 parseAndroidAvdList ,
9+ parseAndroidEmulatorAvdNameOutput ,
910 parseAndroidFeatureListForTv ,
1011 parseAndroidTargetFromCharacteristics ,
1112 resolveAndroidAvdName ,
@@ -121,6 +122,12 @@ test('parseAndroidAvdList drops empty lines', () => {
121122 assert . deepEqual ( listed , [ 'Pixel_9_Pro_XL' , 'Wear_OS' ] ) ;
122123} ) ;
123124
125+ test ( 'parseAndroidEmulatorAvdNameOutput drops trailing adb protocol status' , ( ) => {
126+ assert . equal ( parseAndroidEmulatorAvdNameOutput ( 'Pixel_9_Pro_XL\r\nOK\r\n' ) , 'Pixel_9_Pro_XL' ) ;
127+ assert . equal ( parseAndroidEmulatorAvdNameOutput ( 'Pixel_9_Pro_XL\n' ) , 'Pixel_9_Pro_XL' ) ;
128+ assert . equal ( parseAndroidEmulatorAvdNameOutput ( '\r\nOK\r\n' ) , undefined ) ;
129+ } ) ;
130+
124131test ( 'resolveAndroidAvdName supports space vs underscore matching' , ( ) => {
125132 const avdNames = [ 'Pixel_9_Pro_XL' , 'Medium_Tablet_API_35' ] ;
126133 assert . equal ( resolveAndroidAvdName ( avdNames , 'Pixel_9_Pro_XL' ) , 'Pixel_9_Pro_XL' ) ;
Original file line number Diff line number Diff line change @@ -38,6 +38,18 @@ function normalizeAndroidName(value: string): string {
3838 return value . toLowerCase ( ) . replace ( / _ / g, ' ' ) . replace ( / \s + / g, ' ' ) . trim ( ) ;
3939}
4040
41+ export function parseAndroidEmulatorAvdNameOutput ( rawOutput : string ) : string | undefined {
42+ const lines = rawOutput
43+ . split ( '\n' )
44+ . map ( ( line ) => line . trim ( ) )
45+ . filter ( ( line ) => line . length > 0 ) ;
46+ if ( lines . length === 0 ) return undefined ;
47+ if ( lines . at ( - 1 ) === 'OK' ) {
48+ lines . pop ( ) ;
49+ }
50+ return lines . join ( '\n' ) . trim ( ) || undefined ;
51+ }
52+
4153async function readAndroidBootProp (
4254 serial : string ,
4355 timeoutMs = TIMEOUT_PROFILES . android_boot . operationMs ,
@@ -72,8 +84,8 @@ async function resolveAndroidEmulatorAvdName(serial: string): Promise<string | u
7284 allowFailure : true ,
7385 timeoutMs : ANDROID_EMULATOR_AVD_NAME_TIMEOUT_MS ,
7486 } ) ;
75- const emuValue = emuResult . stdout . trim ( ) ;
76- if ( emuResult . exitCode === 0 && emuValue . length > 0 ) {
87+ const emuValue = parseAndroidEmulatorAvdNameOutput ( emuResult . stdout ) ;
88+ if ( emuResult . exitCode === 0 && emuValue ) {
7789 return emuValue ;
7890 }
7991 return undefined ;
You can’t perform that action at this time.
0 commit comments