11import io = require( '@actions/io' ) ;
22import fs = require( 'fs' ) ;
3+ import nock = require( 'nock' ) ;
34import os = require( 'os' ) ;
45import path = require( 'path' ) ;
56
@@ -36,6 +37,10 @@ describe('installer tests', () => {
3637 await io . rmRF ( tempDir ) ;
3738 } , 100000 ) ;
3839
40+ beforeEach ( ( ) => {
41+ nock . cleanAll ( ) ;
42+ } ) ;
43+
3944 it ( 'Acquires version of node if no matching version is installed' , async ( ) => {
4045 await installer . getNode ( '10.16.0' ) ;
4146 const nodeDir = path . join ( toolDir , 'node' , '10.16.0' , os . arch ( ) ) ;
@@ -123,9 +128,25 @@ describe('installer tests', () => {
123128
124129 it ( 'Acquires specified x86 version of node if no matching version is installed' , async ( ) => {
125130 const arch = 'x86' ;
126- await installer . getNode ( '8.8.1' , arch ) ;
127- const nodeDir = path . join ( toolDir , 'node' , '8.8.1' , arch ) ;
128-
131+ const version = '8.8.0' ;
132+ const fileExtension = IS_WINDOWS ? '7z' : 'tar.gz' ;
133+ const platform = {
134+ linux : 'linux' ,
135+ darwin : 'darwin' ,
136+ win32 : 'win'
137+ } [ process . platform ] ;
138+ const fileName = `node-v${ version } -${ platform } -${ arch } .${ fileExtension } ` ;
139+ const pathOnNodeJs = `/dist/v${ version } /${ fileName } ` ;
140+ const scope = nock ( 'https://nodejs.org' )
141+ . get ( pathOnNodeJs )
142+ . replyWithFile (
143+ 200 ,
144+ path . join ( __dirname , '__fixtures__' , `mock-${ fileName } ` )
145+ ) ;
146+ await installer . getNode ( version , arch ) ;
147+ const nodeDir = path . join ( toolDir , 'node' , version , arch ) ;
148+
149+ expect ( scope . isDone ( ) ) . toBe ( true ) ;
129150 expect ( fs . existsSync ( `${ nodeDir } .complete` ) ) . toBe ( true ) ;
130151 if ( IS_WINDOWS ) {
131152 expect ( fs . existsSync ( path . join ( nodeDir , 'node.exe' ) ) ) . toBe ( true ) ;
@@ -136,9 +157,25 @@ describe('installer tests', () => {
136157
137158 it ( 'Acquires specified x64 version of node if no matching version is installed' , async ( ) => {
138159 const arch = 'x64' ;
139- await installer . getNode ( '8.8.1' , arch ) ;
140- const nodeDir = path . join ( toolDir , 'node' , '8.8.1' , arch ) ;
141-
160+ const version = '8.9.1' ;
161+ const fileExtension = IS_WINDOWS ? '7z' : 'tar.gz' ;
162+ const platform = {
163+ linux : 'linux' ,
164+ darwin : 'darwin' ,
165+ win32 : 'win'
166+ } [ process . platform ] ;
167+ const fileName = `node-v${ version } -${ platform } -${ arch } .${ fileExtension } ` ;
168+ const pathOnNodeJs = `/dist/v${ version } /${ fileName } ` ;
169+ const scope = nock ( 'https://nodejs.org' )
170+ . get ( pathOnNodeJs )
171+ . replyWithFile (
172+ 200 ,
173+ path . join ( __dirname , '__fixtures__' , `mock-${ fileName } ` )
174+ ) ;
175+ await installer . getNode ( version , arch ) ;
176+ const nodeDir = path . join ( toolDir , 'node' , version , arch ) ;
177+
178+ expect ( scope . isDone ( ) ) . toBe ( true ) ;
142179 expect ( fs . existsSync ( `${ nodeDir } .complete` ) ) . toBe ( true ) ;
143180 if ( IS_WINDOWS ) {
144181 expect ( fs . existsSync ( path . join ( nodeDir , 'node.exe' ) ) ) . toBe ( true ) ;
0 commit comments