@@ -66,6 +66,41 @@ describe('Unit: Tasks > yarn-install', function () {
66
66
} ) ;
67
67
} ) ;
68
68
69
+ it ( 'catches errors from yarn and cleans up install folder' , function ( ) {
70
+ const yarnStub = sinon . stub ( ) . rejects ( new Error ( 'an error occurred' ) ) ;
71
+ const yarnInstall = proxyquire ( modulePath , {
72
+ '../utils/yarn' : yarnStub
73
+ } ) ;
74
+ const subTasks = yarnInstall . subTasks ;
75
+ const env = setupTestFolder ( ) ;
76
+ const ctx = { installPath : env . dir } ;
77
+ const listrStub = sinon . stub ( ) . callsFake ( ( tasks ) => {
78
+ expect ( tasks ) . to . have . length ( 3 ) ;
79
+
80
+ return Promise . each ( tasks , ( task ) => task . task ( ctx ) ) ;
81
+ } ) ;
82
+
83
+ const distTaskStub = sinon . stub ( subTasks , 'dist' ) . resolves ( ) ;
84
+ const downloadTaskStub = sinon . stub ( subTasks , 'download' ) ;
85
+
86
+ return yarnInstall ( { listr : listrStub } ) . then ( ( ) => {
87
+ expect ( false , 'error should have been thrown' ) . to . be . true ;
88
+ } ) . catch ( ( error ) => {
89
+ expect ( error . message ) . to . equal ( 'an error occurred' ) ;
90
+ expect ( listrStub . calledOnce ) . to . be . true ;
91
+ expect ( distTaskStub . calledOnce ) . to . be . true ;
92
+ expect ( downloadTaskStub . calledOnce ) . to . be . true ;
93
+ expect ( yarnStub . calledOnce ) . to . be . true ;
94
+ expect ( yarnStub . args [ 0 ] [ 0 ] ) . to . deep . equal ( [ 'install' , '--no-emoji' , '--no-progress' ] ) ;
95
+ expect ( yarnStub . args [ 0 ] [ 1 ] ) . to . deep . equal ( {
96
+ cwd : env . dir ,
97
+ env : { NODE_ENV : 'production' } ,
98
+ observe : true
99
+ } ) ;
100
+ expect ( fs . existsSync ( env . dir ) ) . to . be . false ;
101
+ } ) ;
102
+ } ) ;
103
+
69
104
describe ( 'dist subtask' , function ( ) {
70
105
it ( 'rejects if yarn util returns invalid json' , function ( ) {
71
106
const yarnStub = sinon . stub ( ) . resolves ( { stdout : 'not json' } ) ;
@@ -253,5 +288,34 @@ describe('Unit: Tasks > yarn-install', function () {
253
288
expect ( mapResult ) . to . deep . equal ( [ { path : 'index.js' } , { path : 'package.json' } , { path : 'yarn.lock' } ] ) ;
254
289
} ) ;
255
290
} ) ;
291
+
292
+ it ( 'catches errors from decompress and cleans up the install folder' , function ( ) {
293
+ const env = setupTestFolder ( ) ;
294
+ const downloadStub = sinon . stub ( ) . resolves ( { downloadedData : true } ) ;
295
+ const shasumStub = sinon . stub ( ) . returns ( 'asdf1234' ) ;
296
+ const decompressStub = sinon . stub ( ) . rejects ( new Error ( 'an error occurred' ) ) ;
297
+ const downloadTask = proxyquire ( modulePath , {
298
+ download : downloadStub ,
299
+ shasum : shasumStub ,
300
+ decompress : decompressStub
301
+ } ) . subTasks . download ;
302
+ const ctx = {
303
+ tarball : 'something.tgz' ,
304
+ shasum : 'asdf1234' ,
305
+ installPath : path . join ( env . dir , 'versions/1.0.0' )
306
+ } ;
307
+
308
+ return downloadTask ( ctx ) . then ( ( ) => {
309
+ expect ( false , 'Error should have been thrown' ) . to . be . true ;
310
+ } ) . catch ( ( error ) => {
311
+ expect ( error . message ) . to . equal ( 'an error occurred' ) ;
312
+ expect ( downloadStub . calledOnce ) . to . be . true ;
313
+ expect ( downloadStub . calledWithExactly ( 'something.tgz' ) ) ;
314
+ expect ( shasumStub . calledOnce ) . to . be . true ;
315
+ expect ( shasumStub . calledWithExactly ( { downloadedData : true } ) ) . to . be . true ;
316
+ expect ( decompressStub . calledOnce ) . to . be . true ;
317
+ expect ( fs . existsSync ( ctx . installPath ) ) . to . be . false ;
318
+ } ) ;
319
+ } ) ;
256
320
} ) ;
257
321
} ) ;
0 commit comments