@@ -21,6 +21,8 @@ describe('program.Program', () => {
21
21
const absolutePackageDir = path . join ( __dirname , '..' , '..' ) ;
22
22
return program . execute (
23
23
absolutePackageDir , {
24
+ getVersion : ( ) => spy ( ) ,
25
+ checkForUpdates : spy ( ) ,
24
26
systemProcess : fakeProcess ,
25
27
shouldExitProgram : false ,
26
28
...options ,
@@ -176,7 +178,10 @@ describe('program.Program', () => {
176
178
} ) ;
177
179
program . command ( 'thing' , 'does a thing' , ( ) => { } ) ;
178
180
179
- return execProgram ( program , { getVersion : spy ( ) , logStream} )
181
+ return execProgram ( program , {
182
+ getVersion : spy ( ) ,
183
+ logStream,
184
+ } )
180
185
. then ( ( ) => {
181
186
assert . equal ( logStream . makeVerbose . called , true ) ;
182
187
} ) ;
@@ -241,13 +246,50 @@ describe('program.Program', () => {
241
246
} ) ;
242
247
} ) ;
243
248
249
+ it ( 'checks for updates automatically' , ( ) => {
250
+ const handler = spy ( ) ;
251
+ const getVersion = ( ) => 'some-package-version' ;
252
+ const checkForUpdates = sinon . stub ( ) ;
253
+ const program = new Program ( [ 'run' ] )
254
+ . command ( 'run' , 'some command' , handler ) ;
255
+ return execProgram ( program , {
256
+ checkForUpdates,
257
+ getVersion,
258
+ globalEnv : 'production' ,
259
+ } )
260
+ . then ( ( ) => {
261
+ assert . equal ( checkForUpdates . firstCall . args [ 0 ] . version ,
262
+ 'some-package-version' ) ;
263
+ } ) ;
264
+ } ) ;
265
+
266
+ it ( 'does not check for updates during development' , ( ) => {
267
+ const handler = spy ( ) ;
268
+ const getVersion = ( ) => 'some-package-version' ;
269
+ const checkForUpdates = sinon . stub ( ) ;
270
+ const program = new Program ( [ 'run' ] )
271
+ . command ( 'run' , 'some command' , handler ) ;
272
+ return execProgram ( program , {
273
+ checkForUpdates,
274
+ getVersion,
275
+ globalEnv : 'development' ,
276
+ } )
277
+ . then ( ( ) => {
278
+ assert . equal ( checkForUpdates . called , false ) ;
279
+ } ) ;
280
+ } ) ;
244
281
} ) ;
245
282
246
283
247
284
describe ( 'program.main' , ( ) => {
248
285
249
286
function execProgram ( argv , { projectRoot = '' , ...mainOptions } : Object = { } ) {
250
- const runOptions = { shouldExitProgram : false , systemProcess : fake ( process ) } ;
287
+ const runOptions = {
288
+ getVersion : ( ) => 'not-a-real-version' ,
289
+ checkForUpdates : spy ( ) ,
290
+ shouldExitProgram : false ,
291
+ systemProcess : fake ( process ) ,
292
+ } ;
251
293
return main ( projectRoot , { argv, runOptions, ...mainOptions } ) ;
252
294
}
253
295
@@ -351,15 +393,15 @@ describe('program.defaultVersionGetter', () => {
351
393
const pkgFile = path . join ( root , 'package.json' ) ;
352
394
return fs . readFile ( pkgFile )
353
395
. then ( ( pkgData ) => {
354
- const testBuildEnv = { localEnv : 'production' } ;
396
+ const testBuildEnv = { globalEnv : 'production' } ;
355
397
assert . equal ( defaultVersionGetter ( root , testBuildEnv ) ,
356
398
JSON . parse ( pkgData ) . version ) ;
357
399
} ) ;
358
400
} ) ;
359
401
360
402
it ( 'returns git commit information in development' , ( ) => {
361
403
const commit = `${ git . branch ( ) } -${ git . long ( ) } ` ;
362
- const testBuildEnv = { localEnv : 'development' } ;
404
+ const testBuildEnv = { globalEnv : 'development' } ;
363
405
assert . equal ( defaultVersionGetter ( root , testBuildEnv ) ,
364
406
commit ) ;
365
407
} ) ;
0 commit comments