@@ -130,6 +130,48 @@ describe('LocalBinary busy-binary download handling', function () {
130130 } ) ;
131131 } ) ;
132132
133+ // SDK-7713: binaryPath() read this.windows before anything had set it, so on
134+ // Windows it looked for "BrowserStackLocal" without ".exe", never found it, and
135+ // re-downloaded on every start -- colliding with any other run executing it.
136+ describe ( 'existing binary on Windows' , function ( ) {
137+ var dir , exe ;
138+
139+ function windowsBinary ( ) {
140+ var platform = Object . getOwnPropertyDescriptor ( process , 'platform' ) ;
141+ Object . defineProperty ( process , 'platform' , { value : 'win32' } ) ;
142+ try {
143+ var binary = new LocalBinary ( ) ;
144+ } finally {
145+ Object . defineProperty ( process , 'platform' , platform ) ;
146+ }
147+ binary . orderedPaths = [ dir ] ;
148+ binary . download = binary . downloadSync = function ( ) { throw new Error ( 'should not re-download' ) ; } ;
149+ return binary ;
150+ }
151+
152+ beforeEach ( function ( ) {
153+ dir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'bs-local-' ) ) ;
154+ exe = path . join ( dir , 'BrowserStackLocal.exe' ) ;
155+ fs . writeFileSync ( exe , 'binary' , { mode : 0o755 } ) ;
156+ } ) ;
157+
158+ afterEach ( function ( ) {
159+ fs . unlinkSync ( exe ) ;
160+ fs . rmdirSync ( dir ) ;
161+ } ) ;
162+
163+ it ( 'reuses BrowserStackLocal.exe instead of re-downloading (sync)' , function ( ) {
164+ expect ( windowsBinary ( ) . binaryPath ( { } , null , 'key' , 9 ) ) . to . equal ( exe ) ;
165+ } ) ;
166+
167+ it ( 'reuses BrowserStackLocal.exe instead of re-downloading (async)' , function ( done ) {
168+ windowsBinary ( ) . binaryPath ( { } , null , 'key' , 9 , function ( binaryPath ) {
169+ expect ( binaryPath ) . to . equal ( exe ) ;
170+ done ( ) ;
171+ } ) ;
172+ } ) ;
173+ } ) ;
174+
133175 describe ( 'isBinaryBusy' , function ( ) {
134176 it ( 'reports a readable file as free' , function ( ) {
135177 var binary = new LocalBinary ( ) ,
0 commit comments