@@ -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' ) ;
@@ -40,7 +41,20 @@ describe('setup-node', () => {
40
41
let execSpy : jest . SpyInstance ;
41
42
let authSpy : jest . SpyInstance ;
42
43
44
+ const IS_WINDOWS = process . platform === 'win32' ;
45
+ const toolDir = path . join (
46
+ __dirname ,
47
+ 'runner' ,
48
+ path . join (
49
+ Math . random ( )
50
+ . toString ( 36 )
51
+ . substring ( 7 )
52
+ ) ,
53
+ 'tools'
54
+ ) ;
55
+
43
56
beforeEach ( ( ) => {
57
+ nock . cleanAll ( ) ;
44
58
// @actions /core
45
59
inputs = { } ;
46
60
inSpy = jest . spyOn ( core , 'getInput' ) ;
@@ -337,6 +351,64 @@ describe('setup-node', () => {
337
351
expect ( cnSpy ) . toHaveBeenCalledWith ( `::error::${ errMsg } ${ osm . EOL } ` ) ;
338
352
} ) ;
339
353
354
+ it ( 'Acquires specified x86 version of node if no matching version is installed' , async ( ) => {
355
+ const arch = 'x86' ;
356
+ const version = '8.8.0' ;
357
+ const fileExtension = IS_WINDOWS ? '7z' : 'tar.gz' ;
358
+ const platform = {
359
+ linux : 'linux' ,
360
+ darwin : 'darwin' ,
361
+ win32 : 'win'
362
+ } [ process . platform ] ;
363
+ const fileName = `node-v${ version } -${ platform } -${ arch } .${ fileExtension } ` ;
364
+ const pathOnNodeJs = `/dist/v${ version } /${ fileName } ` ;
365
+ const scope = nock ( 'nodejs.org' )
366
+ . get ( pathOnNodeJs )
367
+ . replyWithFile (
368
+ 200 ,
369
+ path . join ( __dirname , '__fixtures__' , `mock-${ fileName } ` )
370
+ ) ;
371
+ await im . getNode ( version , true , true , arch ) ;
372
+ const nodeDir = path . join ( toolDir , 'node' , version , arch ) ;
373
+
374
+ expect ( scope . isDone ( ) ) . toBe ( true ) ;
375
+ expect ( fs . existsSync ( `${ nodeDir } .complete` ) ) . toBe ( true ) ;
376
+ if ( IS_WINDOWS ) {
377
+ expect ( fs . existsSync ( path . join ( nodeDir , 'node.exe' ) ) ) . toBe ( true ) ;
378
+ } else {
379
+ expect ( fs . existsSync ( path . join ( nodeDir , 'bin' , 'node' ) ) ) . toBe ( true ) ;
380
+ }
381
+ } , 100000 ) ;
382
+
383
+ it ( 'Acquires specified x64 version of node if no matching version is installed' , async ( ) => {
384
+ const arch = 'x64' ;
385
+ const version = '8.9.1' ;
386
+ const fileExtension = IS_WINDOWS ? '7z' : 'tar.gz' ;
387
+ const platform = {
388
+ linux : 'linux' ,
389
+ darwin : 'darwin' ,
390
+ win32 : 'win'
391
+ } [ process . platform ] ;
392
+ const fileName = `node-v${ version } -${ platform } -${ arch } .${ fileExtension } ` ;
393
+ const pathOnNodeJs = `/dist/v${ version } /${ fileName } ` ;
394
+ const scope = nock ( 'nodejs.org' )
395
+ . get ( pathOnNodeJs )
396
+ . replyWithFile (
397
+ 200 ,
398
+ path . join ( __dirname , '__fixtures__' , `mock-${ fileName } ` )
399
+ ) ;
400
+ await im . getNode ( version , true , true , arch ) ;
401
+ const nodeDir = path . join ( toolDir , 'node' , version , arch ) ;
402
+
403
+ expect ( scope . isDone ( ) ) . toBe ( true ) ;
404
+ expect ( fs . existsSync ( `${ nodeDir } .complete` ) ) . toBe ( true ) ;
405
+ if ( IS_WINDOWS ) {
406
+ expect ( fs . existsSync ( path . join ( nodeDir , 'node.exe' ) ) ) . toBe ( true ) ;
407
+ } else {
408
+ expect ( fs . existsSync ( path . join ( nodeDir , 'bin' , 'node' ) ) ) . toBe ( true ) ;
409
+ }
410
+ } , 100000 ) ;
411
+
340
412
describe ( 'check-latest flag' , ( ) => {
341
413
it ( 'use local version and dont check manifest if check-latest is not specified' , async ( ) => {
342
414
os . platform = 'linux' ;
0 commit comments