@@ -38,7 +38,9 @@ exports['Deployment: JavaScript'] = {
3838 this . tessel = TesselSimulator ( ) ;
3939 this . end = sandbox . spy ( this . tessel . _rps . stdin , 'end' ) ;
4040
41+ this . fetchCurrentBuildInfo = sandbox . stub ( this . tessel , 'fetchCurrentBuildInfo' ) . returns ( Promise . resolve ( '40b2b46a62a34b5a26170c75f7e717cea673d1eb' ) ) ;
4142 this . fetchNodeProcessVersions = sandbox . stub ( this . tessel , 'fetchNodeProcessVersions' ) . returns ( Promise . resolve ( processVersions ) ) ;
43+ this . requestBuildList = sandbox . stub ( updates , 'requestBuildList' ) . returns ( Promise . resolve ( tesselBuilds ) ) ;
4244
4345 this . pWrite = sandbox . stub ( Preferences , 'write' ) . returns ( Promise . resolve ( ) ) ;
4446
@@ -1802,7 +1804,10 @@ exports['deploy.findProject'] = {
18021804exports [ 'deploy.sendBundle, error handling' ] = {
18031805 setUp : function ( done ) {
18041806 this . tessel = TesselSimulator ( ) ;
1807+ this . fetchCurrentBuildInfo = sandbox . stub ( this . tessel , 'fetchCurrentBuildInfo' ) . returns ( Promise . resolve ( '40b2b46a62a34b5a26170c75f7e717cea673d1eb' ) ) ;
18051808 this . fetchNodeProcessVersions = sandbox . stub ( this . tessel , 'fetchNodeProcessVersions' ) . returns ( Promise . resolve ( processVersions ) ) ;
1809+ this . requestBuildList = sandbox . stub ( updates , 'requestBuildList' ) . returns ( Promise . resolve ( tesselBuilds ) ) ;
1810+
18061811
18071812 this . pathResolve = sandbox . stub ( path , 'resolve' ) ;
18081813 this . failure = 'FAIL' ;
@@ -1882,7 +1887,10 @@ exports['deployment.js.preBundle'] = {
18821887 callback ( ) ;
18831888 } ) ;
18841889
1890+ this . fetchCurrentBuildInfo = sandbox . stub ( this . tessel , 'fetchCurrentBuildInfo' ) . returns ( Promise . resolve ( '40b2b46a62a34b5a26170c75f7e717cea673d1eb' ) ) ;
18851891 this . fetchNodeProcessVersions = sandbox . stub ( this . tessel , 'fetchNodeProcessVersions' ) . returns ( Promise . resolve ( processVersions ) ) ;
1892+ this . requestBuildList = sandbox . stub ( updates , 'requestBuildList' ) . returns ( Promise . resolve ( tesselBuilds ) ) ;
1893+
18861894
18871895 this . findProject = sandbox . stub ( deploy , 'findProject' ) . returns ( Promise . resolve ( {
18881896 pushdir : '' ,
@@ -1916,6 +1924,44 @@ exports['deployment.js.preBundle'] = {
19161924 } ) ;
19171925 } ,
19181926
1927+ preBundleCallsfetchCurrentBuildInfoAndForwardsResult ( test ) {
1928+ test . expect ( 4 ) ;
1929+
1930+ deploy . sendBundle ( this . tessel , {
1931+ target : '/' ,
1932+ entryPoint : 'foo.js' ,
1933+ lang : deployment . js
1934+ } ) . then ( ( ) => {
1935+ test . equal ( this . fetchCurrentBuildInfo . callCount , 1 ) ;
1936+ test . equal ( this . resolveBinaryModules . callCount , 1 ) ;
1937+
1938+ var args = this . resolveBinaryModules . lastCall . args [ 0 ] ;
1939+
1940+ test . equal ( args . tessel , this . tessel ) ;
1941+ test . equal ( args . tessel . versions , processVersions ) ;
1942+ test . done ( ) ;
1943+ } ) ;
1944+ } ,
1945+
1946+ preBundleCallsrequestBuildListAndForwardsResult ( test ) {
1947+ test . expect ( 4 ) ;
1948+
1949+ deploy . sendBundle ( this . tessel , {
1950+ target : '/' ,
1951+ entryPoint : 'foo.js' ,
1952+ lang : deployment . js
1953+ } ) . then ( ( ) => {
1954+ test . equal ( this . requestBuildList . callCount , 1 ) ;
1955+ test . equal ( this . resolveBinaryModules . callCount , 1 ) ;
1956+
1957+ var args = this . resolveBinaryModules . lastCall . args [ 0 ] ;
1958+
1959+ test . equal ( args . tessel , this . tessel ) ;
1960+ test . equal ( args . tessel . versions , processVersions ) ;
1961+ test . done ( ) ;
1962+ } ) ;
1963+ } ,
1964+
19191965 preBundleCallsfetchNodeProcessVersionsAndForwardsResult ( test ) {
19201966 test . expect ( 4 ) ;
19211967
@@ -2364,6 +2410,80 @@ exports['deployment.js.resolveBinaryModules'] = {
23642410 test . done ( ) ;
23652411 } ) ;
23662412 } ,
2413+
2414+ requestsRemoteGunzipErrors : function ( test ) {
2415+ test . expect ( 9 ) ;
2416+
2417+ this . removeSync = sandbox . stub ( fs , 'removeSync' ) ;
2418+ this . exists = sandbox . stub ( fs , 'existsSync' , ( ) => false ) ;
2419+ this . mkdirp = sandbox . stub ( fs , 'mkdirp' , ( dir , handler ) => {
2420+ handler ( ) ;
2421+ } ) ;
2422+
2423+ this . transform = new Transform ( ) ;
2424+ this . transform . stubsUsed = [ ] ;
2425+ this . rstream = null ;
2426+
2427+ this . pipe = sandbox . stub ( stream . Stream . prototype , 'pipe' , ( ) => {
2428+ // After the second transform is piped, emit the end
2429+ // event on the request stream;
2430+ if ( this . pipe . callCount === 2 ) {
2431+ process . nextTick ( ( ) => this . rstream . emit ( 'end' ) ) ;
2432+ }
2433+ return this . rstream ;
2434+ } ) ;
2435+
2436+ this . createGunzip = sandbox . stub ( zlib , 'createGunzip' , ( ) => {
2437+ this . transform . stubsUsed . push ( 'createGunzip' ) ;
2438+ return this . transform ;
2439+ } ) ;
2440+
2441+ this . Extract = sandbox . stub ( tar , 'Extract' , ( ) => {
2442+ this . transform . stubsUsed . push ( 'Extract' ) ;
2443+ return this . transform ;
2444+ } ) ;
2445+
2446+ this . request = sandbox . stub ( request , 'Request' , ( opts ) => {
2447+ this . rstream = new Request ( opts ) ;
2448+ return this . rstream ;
2449+ } ) ;
2450+
2451+ // Hook into the ifReachable call to trigger an error at the gunzip stream
2452+ this . ifReachable . restore ( ) ;
2453+ this . ifReachable = sandbox . stub ( remote , 'ifReachable' , ( ) => {
2454+ this . transform . emit ( 'error' , {
2455+ code : 'Z_DATA_ERROR' ,
2456+ } ) ;
2457+ return Promise . resolve ( ) ;
2458+ } ) ;
2459+
2460+ deployment . js . resolveBinaryModules ( {
2461+ target : this . target ,
2462+ tessel : {
2463+ versions : {
2464+ modules : 46
2465+ } ,
2466+ } ,
2467+ } ) . then ( ( ) => {
2468+ test . equal ( this . globFiles . callCount , 1 ) ;
2469+ test . equal ( this . exists . callCount , 1 ) ;
2470+ test . equal ( this . mkdirp . callCount , 1 ) ;
2471+ test . equal ( this . mkdirp . lastCall . args [ 0 ] . endsWith ( path . normalize ( '.tessel/binaries/release-1.1.1-Release-node-v46-linux-mipsel' ) ) , true ) ;
2472+
2473+ // The result of gunzip emitting an error:
2474+ test . equal ( this . removeSync . callCount , 1 ) ;
2475+ test . equal ( this . removeSync . lastCall . args [ 0 ] . endsWith ( path . normalize ( '.tessel/binaries/release-1.1.1-Release-node-v46-linux-mipsel' ) ) , true ) ;
2476+
2477+ test . equal ( this . request . callCount , 1 ) ;
2478+ test . equal ( this . createGunzip . callCount , 1 ) ;
2479+ test . deepEqual ( this . transform . stubsUsed , [ 'createGunzip' , 'Extract' ] ) ;
2480+
2481+ test . done ( ) ;
2482+ } ) . catch ( error => {
2483+ test . ok ( false , error . toString ( ) ) ;
2484+ test . done ( ) ;
2485+ } ) ;
2486+ } ,
23672487} ;
23682488
23692489exports [ 'deployment.js.injectBinaryModules' ] = {
0 commit comments