@@ -39,6 +39,7 @@ describe('setup-node', () => {
39
39
let whichSpy : jest . SpyInstance ;
40
40
let existsSpy : jest . SpyInstance ;
41
41
let mkdirpSpy : jest . SpyInstance ;
42
+ let cpSpy : jest . SpyInstance ;
42
43
let execSpy : jest . SpyInstance ;
43
44
let authSpy : jest . SpyInstance ;
44
45
let parseNodeVersionSpy : jest . SpyInstance ;
@@ -51,6 +52,7 @@ describe('setup-node', () => {
51
52
console . log ( '::stop-commands::stoptoken' ) ; // Disable executing of runner commands when running tests in actions
52
53
process . env [ 'GITHUB_PATH' ] = '' ; // Stub out ENV file functionality so we can verify it writes to standard out
53
54
process . env [ 'GITHUB_OUTPUT' ] = '' ; // Stub out ENV file functionality so we can verify it writes to standard out
55
+ process . env [ 'RUNNER_TEMP' ] = '/runner_temp' ;
54
56
inputs = { } ;
55
57
inSpy = jest . spyOn ( core , 'getInput' ) ;
56
58
inSpy . mockImplementation ( name => inputs [ name ] ) ;
@@ -78,6 +80,7 @@ describe('setup-node', () => {
78
80
whichSpy = jest . spyOn ( io , 'which' ) ;
79
81
existsSpy = jest . spyOn ( fs , 'existsSync' ) ;
80
82
mkdirpSpy = jest . spyOn ( io , 'mkdirP' ) ;
83
+ cpSpy = jest . spyOn ( io , 'cp' ) ;
81
84
82
85
// @actions /tool-cache
83
86
isCacheActionAvailable = jest . spyOn ( cache , 'isFeatureAvailable' ) ;
@@ -273,6 +276,92 @@ describe('setup-node', () => {
273
276
expect ( cnSpy ) . toHaveBeenCalledWith ( `::add-path::${ expPath } ${ osm . EOL } ` ) ;
274
277
} ) ;
275
278
279
+ it ( 'windows: falls back to exe version if not in manifest and not in node dist' , async ( ) => {
280
+ os . platform = 'win32' ;
281
+ os . arch = 'x64' ;
282
+
283
+ // a version which is not in the manifest but is in node dist
284
+ const versionSpec = '13.13.1-nightly20200415947ddec091' ;
285
+
286
+ const workingUrls = [
287
+ `https://nodejs.org/download/nightly/v${ versionSpec } /win-x64/node.exe` ,
288
+ `https://nodejs.org/download/nightly/v${ versionSpec } /win-x64/node.lib`
289
+ ] ;
290
+
291
+ inputs [ 'node-version' ] = versionSpec ;
292
+ inputs [ 'always-auth' ] = false ;
293
+ inputs [ 'token' ] = 'faketoken' ;
294
+
295
+ // ... but not in the local cache
296
+ findSpy . mockImplementation ( ( ) => '' ) ;
297
+ findAllVersionsSpy . mockImplementation ( ( ) => [ ] ) ;
298
+
299
+ dlSpy . mockImplementation ( async url => {
300
+ if ( workingUrls . includes ( url ) ) {
301
+ return '/some/temp/path' ;
302
+ }
303
+
304
+ throw new tc . HTTPError ( 404 ) ;
305
+ } ) ;
306
+ const toolPath = path . normalize (
307
+ '/cache/node/13.13.1-nightly20200415947ddec091/x64'
308
+ ) ;
309
+ cacheSpy . mockImplementation ( async ( ) => toolPath ) ;
310
+ mkdirpSpy . mockImplementation ( async ( ) => { } ) ;
311
+ cpSpy . mockImplementation ( async ( ) => { } ) ;
312
+
313
+ await main . run ( ) ;
314
+
315
+ workingUrls . forEach ( url => {
316
+ expect ( dlSpy ) . toHaveBeenCalledWith ( url ) ;
317
+ } ) ;
318
+ expect ( cnSpy ) . toHaveBeenCalledWith ( `::add-path::${ toolPath } ${ osm . EOL } ` ) ;
319
+ } ) ;
320
+
321
+ it ( 'linux: does not fall back to exe version if not in manifest and not in node dist' , async ( ) => {
322
+ os . platform = 'linux' ;
323
+ os . arch = 'x64' ;
324
+
325
+ // a version which is not in the manifest but is in node dist
326
+ const versionSpec = '13.13.1-nightly20200415947ddec091' ;
327
+
328
+ const workingUrls = [
329
+ `https://nodejs.org/download/nightly/v${ versionSpec } /win-x64/node.exe` ,
330
+ `https://nodejs.org/download/nightly/v${ versionSpec } /win-x64/node.lib`
331
+ ] ;
332
+
333
+ inputs [ 'node-version' ] = versionSpec ;
334
+ inputs [ 'always-auth' ] = false ;
335
+ inputs [ 'token' ] = 'faketoken' ;
336
+
337
+ // ... but not in the local cache
338
+ findSpy . mockImplementation ( ( ) => '' ) ;
339
+ findAllVersionsSpy . mockImplementation ( ( ) => [ ] ) ;
340
+
341
+ dlSpy . mockImplementation ( async url => {
342
+ if ( workingUrls . includes ( url ) ) {
343
+ return '/some/temp/path' ;
344
+ }
345
+
346
+ throw new tc . HTTPError ( 404 ) ;
347
+ } ) ;
348
+ const toolPath = path . normalize (
349
+ '/cache/node/13.13.1-nightly20200415947ddec091/x64'
350
+ ) ;
351
+ cacheSpy . mockImplementation ( async ( ) => toolPath ) ;
352
+ mkdirpSpy . mockImplementation ( async ( ) => { } ) ;
353
+ cpSpy . mockImplementation ( async ( ) => { } ) ;
354
+
355
+ await main . run ( ) ;
356
+
357
+ workingUrls . forEach ( url => {
358
+ expect ( dlSpy ) . not . toHaveBeenCalledWith ( url ) ;
359
+ } ) ;
360
+ expect ( cnSpy ) . toHaveBeenCalledWith (
361
+ `::error::Unexpected HTTP response: 404${ osm . EOL } `
362
+ ) ;
363
+ } ) ;
364
+
276
365
it ( 'does not find a version that does not exist' , async ( ) => {
277
366
os . platform = 'linux' ;
278
367
os . arch = 'x64' ;
0 commit comments