2
2
const expect = require ( 'chai' ) . expect ;
3
3
const sinon = require ( 'sinon' ) ;
4
4
const proxyquire = require ( 'proxyquire' ) . noCallThru ( ) ;
5
+ const Promise = require ( 'bluebird' ) ;
5
6
const path = require ( 'path' ) ;
6
7
7
8
const modulePath = '../../../lib/commands/install' ;
@@ -116,7 +117,7 @@ describe('Unit: Commands > Install', function () {
116
117
} ) ;
117
118
let testInstance = new InstallCommand ( { listr : listrStub } , { cliVersion : '1.0.0' , setEnvironment : setEnvironmentStub } ) ;
118
119
119
- return testInstance . run ( { version : 'local' } ) . then ( ( ) => {
120
+ return testInstance . run ( { version : 'local' , zip : '' } ) . then ( ( ) => {
120
121
expect ( false , 'run should have rejected' ) . to . be . true ;
121
122
} ) . catch ( ( ) => {
122
123
expect ( readdirStub . calledOnce ) . to . be . true ;
@@ -127,12 +128,13 @@ describe('Unit: Commands > Install', function () {
127
128
] ) ;
128
129
expect ( listrStub . args [ 0 ] [ 1 ] ) . to . deep . equal ( {
129
130
ui : { listr : listrStub } ,
130
- argv : { version : 'local' } ,
131
+ argv : { version : 'local' , zip : '' } ,
131
132
local : true
132
133
} ) ;
133
134
expect ( listrStub . args [ 1 ] [ 1 ] ) . to . deep . equal ( {
134
135
version : null ,
135
- cliVersion : '1.0.0'
136
+ cliVersion : '1.0.0' ,
137
+ zip : ''
136
138
} ) ;
137
139
expect ( setEnvironmentStub . calledOnce ) . to . be . true ;
138
140
expect ( setEnvironmentStub . calledWithExactly ( true , true ) ) . to . be . true ;
@@ -152,7 +154,7 @@ describe('Unit: Commands > Install', function () {
152
154
} ) ;
153
155
let testInstance = new InstallCommand ( { listr : listrStub } , { cliVersion : '1.0.0' , setEnvironment : setEnvironmentStub } ) ;
154
156
155
- return testInstance . run ( { version : '1.5.0' , local : true } ) . then ( ( ) => {
157
+ return testInstance . run ( { version : '1.5.0' , local : true , zip : '' } ) . then ( ( ) => {
156
158
expect ( false , 'run should have rejected' ) . to . be . true ;
157
159
} ) . catch ( ( ) => {
158
160
expect ( readdirStub . calledOnce ) . to . be . true ;
@@ -163,31 +165,47 @@ describe('Unit: Commands > Install', function () {
163
165
] ) ;
164
166
expect ( listrStub . args [ 0 ] [ 1 ] ) . to . deep . equal ( {
165
167
ui : { listr : listrStub } ,
166
- argv : { version : '1.5.0' , local : true } ,
168
+ argv : { version : '1.5.0' , local : true , zip : '' } ,
167
169
local : true
168
170
} ) ;
169
171
expect ( listrStub . args [ 1 ] [ 1 ] ) . to . deep . equal ( {
170
172
version : '1.5.0' ,
171
- cliVersion : '1.0.0'
173
+ cliVersion : '1.0.0' ,
174
+ zip : ''
172
175
} ) ;
173
176
expect ( setEnvironmentStub . calledOnce ) . to . be . true ;
174
177
expect ( setEnvironmentStub . calledWithExactly ( true , true ) ) . to . be . true ;
175
178
} ) ;
176
179
} ) ;
177
180
178
- it ( 'returns after tasks run if --no-setup is passed' , function ( ) {
179
- let readdirStub = sandbox . stub ( ) . returns ( [ ] ) ;
180
- let listrStub = sandbox . stub ( ) . resolves ( ) ;
181
+ it ( 'calls all tasks and returns after tasks run if --no-setup is passed' , function ( ) {
182
+ const readdirStub = sandbox . stub ( ) . returns ( [ ] ) ;
183
+ const yarnInstallStub = sandbox . stub ( ) . resolves ( ) ;
184
+ const ensureStructureStub = sandbox . stub ( ) . resolves ( ) ;
185
+ const listrStub = sandbox . stub ( ) . callsFake ( ( tasks , ctx ) => {
186
+ return Promise . each ( tasks , task => task . task ( ctx , { } ) ) ;
187
+ } ) ;
181
188
182
189
const InstallCommand = proxyquire ( modulePath , {
183
- 'fs-extra' : { readdirSync : readdirStub }
190
+ 'fs-extra' : { readdirSync : readdirStub } ,
191
+ '../tasks/yarn-install' : yarnInstallStub ,
192
+ '../tasks/ensure-structure' : ensureStructureStub ,
193
+ './doctor/checks/install' : [ ]
184
194
} ) ;
185
- let testInstance = new InstallCommand ( { listr : listrStub } , { cliVersion : '1.0.0' } ) ;
186
- let runCommandStub = sandbox . stub ( testInstance , 'runCommand' ) . resolves ( ) ;
195
+ const testInstance = new InstallCommand ( { listr : listrStub } , { cliVersion : '1.0.0' } ) ;
196
+ const runCommandStub = sandbox . stub ( testInstance , 'runCommand' ) . resolves ( ) ;
197
+ const versionStub = sandbox . stub ( testInstance , 'version' ) . resolves ( ) ;
198
+ const linkStub = sinon . stub ( testInstance , 'link' ) . resolves ( ) ;
199
+ const casperStub = sinon . stub ( testInstance , 'casper' ) . resolves ( ) ;
187
200
188
201
return testInstance . run ( { version : '1.0.0' , setup : false } ) . then ( ( ) => {
189
202
expect ( readdirStub . calledOnce ) . to . be . true ;
190
- expect ( listrStub . calledTwice ) . to . be . true ;
203
+ expect ( listrStub . calledThrice ) . to . be . true ;
204
+ expect ( yarnInstallStub . calledOnce ) . to . be . true ;
205
+ expect ( ensureStructureStub . calledOnce ) . to . be . true ;
206
+ expect ( versionStub . calledOnce ) . to . be . true ;
207
+ expect ( linkStub . calledOnce ) . to . be . true ;
208
+ expect ( casperStub . calledOnce ) . to . be . true ;
191
209
expect ( runCommandStub . called ) . to . be . false ;
192
210
} ) ;
193
211
} ) ;
@@ -204,36 +222,56 @@ describe('Unit: Commands > Install', function () {
204
222
let testInstance = new InstallCommand ( { listr : listrStub } , { cliVersion : '1.0.0' , setEnvironment : setEnvironmentStub } ) ;
205
223
let runCommandStub = sandbox . stub ( testInstance , 'runCommand' ) . resolves ( ) ;
206
224
207
- return testInstance . run ( { version : 'local' , setup : true } ) . then ( ( ) => {
225
+ return testInstance . run ( { version : 'local' , setup : true , zip : '' } ) . then ( ( ) => {
208
226
expect ( readdirStub . calledOnce ) . to . be . true ;
209
227
expect ( listrStub . calledTwice ) . to . be . true ;
210
228
expect ( setEnvironmentStub . calledOnce ) . to . be . true ;
211
229
expect ( setEnvironmentStub . calledWithExactly ( true , true ) ) ;
212
230
expect ( runCommandStub . calledOnce ) . to . be . true ;
213
231
expect ( runCommandStub . calledWithExactly (
214
232
{ SetupCommand : true } ,
215
- { version : 'local' , local : true }
233
+ { version : 'local' , local : true , zip : '' }
216
234
) ) ;
217
235
} ) ;
218
236
} ) ;
219
237
} ) ;
220
238
221
239
describe ( 'tasks > version' , function ( ) {
222
240
it ( 'calls resolveVersion, sets version and install path' , function ( ) {
223
- let resolveVersionStub = sinon . stub ( ) . resolves ( '1.5.0' ) ;
241
+ const resolveVersionStub = sinon . stub ( ) . resolves ( '1.5.0' ) ;
224
242
const InstallCommand = proxyquire ( modulePath , {
225
243
'../utils/resolve-version' : resolveVersionStub
226
244
} ) ;
227
245
228
- let testInstance = new InstallCommand ( { } , { } ) ;
229
- let context = { version : '1.0.0' } ;
246
+ const testInstance = new InstallCommand ( { } , { } ) ;
247
+ const context = { version : '1.0.0' } ;
230
248
231
249
return testInstance . version ( context ) . then ( ( ) => {
232
250
expect ( resolveVersionStub . calledOnce ) . to . be . true ;
233
251
expect ( context . version ) . to . equal ( '1.5.0' ) ;
234
252
expect ( context . installPath ) . to . equal ( path . join ( process . cwd ( ) , 'versions/1.5.0' ) ) ;
235
253
} ) ;
236
254
} ) ;
255
+
256
+ it ( 'calls versionFromZip if zip file is passed in context' , function ( ) {
257
+ const resolveVersionStub = sinon . stub ( ) . resolves ( '1.5.0' ) ;
258
+ const zipVersionStub = sinon . stub ( ) . resolves ( '1.5.2' ) ;
259
+ const InstallCommand = proxyquire ( modulePath , {
260
+ '../utils/resolve-version' : resolveVersionStub ,
261
+ '../utils/version-from-zip' : zipVersionStub
262
+ } ) ;
263
+
264
+ const testInstance = new InstallCommand ( { } , { } ) ;
265
+ const context = { version : '1.0.0' , zip : '/some/zip/file.zip' } ;
266
+
267
+ return testInstance . version ( context ) . then ( ( ) => {
268
+ expect ( resolveVersionStub . called ) . to . be . false ;
269
+ expect ( zipVersionStub . calledOnce ) . to . be . true ;
270
+ expect ( zipVersionStub . calledWith ( '/some/zip/file.zip' ) ) . to . be . true ;
271
+ expect ( context . version ) . to . equal ( '1.5.2' ) ;
272
+ expect ( context . installPath ) . to . equal ( path . join ( process . cwd ( ) , 'versions/1.5.2' ) ) ;
273
+ } ) ;
274
+ } ) ;
237
275
} ) ;
238
276
239
277
describe ( 'tasks > casper' , function ( ) {
0 commit comments