Skip to content

Commit 99dbe22

Browse files
committed
Add tests for LocalBinary download
Testing download without and with a proxy
1 parent 8349722 commit 99dbe22

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"eslint": "1.10.3",
2424
"expect.js": "0.3.1",
2525
"mocha": "2.4.5",
26-
"mocks": "0.0.15"
26+
"mocks": "0.0.15",
27+
"proxy": "^0.2.4"
2728
},
2829
"bugs": "https://github.com/browserstack/browserstack-local-nodejs/issues",
2930
"homepage": "https://github.com/browserstack/browserstack-local-nodejs",

test/local.js

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ var expect = require('expect.js'),
22
mocks = require('mocks'),
33
path = require('path'),
44
fs = require('fs'),
5-
browserstack = require('../index');
5+
Proxy = require('proxy'),
6+
browserstack = require('../index'),
7+
LocalBinary = require('../lib/LocalBinary');
68

79
describe('Local', function () {
810
var bsLocal;
@@ -152,3 +154,57 @@ describe('Local', function () {
152154
});
153155

154156
});
157+
158+
describe('LocalBinary', function () {
159+
var proxy;
160+
var proxyPort;
161+
var binary;
162+
var tempDownloadPath;
163+
164+
before(function (done) {
165+
// setup HTTP proxy server
166+
proxy = new Proxy();
167+
proxy.listen(function () {
168+
proxyPort = proxy.address().port;
169+
done();
170+
});
171+
});
172+
173+
after(function (done) {
174+
proxy.once('close', function () { done(); });
175+
proxy.close();
176+
});
177+
178+
beforeEach(function () {
179+
binary = new LocalBinary();
180+
tempDownloadPath = path.join(process.cwd(), 'download');
181+
});
182+
183+
afterEach(function () {
184+
fs.rmdirSync(tempDownloadPath);
185+
});
186+
187+
it('should download binaries without proxy', function (done) {
188+
this.timeout(600000);
189+
var conf = {};
190+
binary.download(conf, tempDownloadPath, function (result) {
191+
expect(fs.existsSync(result)).to.equal(true);
192+
fs.unlinkSync(result);
193+
done();
194+
});
195+
});
196+
197+
it('should download binaries with proxy', function (done) {
198+
this.timeout(600000);
199+
var conf = {
200+
proxyHost: '127.0.0.1',
201+
proxyPort: proxyPort
202+
};
203+
binary.download(conf, tempDownloadPath, function (result) {
204+
// test for file existence
205+
expect(fs.existsSync(result)).to.equal(true);
206+
fs.unlinkSync(result);
207+
done();
208+
});
209+
});
210+
});

0 commit comments

Comments
 (0)