@@ -134,6 +134,7 @@ describe('setup-node', () => {
134134 let match = await tc . findFromManifest ( '12.16.2' , true , versions ) ;
135135 expect ( match ) . toBeDefined ( ) ;
136136 expect ( match ?. version ) . toBe ( '12.16.2' ) ;
137+ expect ( ( match as any ) . lts ) . toBe ( 'Erbium' ) ;
137138 } ) ;
138139
139140 it ( 'can find 12 from manifest on linux' , async ( ) => {
@@ -148,6 +149,7 @@ describe('setup-node', () => {
148149 let match = await tc . findFromManifest ( '12.16.2' , true , versions ) ;
149150 expect ( match ) . toBeDefined ( ) ;
150151 expect ( match ?. version ) . toBe ( '12.16.2' ) ;
152+ expect ( ( match as any ) . lts ) . toBe ( 'Erbium' ) ;
151153 } ) ;
152154
153155 it ( 'can find 10 from manifest on windows' , async ( ) => {
@@ -162,6 +164,7 @@ describe('setup-node', () => {
162164 let match = await tc . findFromManifest ( '10' , true , versions ) ;
163165 expect ( match ) . toBeDefined ( ) ;
164166 expect ( match ?. version ) . toBe ( '10.20.1' ) ;
167+ expect ( ( match as any ) . lts ) . toBe ( 'Dubnium' ) ;
165168 } ) ;
166169
167170 //--------------------------------------------------
@@ -217,6 +220,10 @@ describe('setup-node', () => {
217220 expect ( cnSpy ) . toHaveBeenCalledWith ( '::error::' + errMsg + osm . EOL ) ;
218221 } ) ;
219222
223+ //--------------------------------------------------
224+ // Manifest tests
225+ //--------------------------------------------------
226+
220227 it ( 'downloads a version from a manifest match' , async ( ) => {
221228 os . platform = 'linux' ;
222229 os . arch = 'x64' ;
@@ -392,6 +399,10 @@ describe('setup-node', () => {
392399 expect ( logSpy ) . not . toHaveBeenCalledWith (
393400 'Attempt to resolve the latest version from manifest...'
394401 ) ;
402+ expect ( dbgSpy ) . not . toHaveBeenCalledWith ( 'No manifest cached' ) ;
403+ expect ( dbgSpy ) . not . toHaveBeenCalledWith (
404+ 'Getting manifest from actions/node-versions@main'
405+ ) ;
395406 } ) ;
396407
397408 it ( 'check latest version and resolve it from local cache' , async ( ) => {
@@ -412,6 +423,10 @@ describe('setup-node', () => {
412423 expect ( logSpy ) . toHaveBeenCalledWith (
413424 'Attempt to resolve the latest version from manifest...'
414425 ) ;
426+ expect ( dbgSpy ) . toHaveBeenCalledWith ( 'No manifest cached' ) ;
427+ expect ( dbgSpy ) . toHaveBeenCalledWith (
428+ 'Getting manifest from actions/node-versions@main'
429+ ) ;
415430 expect ( logSpy ) . toHaveBeenCalledWith ( "Resolved as '12.16.2'" ) ;
416431 expect ( logSpy ) . toHaveBeenCalledWith ( `Found in cache @ ${ toolPath } ` ) ;
417432 } ) ;
@@ -436,6 +451,10 @@ describe('setup-node', () => {
436451 expect ( logSpy ) . toHaveBeenCalledWith (
437452 'Attempt to resolve the latest version from manifest...'
438453 ) ;
454+ expect ( dbgSpy ) . toHaveBeenCalledWith ( 'No manifest cached' ) ;
455+ expect ( dbgSpy ) . toHaveBeenCalledWith (
456+ 'Getting manifest from actions/node-versions@main'
457+ ) ;
439458 expect ( logSpy ) . toHaveBeenCalledWith ( "Resolved as '12.16.2'" ) ;
440459 expect ( logSpy ) . toHaveBeenCalledWith (
441460 `Acquiring 12.16.2 - ${ os . arch } from ${ expectedUrl } `
@@ -472,6 +491,10 @@ describe('setup-node', () => {
472491 expect ( logSpy ) . toHaveBeenCalledWith (
473492 'Attempt to resolve the latest version from manifest...'
474493 ) ;
494+ expect ( dbgSpy ) . toHaveBeenCalledWith ( 'No manifest cached' ) ;
495+ expect ( dbgSpy ) . toHaveBeenCalledWith (
496+ 'Getting manifest from actions/node-versions@main'
497+ ) ;
475498 expect ( logSpy ) . toHaveBeenCalledWith (
476499 `Failed to resolve version ${ versionSpec } from manifest`
477500 ) ;
@@ -525,4 +548,222 @@ describe('setup-node', () => {
525548 expect ( cnSpy ) . toHaveBeenCalledWith ( `::add-path::${ expPath } ${ osm . EOL } ` ) ;
526549 } ) ;
527550 } ) ;
551+
552+ describe ( 'LTS version' , ( ) => {
553+ beforeEach ( ( ) => {
554+ os . platform = 'linux' ;
555+ os . arch = 'x64' ;
556+ inputs . stable = 'true' ;
557+ } ) ;
558+
559+ it ( 'find latest LTS version and resolve it from local cache (lts/erbium)' , async ( ) => {
560+ // arrange
561+ inputs [ 'node-version' ] = 'lts/erbium' ;
562+
563+ const toolPath = path . normalize ( '/cache/node/12.16.2/x64' ) ;
564+ findSpy . mockReturnValue ( toolPath ) ;
565+
566+ // act
567+ await main . run ( ) ;
568+
569+ // assert
570+ expect ( logSpy ) . toHaveBeenCalledWith (
571+ 'Attempt to resolve LTS alias from manifest...'
572+ ) ;
573+ expect ( dbgSpy ) . toHaveBeenCalledWith (
574+ 'Getting manifest from actions/node-versions@main'
575+ ) ;
576+ expect ( dbgSpy ) . not . toHaveBeenCalledWith ( 'No manifest cached' ) ;
577+ expect ( dbgSpy ) . toHaveBeenCalledWith (
578+ `LTS alias 'erbium' for Node version 'lts/erbium'`
579+ ) ;
580+ expect ( dbgSpy ) . toHaveBeenCalledWith (
581+ `Found LTS release '12.16.2' for Node version 'lts/erbium'`
582+ ) ;
583+ expect ( logSpy ) . toHaveBeenCalledWith ( `Found in cache @ ${ toolPath } ` ) ;
584+ expect ( cnSpy ) . toHaveBeenCalledWith (
585+ `::add-path::${ path . join ( toolPath , 'bin' ) } ${ osm . EOL } `
586+ ) ;
587+ } ) ;
588+
589+ it ( 'find latest LTS version and install it from manifest (lts/erbium)' , async ( ) => {
590+ // arrange
591+ inputs [ 'node-version' ] = 'lts/erbium' ;
592+
593+ const toolPath = path . normalize ( '/cache/node/12.16.2/x64' ) ;
594+ findSpy . mockImplementation ( ( ) => '' ) ;
595+ dlSpy . mockImplementation ( async ( ) => '/some/temp/path' ) ;
596+ exSpy . mockImplementation ( async ( ) => '/some/other/temp/path' ) ;
597+ cacheSpy . mockImplementation ( async ( ) => toolPath ) ;
598+ const expectedUrl =
599+ 'https://github.com/actions/node-versions/releases/download/12.16.2-20200423.28/node-12.16.2-linux-x64.tar.gz' ;
600+
601+ // act
602+ await main . run ( ) ;
603+
604+ // assert
605+ expect ( logSpy ) . toHaveBeenCalledWith (
606+ 'Attempt to resolve LTS alias from manifest...'
607+ ) ;
608+ expect ( dbgSpy ) . toHaveBeenCalledWith (
609+ 'Getting manifest from actions/node-versions@main'
610+ ) ;
611+ expect ( dbgSpy ) . not . toHaveBeenCalledWith ( 'No manifest cached' ) ;
612+ expect ( dbgSpy ) . toHaveBeenCalledWith (
613+ `LTS alias 'erbium' for Node version 'lts/erbium'`
614+ ) ;
615+ expect ( dbgSpy ) . toHaveBeenCalledWith (
616+ `Found LTS release '12.16.2' for Node version 'lts/erbium'`
617+ ) ;
618+ expect ( logSpy ) . toHaveBeenCalledWith ( 'Attempting to download 12...' ) ;
619+ expect ( logSpy ) . toHaveBeenCalledWith (
620+ `Acquiring 12.16.2 - ${ os . arch } from ${ expectedUrl } `
621+ ) ;
622+ expect ( logSpy ) . toHaveBeenCalledWith ( 'Extracting ...' ) ;
623+ expect ( logSpy ) . toHaveBeenCalledWith ( 'Adding to the cache ...' ) ;
624+ expect ( cnSpy ) . toHaveBeenCalledWith (
625+ `::add-path::${ path . join ( toolPath , 'bin' ) } ${ osm . EOL } `
626+ ) ;
627+ } ) ;
628+
629+ it ( 'find latest LTS version and resolve it from local cache (lts/*)' , async ( ) => {
630+ // arrange
631+ inputs [ 'node-version' ] = 'lts/*' ;
632+
633+ const toolPath = path . normalize ( '/cache/node/14.0.0/x64' ) ;
634+ findSpy . mockReturnValue ( toolPath ) ;
635+
636+ // act
637+ await main . run ( ) ;
638+
639+ // assert
640+ expect ( logSpy ) . toHaveBeenCalledWith (
641+ 'Attempt to resolve LTS alias from manifest...'
642+ ) ;
643+ expect ( dbgSpy ) . toHaveBeenCalledWith (
644+ 'Getting manifest from actions/node-versions@main'
645+ ) ;
646+ expect ( dbgSpy ) . not . toHaveBeenCalledWith ( 'No manifest cached' ) ;
647+ expect ( dbgSpy ) . toHaveBeenCalledWith (
648+ `LTS alias '*' for Node version 'lts/*'`
649+ ) ;
650+ expect ( dbgSpy ) . toHaveBeenCalledWith (
651+ `Found LTS release '14.0.0' for Node version 'lts/*'`
652+ ) ;
653+ expect ( logSpy ) . toHaveBeenCalledWith ( `Found in cache @ ${ toolPath } ` ) ;
654+ expect ( cnSpy ) . toHaveBeenCalledWith (
655+ `::add-path::${ path . join ( toolPath , 'bin' ) } ${ osm . EOL } `
656+ ) ;
657+ } ) ;
658+
659+ it ( 'find latest LTS version and install it from manifest (lts/*)' , async ( ) => {
660+ // arrange
661+ inputs [ 'node-version' ] = 'lts/*' ;
662+
663+ const toolPath = path . normalize ( '/cache/node/14.0.0/x64' ) ;
664+ findSpy . mockImplementation ( ( ) => '' ) ;
665+ dlSpy . mockImplementation ( async ( ) => '/some/temp/path' ) ;
666+ exSpy . mockImplementation ( async ( ) => '/some/other/temp/path' ) ;
667+ cacheSpy . mockImplementation ( async ( ) => toolPath ) ;
668+ const expectedUrl =
669+ 'https://github.com/actions/node-versions/releases/download/14.0.0-20200423.30/node-14.0.0-linux-x64.tar.gz' ;
670+
671+ // act
672+ await main . run ( ) ;
673+
674+ // assert
675+ expect ( logSpy ) . toHaveBeenCalledWith (
676+ 'Attempt to resolve LTS alias from manifest...'
677+ ) ;
678+ expect ( dbgSpy ) . toHaveBeenCalledWith (
679+ 'Getting manifest from actions/node-versions@main'
680+ ) ;
681+ expect ( dbgSpy ) . not . toHaveBeenCalledWith ( 'No manifest cached' ) ;
682+ expect ( dbgSpy ) . toHaveBeenCalledWith (
683+ `LTS alias '*' for Node version 'lts/*'`
684+ ) ;
685+ expect ( dbgSpy ) . toHaveBeenCalledWith (
686+ `Found LTS release '14.0.0' for Node version 'lts/*'`
687+ ) ;
688+ expect ( logSpy ) . toHaveBeenCalledWith ( 'Attempting to download 14...' ) ;
689+ expect ( logSpy ) . toHaveBeenCalledWith (
690+ `Acquiring 14.0.0 - ${ os . arch } from ${ expectedUrl } `
691+ ) ;
692+ expect ( logSpy ) . toHaveBeenCalledWith ( 'Extracting ...' ) ;
693+ expect ( logSpy ) . toHaveBeenCalledWith ( 'Adding to the cache ...' ) ;
694+ expect ( cnSpy ) . toHaveBeenCalledWith (
695+ `::add-path::${ path . join ( toolPath , 'bin' ) } ${ osm . EOL } `
696+ ) ;
697+ } ) ;
698+
699+ it ( 'fail with unable to parse LTS alias (lts/)' , async ( ) => {
700+ // arrange
701+ inputs [ 'node-version' ] = 'lts/' ;
702+
703+ findSpy . mockImplementation ( ( ) => '' ) ;
704+
705+ // act
706+ await main . run ( ) ;
707+
708+ // assert
709+ expect ( logSpy ) . toHaveBeenCalledWith (
710+ 'Attempt to resolve LTS alias from manifest...'
711+ ) ;
712+ expect ( dbgSpy ) . toHaveBeenCalledWith (
713+ 'Getting manifest from actions/node-versions@main'
714+ ) ;
715+ expect ( cnSpy ) . toHaveBeenCalledWith (
716+ `::error::Unable to parse LTS alias for Node version 'lts/'${ osm . EOL } `
717+ ) ;
718+ } ) ;
719+
720+ it ( 'fail to find LTS version (lts/unknown)' , async ( ) => {
721+ // arrange
722+ inputs [ 'node-version' ] = 'lts/unknown' ;
723+
724+ findSpy . mockImplementation ( ( ) => '' ) ;
725+
726+ // act
727+ await main . run ( ) ;
728+
729+ // assert
730+ expect ( logSpy ) . toHaveBeenCalledWith (
731+ 'Attempt to resolve LTS alias from manifest...'
732+ ) ;
733+ expect ( dbgSpy ) . toHaveBeenCalledWith (
734+ 'Getting manifest from actions/node-versions@main'
735+ ) ;
736+ expect ( dbgSpy ) . toHaveBeenCalledWith (
737+ `LTS alias 'unknown' for Node version 'lts/unknown'`
738+ ) ;
739+ expect ( cnSpy ) . toHaveBeenCalledWith (
740+ `::error::Unable to find LTS release 'unknown' for Node version 'lts/unknown'.${ osm . EOL } `
741+ ) ;
742+ } ) ;
743+
744+ it ( 'fail if manifest is not available' , async ( ) => {
745+ // arrange
746+ inputs [ 'node-version' ] = 'lts/erbium' ;
747+
748+ // ... but not in the local cache
749+ findSpy . mockImplementation ( ( ) => '' ) ;
750+ getManifestSpy . mockImplementation ( ( ) => {
751+ throw new Error ( 'Unable to download manifest' ) ;
752+ } ) ;
753+
754+ // act
755+ await main . run ( ) ;
756+
757+ // assert
758+ expect ( logSpy ) . toHaveBeenCalledWith (
759+ 'Attempt to resolve LTS alias from manifest...'
760+ ) ;
761+ expect ( dbgSpy ) . toHaveBeenCalledWith (
762+ 'Getting manifest from actions/node-versions@main'
763+ ) ;
764+ expect ( cnSpy ) . toHaveBeenCalledWith (
765+ `::error::Unable to download manifest${ osm . EOL } `
766+ ) ;
767+ } ) ;
768+ } ) ;
528769} ) ;
0 commit comments