@@ -8,6 +8,7 @@ import path from 'path';
8
8
import * as main from '../src/main' ;
9
9
import * as im from '../src/installer' ;
10
10
import * as auth from '../src/authutil' ;
11
+ import { context } from '@actions/github' ;
11
12
12
13
let nodeTestManifest = require ( './data/versions-manifest.json' ) ;
13
14
let nodeTestDist = require ( './data/node-dist-index.json' ) ;
@@ -24,6 +25,7 @@ describe('setup-node', () => {
24
25
let findSpy : jest . SpyInstance ;
25
26
let cnSpy : jest . SpyInstance ;
26
27
let logSpy : jest . SpyInstance ;
28
+ let warningSpy : jest . SpyInstance ;
27
29
let getManifestSpy : jest . SpyInstance ;
28
30
let getDistSpy : jest . SpyInstance ;
29
31
let platSpy : jest . SpyInstance ;
@@ -77,8 +79,9 @@ describe('setup-node', () => {
77
79
78
80
// writes
79
81
cnSpy = jest . spyOn ( process . stdout , 'write' ) ;
80
- logSpy = jest . spyOn ( console , 'log ' ) ;
82
+ logSpy = jest . spyOn ( core , 'info ' ) ;
81
83
dbgSpy = jest . spyOn ( core , 'debug' ) ;
84
+ warningSpy = jest . spyOn ( core , 'warning' ) ;
82
85
cnSpy . mockImplementation ( line => {
83
86
// uncomment to debug
84
87
// process.stderr.write('write:' + line + '\n');
@@ -333,4 +336,154 @@ describe('setup-node', () => {
333
336
334
337
expect ( cnSpy ) . toHaveBeenCalledWith ( `::error::${ errMsg } ${ osm . EOL } ` ) ;
335
338
} ) ;
339
+
340
+ describe ( 'check-latest flag' , ( ) => {
341
+ it ( 'use local version and dont check manifest if check-latest is not specified' , async ( ) => {
342
+ os . platform = 'linux' ;
343
+ os . arch = 'x64' ;
344
+
345
+ inputs [ 'node-version' ] = '12' ;
346
+ inputs [ 'check-latest' ] = 'false' ;
347
+
348
+ const toolPath = path . normalize ( '/cache/node/12.16.1/x64' ) ;
349
+ findSpy . mockReturnValue ( toolPath ) ;
350
+ await main . run ( ) ;
351
+
352
+ expect ( logSpy ) . toHaveBeenCalledWith ( `Found in cache @ ${ toolPath } ` ) ;
353
+ expect ( logSpy ) . not . toHaveBeenCalledWith (
354
+ 'Attempt to resolve the latest version from manifest...'
355
+ ) ;
356
+ } ) ;
357
+
358
+ it ( 'check latest version and resolve it from local cache' , async ( ) => {
359
+ os . platform = 'linux' ;
360
+ os . arch = 'x64' ;
361
+
362
+ inputs [ 'node-version' ] = '12' ;
363
+ inputs [ 'check-latest' ] = 'true' ;
364
+
365
+ const toolPath = path . normalize ( '/cache/node/12.16.2/x64' ) ;
366
+ findSpy . mockReturnValue ( toolPath ) ;
367
+ dlSpy . mockImplementation ( async ( ) => '/some/temp/path' ) ;
368
+ exSpy . mockImplementation ( async ( ) => '/some/other/temp/path' ) ;
369
+ cacheSpy . mockImplementation ( async ( ) => toolPath ) ;
370
+
371
+ await main . run ( ) ;
372
+
373
+ expect ( logSpy ) . toHaveBeenCalledWith (
374
+ 'Attempt to resolve the latest version from manifest...'
375
+ ) ;
376
+ expect ( logSpy ) . toHaveBeenCalledWith ( "Resolved as '12.16.2'" ) ;
377
+ expect ( logSpy ) . toHaveBeenCalledWith ( `Found in cache @ ${ toolPath } ` ) ;
378
+ } ) ;
379
+
380
+ it ( 'check latest version and install it from manifest' , async ( ) => {
381
+ os . platform = 'linux' ;
382
+ os . arch = 'x64' ;
383
+
384
+ inputs [ 'node-version' ] = '12' ;
385
+ inputs [ 'check-latest' ] = 'true' ;
386
+
387
+ findSpy . mockImplementation ( ( ) => '' ) ;
388
+ dlSpy . mockImplementation ( async ( ) => '/some/temp/path' ) ;
389
+ const toolPath = path . normalize ( '/cache/node/12.16.2/x64' ) ;
390
+ exSpy . mockImplementation ( async ( ) => '/some/other/temp/path' ) ;
391
+ cacheSpy . mockImplementation ( async ( ) => toolPath ) ;
392
+ const expectedUrl =
393
+ 'https://github.com/actions/node-versions/releases/download/12.16.2-20200423.28/node-12.16.2-linux-x64.tar.gz' ;
394
+
395
+ await main . run ( ) ;
396
+
397
+ expect ( logSpy ) . toHaveBeenCalledWith (
398
+ 'Attempt to resolve the latest version from manifest...'
399
+ ) ;
400
+ expect ( logSpy ) . toHaveBeenCalledWith ( "Resolved as '12.16.2'" ) ;
401
+ expect ( logSpy ) . toHaveBeenCalledWith (
402
+ `Acquiring 12.16.2 from ${ expectedUrl } `
403
+ ) ;
404
+ expect ( logSpy ) . toHaveBeenCalledWith ( 'Extracting ...' ) ;
405
+ } ) ;
406
+
407
+ it ( 'fallback to dist if version if not found in manifest' , async ( ) => {
408
+ os . platform = 'linux' ;
409
+ os . arch = 'x64' ;
410
+
411
+ // a version which is not in the manifest but is in node dist
412
+ let versionSpec = '11' ;
413
+
414
+ inputs [ 'node-version' ] = versionSpec ;
415
+ inputs [ 'check-latest' ] = 'true' ;
416
+ inputs [ 'always-auth' ] = false ;
417
+ inputs [ 'token' ] = 'faketoken' ;
418
+
419
+ // ... but not in the local cache
420
+ findSpy . mockImplementation ( ( ) => '' ) ;
421
+
422
+ dlSpy . mockImplementation ( async ( ) => '/some/temp/path' ) ;
423
+ let toolPath = path . normalize ( '/cache/node/11.11.0/x64' ) ;
424
+ exSpy . mockImplementation ( async ( ) => '/some/other/temp/path' ) ;
425
+ cacheSpy . mockImplementation ( async ( ) => toolPath ) ;
426
+
427
+ await main . run ( ) ;
428
+
429
+ let expPath = path . join ( toolPath , 'bin' ) ;
430
+
431
+ expect ( dlSpy ) . toHaveBeenCalled ( ) ;
432
+ expect ( exSpy ) . toHaveBeenCalled ( ) ;
433
+ expect ( logSpy ) . toHaveBeenCalledWith (
434
+ 'Attempt to resolve the latest version from manifest...'
435
+ ) ;
436
+ expect ( logSpy ) . toHaveBeenCalledWith (
437
+ `Failed to resolve version ${ versionSpec } from manifest`
438
+ ) ;
439
+ expect ( logSpy ) . toHaveBeenCalledWith (
440
+ `Attempting to download ${ versionSpec } ...`
441
+ ) ;
442
+ expect ( cnSpy ) . toHaveBeenCalledWith ( `::add-path::${ expPath } ${ osm . EOL } ` ) ;
443
+ } ) ;
444
+
445
+ it ( 'fallback to dist if manifest is not available' , async ( ) => {
446
+ os . platform = 'linux' ;
447
+ os . arch = 'x64' ;
448
+
449
+ // a version which is not in the manifest but is in node dist
450
+ let versionSpec = '12' ;
451
+
452
+ inputs [ 'node-version' ] = versionSpec ;
453
+ inputs [ 'check-latest' ] = 'true' ;
454
+ inputs [ 'always-auth' ] = false ;
455
+ inputs [ 'token' ] = 'faketoken' ;
456
+
457
+ // ... but not in the local cache
458
+ findSpy . mockImplementation ( ( ) => '' ) ;
459
+ getManifestSpy . mockImplementation ( ( ) => {
460
+ throw new Error ( 'Unable to download manifest' ) ;
461
+ } ) ;
462
+
463
+ dlSpy . mockImplementation ( async ( ) => '/some/temp/path' ) ;
464
+ let toolPath = path . normalize ( '/cache/node/12.11.0/x64' ) ;
465
+ exSpy . mockImplementation ( async ( ) => '/some/other/temp/path' ) ;
466
+ cacheSpy . mockImplementation ( async ( ) => toolPath ) ;
467
+
468
+ await main . run ( ) ;
469
+
470
+ let expPath = path . join ( toolPath , 'bin' ) ;
471
+
472
+ expect ( dlSpy ) . toHaveBeenCalled ( ) ;
473
+ expect ( exSpy ) . toHaveBeenCalled ( ) ;
474
+ expect ( logSpy ) . toHaveBeenCalledWith (
475
+ 'Attempt to resolve the latest version from manifest...'
476
+ ) ;
477
+ expect ( logSpy ) . toHaveBeenCalledWith (
478
+ 'Unable to resolve version from manifest...'
479
+ ) ;
480
+ expect ( logSpy ) . toHaveBeenCalledWith (
481
+ `Failed to resolve version ${ versionSpec } from manifest`
482
+ ) ;
483
+ expect ( logSpy ) . toHaveBeenCalledWith (
484
+ `Attempting to download ${ versionSpec } ...`
485
+ ) ;
486
+ expect ( cnSpy ) . toHaveBeenCalledWith ( `::add-path::${ expPath } ${ osm . EOL } ` ) ;
487
+ } ) ;
488
+ } ) ;
336
489
} ) ;
0 commit comments