Skip to content

Commit 368f94e

Browse files
Merge pull request #187 from browserstack/sdk-7713-reuse-running-binary
LOC-7472 Look for BrowserStackLocal.exe on Windows before downloading
2 parents 1e479a6 + cfe59ce commit 368f94e

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

‎lib/LocalBinary.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const packageName = 'browserstack-local-nodejs';
1717

1818
function LocalBinary(){
1919
this.hostOS = process.platform;
20+
/* Set here, not only in getBinaryFilename(): binaryPath() reads it before any download. */
21+
this.windows = /mswin|msys|mingw|cygwin|bccwin|wince|emc|win32/i.test(this.hostOS);
2022
this.is64bits = process.arch == 'x64';
2123
this.isArm64 = process.arch == 'arm64';
2224
this.baseRetries = 9;

‎test/local_binary_busy_download.js‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)