@@ -9,6 +9,7 @@ import * as main from '../src/main';
9
9
import * as im from '../src/installer' ;
10
10
import * as auth from '../src/authutil' ;
11
11
import { context } from '@actions/github' ;
12
+ import nock = require( 'nock' ) ;
12
13
13
14
let nodeTestManifest = require ( './data/versions-manifest.json' ) ;
14
15
let nodeTestDist = require ( './data/node-dist-index.json' ) ;
@@ -337,6 +338,52 @@ describe('setup-node', () => {
337
338
expect ( cnSpy ) . toHaveBeenCalledWith ( `::error::${ errMsg } ${ osm . EOL } ` ) ;
338
339
} ) ;
339
340
341
+ it ( 'Acquires specified x64 or x86 version of node if no matching version is installed' , async ( ) => {
342
+ const toolDir = path . join (
343
+ __dirname ,
344
+ 'runner' ,
345
+ path . join (
346
+ Math . random ( )
347
+ . toString ( 36 )
348
+ . substring ( 7 )
349
+ ) ,
350
+ 'tools'
351
+ ) ;
352
+
353
+ os . platform = process . platform ;
354
+ const IS_WINDOWS = os . platform === 'win32' ;
355
+ for ( const { arch, version} of [
356
+ { arch : 'x64' , version : '12.18.3' } ,
357
+ { arch : 'x86' , version : '12.18.3' }
358
+ ] ) {
359
+ nock . cleanAll ( ) ;
360
+ const fileExtension = IS_WINDOWS ? '7z' : 'tar.gz' ;
361
+ const platform = {
362
+ linux : 'linux' ,
363
+ darwin : 'darwin' ,
364
+ win32 : 'win'
365
+ } [ process . platform ] ;
366
+ const fileName = `node-v${ version } -${ platform } -${ arch } .${ fileExtension } ` ;
367
+ const pathOnNodeJs = `/dist/v${ version } /${ fileName } ` ;
368
+ const scope = nock ( 'nodejs.org' )
369
+ . get ( pathOnNodeJs )
370
+ . replyWithFile (
371
+ 200 ,
372
+ path . join ( __dirname , '__fixtures__' , `mock-${ fileName } ` )
373
+ ) ;
374
+ await im . getNode ( version , true , true , undefined , arch ) ;
375
+ const nodeDir = path . join ( toolDir , 'node' , version , arch ) ;
376
+
377
+ expect ( scope . isDone ( ) ) . toBe ( true ) ;
378
+ expect ( fs . existsSync ( `${ nodeDir } .complete` ) ) . toBe ( true ) ;
379
+ if ( IS_WINDOWS ) {
380
+ expect ( fs . existsSync ( path . join ( nodeDir , 'node.exe' ) ) ) . toBe ( true ) ;
381
+ } else {
382
+ expect ( fs . existsSync ( path . join ( nodeDir , 'bin' , 'node' ) ) ) . toBe ( true ) ;
383
+ }
384
+ }
385
+ } , 100000 ) ;
386
+
340
387
describe ( 'check-latest flag' , ( ) => {
341
388
it ( 'use local version and dont check manifest if check-latest is not specified' , async ( ) => {
342
389
os . platform = 'linux' ;
0 commit comments