@@ -4,17 +4,11 @@ var path = require('path');
44var mocks = require ( 'mocks' ) ,
55 httpMock = require ( './lib/mocks' ) . httpMock ,
66 fsMock = require ( './lib/mocks' ) . fsMock ,
7- unzipMock = require ( './lib/mocks' ) . unzipMock ;
7+ unzipMock = require ( './lib/mocks' ) . unzipMock ,
8+ sinon = require ( 'sinon' ) ;
89
9- var zb = mocks . loadFile ( './lib/ZipBinary.js' , {
10- https : httpMock ,
11- fs : fsMock ,
12- unzip : unzipMock
13- } ) ;
14- var ZipBinary = zb . ZipBinary ;
15-
16- var PLATFORM = 'platform' ;
17- var ARCH = 'arch' ;
10+ var PLATFORM = 'linux' ;
11+ var ARCH = 'x64' ;
1812var EXT = 'exe' ;
1913var DEFAULT_BINARY_DIR = path . resolve ( path . join ( __dirname , '../bin' , PLATFORM , ARCH ) ) ;
2014var DEFAULT_BINARY_DIR_NO_ARCH = path . resolve ( path . join ( __dirname , '../bin' , PLATFORM ) ) ;
@@ -25,44 +19,69 @@ var OTHER_BINARY_DIR = '/bin';
2519var OTHER_BINARY_FILE = path . join ( OTHER_BINARY_DIR , 'BrowserStackLocal' ) ;
2620var OTHER_BINARY_FILE_WITH_EXT = path . join ( OTHER_BINARY_DIR , 'BrowserStackLocal.' + EXT ) ;
2721var ZIP_URL = 'https://www.browserstack.com/browserstack-local/BrowserStackLocal-' + PLATFORM + '-' + ARCH + '.zip' ;
28- var ZIP_URL_NO_ARCH = 'https://www.browserstack.com/browserstack-local/BrowserStackLocal-' + PLATFORM + ' .zip';
22+ var ZIP_URL_NO_ARCH = 'https://www.browserstack.com/browserstack-local/BrowserStackLocal-win32 .zip' ;
2923
3024describe ( 'ZipBinary' , function ( ) {
31- var zipBinary ;
25+ var zipBinary , ZipBinary , platformMock , archMock , binaryPathMock , zipPathMock ,
26+ logBinaryOutputMock , warnLogMock , infoLogMock , helper , basePathMock ;
3227
3328 beforeEach ( function ( ) {
3429 fsMock . fileNameModded = undefined ;
3530 fsMock . mode = undefined ;
3631 unzipMock . dirName = undefined ;
3732 httpMock . url = undefined ;
38- } ) ;
39-
40- describe ( 'with default binary path' , function ( ) {
41- beforeEach ( function ( ) {
42- zipBinary = new ZipBinary ( PLATFORM , ARCH ) ;
43- } ) ;
44-
45- it ( 'should have the correct path' , function ( ) {
46- expect ( zipBinary . path ) . to . equal ( DEFAULT_BINARY_FILE ) ;
47- } ) ;
48-
49- describe ( 'with extension' , function ( ) {
50- it ( 'should have the correct path' , function ( ) {
51- zipBinary = new ZipBinary ( PLATFORM , ARCH , null , EXT ) ;
52- expect ( zipBinary . path ) . to . equal ( DEFAULT_BINARY_FILE_WITH_EXT ) ;
53- } ) ;
54- } ) ;
5533
56- it ( 'should have the correct command' , function ( ) {
57- expect ( zipBinary . command ) . to . equal ( DEFAULT_BINARY_FILE ) ;
34+ platformMock = sinon . stub ( ) ;
35+ archMock = sinon . stub ( ) ;
36+ binaryPathMock = sinon . stub ( ) ;
37+ zipPathMock = sinon . stub ( ) ;
38+ logBinaryOutputMock = sinon . stub ( ) ;
39+ warnLogMock = sinon . stub ( ) ;
40+ infoLogMock = sinon . stub ( ) ;
41+ basePathMock = sinon . stub ( ) ;
42+
43+ helper = {
44+ helper : function ( ) {
45+ this . _basePath = 'default' ;
46+
47+ this . getPlatform = platformMock ;
48+ this . getArch = archMock ;
49+ this . getBinaryPath = binaryPathMock ;
50+ this . getZipPath = zipPathMock ;
51+ this . logBinaryOutput = logBinaryOutputMock ;
52+ this . setBasePath = function ( path ) {
53+ console . log ( "CALLED" ) ;
54+ this . _basePath = path
55+ } ;
56+ this . getBasePath = basePathMock ;
57+ this . log = {
58+ warn : warnLogMock ,
59+ info : infoLogMock
60+ } ;
61+ }
62+ } ;
63+ var zb = mocks . loadFile ( './lib/ZipBinary.js' , {
64+ https : httpMock ,
65+ fs : fsMock ,
66+ unzip : unzipMock ,
67+ './helper' : helper
5868 } ) ;
69+ ZipBinary = zb . ZipBinary ;
70+ } ) ;
5971
72+ describe ( 'with default binary path' , function ( ) {
6073 it ( 'should have the correct args' , function ( ) {
74+ zipBinary = new ZipBinary ( ) ;
6175 expect ( zipBinary . args ) . to . eql ( [ ] ) ;
6276 } ) ;
6377
6478 describe ( '#update' , function ( ) {
6579 it ( 'should download the zip file' , function ( done ) {
80+ platformMock . returns ( 'linux' ) ;
81+ archMock . returns ( 'x64' ) ;
82+ basePathMock . returns ( DEFAULT_BINARY_DIR ) ;
83+ binaryPathMock . returns ( DEFAULT_BINARY_FILE ) ;
84+ zipBinary = new ZipBinary ( ) ;
6685 zipBinary . update ( function ( ) {
6786 expect ( fsMock . fileNameModded ) . to . equal ( DEFAULT_BINARY_FILE ) ;
6887 expect ( fsMock . mode ) . to . equal ( '0755' ) ;
@@ -74,7 +93,11 @@ describe('ZipBinary', function () {
7493
7594 describe ( 'with no arch' , function ( ) {
7695 it ( 'should download the zip file' , function ( done ) {
77- zipBinary = new ZipBinary ( PLATFORM ) ;
96+ platformMock . returns ( 'win32' ) ;
97+ archMock . returns ( '' ) ;
98+ basePathMock . returns ( DEFAULT_BINARY_DIR_NO_ARCH ) ;
99+ binaryPathMock . returns ( DEFAULT_BINARY_FILE_NO_ARCH ) ;
100+ zipBinary = new ZipBinary ( ) ;
78101 zipBinary . update ( function ( ) {
79102 expect ( fsMock . fileNameModded ) . to . equal ( DEFAULT_BINARY_FILE_NO_ARCH ) ;
80103 expect ( fsMock . mode ) . to . equal ( '0755' ) ;
@@ -88,31 +111,18 @@ describe('ZipBinary', function () {
88111 } ) ;
89112
90113 describe ( 'with given binary path' , function ( ) {
91- beforeEach ( function ( ) {
92- zipBinary = new ZipBinary ( PLATFORM , ARCH , OTHER_BINARY_DIR ) ;
93- } ) ;
94-
95- it ( 'should have the correct path' , function ( ) {
96- expect ( zipBinary . path ) . to . equal ( OTHER_BINARY_FILE ) ;
97- } ) ;
98-
99- describe ( 'with extension' , function ( ) {
100- it ( 'should have the correct path' , function ( ) {
101- zipBinary = new ZipBinary ( PLATFORM , ARCH , OTHER_BINARY_DIR , EXT ) ;
102- expect ( zipBinary . path ) . to . equal ( OTHER_BINARY_FILE_WITH_EXT ) ;
103- } ) ;
104- } ) ;
105-
106- it ( 'should have the correct command' , function ( ) {
107- expect ( zipBinary . command ) . to . equal ( OTHER_BINARY_FILE ) ;
108- } ) ;
109-
110114 it ( 'should have the correct args' , function ( ) {
115+ zipBinary = new ZipBinary ( ) ;
111116 expect ( zipBinary . args ) . to . eql ( [ ] ) ;
112117 } ) ;
113118
114119 describe ( '#update' , function ( ) {
115120 it ( 'should download the zip file' , function ( done ) {
121+ platformMock . returns ( 'linux' ) ;
122+ archMock . returns ( 'x64' ) ;
123+ basePathMock . returns ( OTHER_BINARY_DIR ) ;
124+ binaryPathMock . returns ( OTHER_BINARY_FILE ) ;
125+ zipBinary = new ZipBinary ( ) ;
116126 zipBinary . update ( function ( ) {
117127 expect ( fsMock . fileNameModded ) . to . equal ( OTHER_BINARY_FILE ) ;
118128 expect ( fsMock . mode ) . to . equal ( '0755' ) ;
@@ -124,7 +134,11 @@ describe('ZipBinary', function () {
124134
125135 describe ( 'with no arch' , function ( ) {
126136 it ( 'should download the zip file' , function ( done ) {
127- zipBinary = new ZipBinary ( PLATFORM , null , OTHER_BINARY_DIR ) ;
137+ platformMock . returns ( 'win32' ) ;
138+ archMock . returns ( '' ) ;
139+ basePathMock . returns ( OTHER_BINARY_DIR ) ;
140+ binaryPathMock . returns ( OTHER_BINARY_FILE ) ;
141+ zipBinary = new ZipBinary ( ) ;
128142 zipBinary . update ( function ( ) {
129143 expect ( fsMock . fileNameModded ) . to . equal ( OTHER_BINARY_FILE ) ;
130144 expect ( fsMock . mode ) . to . equal ( '0755' ) ;
0 commit comments