Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/LocalBinary.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const packageName = 'browserstack-local-nodejs';

function LocalBinary(){
this.hostOS = process.platform;
/* Set here, not only in getBinaryFilename(): binaryPath() reads it before any download. */
this.windows = /mswin|msys|mingw|cygwin|bccwin|wince|emc|win32/i.test(this.hostOS);
this.is64bits = process.arch == 'x64';
this.isArm64 = process.arch == 'arm64';
this.baseRetries = 9;
Expand Down
42 changes: 42 additions & 0 deletions test/local_binary_busy_download.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,48 @@ describe('LocalBinary busy-binary download handling', function () {
});
});

// SDK-7713: binaryPath() read this.windows before anything had set it, so on
// Windows it looked for "BrowserStackLocal" without ".exe", never found it, and
// re-downloaded on every start -- colliding with any other run executing it.
describe('existing binary on Windows', function () {
var dir, exe;

function windowsBinary() {
var platform = Object.getOwnPropertyDescriptor(process, 'platform');
Object.defineProperty(process, 'platform', { value: 'win32' });
try {
var binary = new LocalBinary();
} finally {
Object.defineProperty(process, 'platform', platform);
}
binary.orderedPaths = [dir];
binary.download = binary.downloadSync = function () { throw new Error('should not re-download'); };
return binary;
}

beforeEach(function () {
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'bs-local-'));
exe = path.join(dir, 'BrowserStackLocal.exe');
fs.writeFileSync(exe, 'binary', { mode: 0o755 });
});

afterEach(function () {
fs.unlinkSync(exe);
fs.rmdirSync(dir);
});

it('reuses BrowserStackLocal.exe instead of re-downloading (sync)', function () {
expect(windowsBinary().binaryPath({}, null, 'key', 9)).to.equal(exe);
});

it('reuses BrowserStackLocal.exe instead of re-downloading (async)', function (done) {
windowsBinary().binaryPath({}, null, 'key', 9, function (binaryPath) {
expect(binaryPath).to.equal(exe);
done();
});
});
});

describe('isBinaryBusy', function () {
it('reports a readable file as free', function () {
var binary = new LocalBinary(),
Expand Down
Loading