@@ -2,7 +2,9 @@ var expect = require('expect.js'),
2
2
mocks = require ( 'mocks' ) ,
3
3
path = require ( 'path' ) ,
4
4
fs = require ( 'fs' ) ,
5
- browserstack = require ( '../index' ) ;
5
+ Proxy = require ( 'proxy' ) ,
6
+ browserstack = require ( '../index' ) ,
7
+ LocalBinary = require ( '../lib/LocalBinary' ) ;
6
8
7
9
describe ( 'Local' , function ( ) {
8
10
var bsLocal ;
@@ -152,3 +154,57 @@ describe('Local', function () {
152
154
} ) ;
153
155
154
156
} ) ;
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