@@ -42,9 +42,10 @@ function echoEnvVarsCmd(varNames: string[]) {
4242 return `echo "${ varNames . map ( toShell ) . join ( ' ' ) } "`
4343}
4444
45- // Windows gives some junk in its output.
46- function cleanOutput ( output : string ) {
47- return output . trim ( ) . split ( '\n' ) . at ( - 1 ) ?. replace ( '"' , '' ) ?? ''
45+ function assertOutputContains ( rawOutput : string , expectedString : string ) : void | never {
46+ // Windows gives some junk we want to trim
47+ const output = rawOutput . trim ( ) . split ( '\n' ) . at ( - 1 ) ?. replace ( '"' , '' ) ?? ''
48+ assert . ok ( output . includes ( expectedString ) , `Expected output to contain "${ expectedString } ", but got "${ output } "` )
4849}
4950
5051describe ( 'testSshConnection' , function ( ) {
@@ -72,7 +73,7 @@ describe('testSshConnection', function () {
7273
7374 await createExecutableFile ( sshPath , echoEnvVarsCmd ( [ 'MY_VAR' ] ) )
7475 const r = await testSshConnection ( process , 'localhost' , sshPath , 'test-user' , session )
75- assert . ok ( cleanOutput ( r . stdout ) . includes ( 'yes' ) )
76+ assertOutputContains ( r . stdout , 'yes' )
7677 } )
7778
7879 it ( 'injects new session into env' , async function ( ) {
@@ -95,16 +96,14 @@ describe('testSshConnection', function () {
9596
9697 await createExecutableFile ( sshPath , echoEnvVarsCmd ( [ 'SESSION_ID' , 'STREAM_URL' , 'TOKEN' ] ) )
9798 const r = await testSshConnection ( process , 'localhost' , sshPath , 'test-user' , newSession )
98- assert . ok (
99- cleanOutput ( r . stdout ) . includes ( `${ newSession . SessionId } ${ newSession . StreamUrl } ${ newSession . TokenValue } ` )
100- )
99+ assertOutputContains ( r . stdout , `${ newSession . SessionId } ${ newSession . StreamUrl } ${ newSession . TokenValue } ` )
101100 } )
102101
103102 it ( 'passes proper args to the ssh invoke' , async function ( ) {
104103 const executableFileContent = isWin ( ) ? `echo "%1 %2"` : `echo "$1 $2"`
105104 const process = createBoundProcess ( async ( ) => ( { } ) )
106105 await createExecutableFile ( sshPath , executableFileContent )
107106 const r = await testSshConnection ( process , 'localhost' , sshPath , 'test-user' , { } as SSM . StartSessionResponse )
108- assert . ok ( cleanOutput ( r . stdout ) . includes ( '-T test-user@localhost' ) )
107+ assertOutputContains ( r . stdout , '-T test-user@localhost' )
109108 } )
110109} )
0 commit comments