mirror of
				https://github.com/actions/setup-node.git
				synced 2025-10-31 16:14:00 +08:00 
			
		
		
		
	Add support for v8-canary, nightly and rc (#655)
This commit is contained in:
		
							
								
								
									
										531
									
								
								__tests__/canary-installer.test.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										531
									
								
								__tests__/canary-installer.test.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,531 @@ | ||||
| import * as core from '@actions/core'; | ||||
| import * as io from '@actions/io'; | ||||
| import * as tc from '@actions/tool-cache'; | ||||
| import * as httpm from '@actions/http-client'; | ||||
| import * as exec from '@actions/exec'; | ||||
| import * as cache from '@actions/cache'; | ||||
| import fs from 'fs'; | ||||
| import cp from 'child_process'; | ||||
| import osm from 'os'; | ||||
| import path from 'path'; | ||||
| import * as main from '../src/main'; | ||||
| import * as auth from '../src/authutil'; | ||||
| import {INodeVersion} from '../src/distributions/base-models'; | ||||
|  | ||||
| const nodeTestManifest = require('./data/versions-manifest.json'); | ||||
| const nodeTestDist = require('./data/node-dist-index.json'); | ||||
| const nodeTestDistNightly = require('./data/node-nightly-index.json'); | ||||
| const nodeTestDistRc = require('./data/node-rc-index.json'); | ||||
| const nodeV8CanaryTestDist = require('./data/v8-canary-dist-index.json'); | ||||
|  | ||||
| describe('setup-node', () => { | ||||
|   let inputs = {} as any; | ||||
|   let os = {} as any; | ||||
|  | ||||
|   let inSpy: jest.SpyInstance; | ||||
|   let findSpy: jest.SpyInstance; | ||||
|   let findAllVersionsSpy: jest.SpyInstance; | ||||
|   let cnSpy: jest.SpyInstance; | ||||
|   let logSpy: jest.SpyInstance; | ||||
|   let warningSpy: jest.SpyInstance; | ||||
|   let getManifestSpy: jest.SpyInstance; | ||||
|   let getDistSpy: jest.SpyInstance; | ||||
|   let platSpy: jest.SpyInstance; | ||||
|   let archSpy: jest.SpyInstance; | ||||
|   let dlSpy: jest.SpyInstance; | ||||
|   let exSpy: jest.SpyInstance; | ||||
|   let cacheSpy: jest.SpyInstance; | ||||
|   let dbgSpy: jest.SpyInstance; | ||||
|   let whichSpy: jest.SpyInstance; | ||||
|   let existsSpy: jest.SpyInstance; | ||||
|   let readFileSyncSpy: jest.SpyInstance; | ||||
|   let mkdirpSpy: jest.SpyInstance; | ||||
|   let execSpy: jest.SpyInstance; | ||||
|   let authSpy: jest.SpyInstance; | ||||
|   let parseNodeVersionSpy: jest.SpyInstance; | ||||
|   let isCacheActionAvailable: jest.SpyInstance; | ||||
|   let getExecOutputSpy: jest.SpyInstance; | ||||
|   let getJsonSpy: jest.SpyInstance; | ||||
|  | ||||
|   beforeEach(() => { | ||||
|     // @actions/core | ||||
|     console.log('::stop-commands::stoptoken'); // Disable executing of runner commands when running tests in actions | ||||
|     process.env['GITHUB_PATH'] = ''; // Stub out ENV file functionality so we can verify it writes to standard out | ||||
|     process.env['GITHUB_OUTPUT'] = ''; // Stub out ENV file functionality so we can verify it writes to standard out | ||||
|     inputs = {}; | ||||
|     inSpy = jest.spyOn(core, 'getInput'); | ||||
|     inSpy.mockImplementation(name => inputs[name]); | ||||
|  | ||||
|     // node | ||||
|     os = {}; | ||||
|     platSpy = jest.spyOn(osm, 'platform'); | ||||
|     platSpy.mockImplementation(() => os['platform']); | ||||
|     archSpy = jest.spyOn(osm, 'arch'); | ||||
|     archSpy.mockImplementation(() => os['arch']); | ||||
|     execSpy = jest.spyOn(cp, 'execSync'); | ||||
|  | ||||
|     // @actions/tool-cache | ||||
|     findSpy = jest.spyOn(tc, 'find'); | ||||
|     findAllVersionsSpy = jest.spyOn(tc, 'findAllVersions'); | ||||
|     dlSpy = jest.spyOn(tc, 'downloadTool'); | ||||
|     exSpy = jest.spyOn(tc, 'extractTar'); | ||||
|     cacheSpy = jest.spyOn(tc, 'cacheDir'); | ||||
|     getManifestSpy = jest.spyOn(tc, 'getManifestFromRepo'); | ||||
|  | ||||
|     // http-client | ||||
|     getJsonSpy = jest.spyOn(httpm.HttpClient.prototype, 'getJson'); | ||||
|  | ||||
|     // io | ||||
|     whichSpy = jest.spyOn(io, 'which'); | ||||
|     existsSpy = jest.spyOn(fs, 'existsSync'); | ||||
|     mkdirpSpy = jest.spyOn(io, 'mkdirP'); | ||||
|  | ||||
|     // @actions/tool-cache | ||||
|     isCacheActionAvailable = jest.spyOn(cache, 'isFeatureAvailable'); | ||||
|  | ||||
|     // disable authentication portion for installer tests | ||||
|     authSpy = jest.spyOn(auth, 'configAuthentication'); | ||||
|     authSpy.mockImplementation(() => {}); | ||||
|  | ||||
|     // gets | ||||
|     getManifestSpy.mockImplementation( | ||||
|       () => <tc.IToolRelease[]>nodeTestManifest | ||||
|     ); | ||||
|  | ||||
|     getJsonSpy.mockImplementation(url => { | ||||
|       let res: any; | ||||
|       if (url.includes('/rc')) { | ||||
|         res = <INodeVersion>nodeTestDistRc; | ||||
|       } else if (url.includes('/nightly')) { | ||||
|         res = <INodeVersion>nodeTestDistNightly; | ||||
|       } else if (url.includes('/v8-canary')) { | ||||
|         res = <INodeVersion>nodeV8CanaryTestDist; | ||||
|       } else { | ||||
|         res = <INodeVersion>nodeTestDist; | ||||
|       } | ||||
|  | ||||
|       return {result: res}; | ||||
|     }); | ||||
|  | ||||
|     // writes | ||||
|     cnSpy = jest.spyOn(process.stdout, 'write'); | ||||
|     logSpy = jest.spyOn(core, 'info'); | ||||
|     dbgSpy = jest.spyOn(core, 'debug'); | ||||
|     warningSpy = jest.spyOn(core, 'warning'); | ||||
|     cnSpy.mockImplementation(line => { | ||||
|       // uncomment to debug | ||||
|       // process.stderr.write('write:' + line + '\n'); | ||||
|     }); | ||||
|     logSpy.mockImplementation(line => { | ||||
|       // uncomment to debug | ||||
|       // process.stderr.write('log:' + line + '\n'); | ||||
|     }); | ||||
|     dbgSpy.mockImplementation(msg => { | ||||
|       // uncomment to see debug output | ||||
|       // process.stderr.write(msg + '\n'); | ||||
|     }); | ||||
|     warningSpy.mockImplementation(msg => { | ||||
|       // uncomment to debug | ||||
|       // process.stderr.write('log:' + msg + '\n'); | ||||
|     }); | ||||
|  | ||||
|     // @actions/exec | ||||
|     getExecOutputSpy = jest.spyOn(exec, 'getExecOutput'); | ||||
|     getExecOutputSpy.mockImplementation(() => 'v16.15.0'); | ||||
|   }); | ||||
|  | ||||
|   afterEach(() => { | ||||
|     jest.resetAllMocks(); | ||||
|     jest.clearAllMocks(); | ||||
|     //jest.restoreAllMocks(); | ||||
|   }); | ||||
|  | ||||
|   afterAll(async () => { | ||||
|     console.log('::stoptoken::'); // Re-enable executing of runner commands when running tests in actions | ||||
|     jest.restoreAllMocks(); | ||||
|   }, 100000); | ||||
|  | ||||
|   //-------------------------------------------------- | ||||
|   // Found in cache tests | ||||
|   //-------------------------------------------------- | ||||
|  | ||||
|   it('finds version in cache with stable true', async () => { | ||||
|     inputs['node-version'] = '20-v8-canary'; | ||||
|     os['arch'] = 'x64'; | ||||
|     inputs.stable = 'true'; | ||||
|  | ||||
|     let toolPath = path.normalize( | ||||
|       '/cache/node/20.0.0-v8-canary20221103f7e2421e91/x64' | ||||
|     ); | ||||
|     findSpy.mockImplementation(() => toolPath); | ||||
|     findAllVersionsSpy.mockImplementation(() => [ | ||||
|       '20.0.0-v8-canary20221103f7e2421e91', | ||||
|       '20.0.0-v8-canary20221030fefe1c0879', | ||||
|       '19.0.0-v8-canary202210172ec229fc56', | ||||
|       '20.0.0-v8-canary2022102310ff1e5a8d' | ||||
|     ]); | ||||
|     await main.run(); | ||||
|  | ||||
|     expect(findSpy).toHaveBeenCalledWith( | ||||
|       'node', | ||||
|       '20.0.0-v8-canary20221103f7e2421e91', | ||||
|       'x64' | ||||
|     ); | ||||
|     expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); | ||||
|   }); | ||||
|  | ||||
|   it('finds version in cache and adds it to the path', async () => { | ||||
|     inputs['node-version'] = '20-v8-canary'; | ||||
|     os['arch'] = 'x64'; | ||||
|  | ||||
|     inSpy.mockImplementation(name => inputs[name]); | ||||
|  | ||||
|     let toolPath = path.normalize( | ||||
|       '/cache/node/20.0.0-v8-canary20221103f7e2421e91/x64' | ||||
|     ); | ||||
|     findSpy.mockImplementation(() => toolPath); | ||||
|     findAllVersionsSpy.mockImplementation(() => [ | ||||
|       '20.0.0-v8-canary20221103f7e2421e91', | ||||
|       '20.0.0-v8-canary20221030fefe1c0879', | ||||
|       '19.0.0-v8-canary202210172ec229fc56', | ||||
|       '20.0.0-v8-canary2022102310ff1e5a8d' | ||||
|     ]); | ||||
|     await main.run(); | ||||
|  | ||||
|     let expPath = path.join(toolPath, 'bin'); | ||||
|     expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`); | ||||
|   }); | ||||
|  | ||||
|   it('handles unhandled find error and reports error', async () => { | ||||
|     os.platform = 'linux'; | ||||
|     let errMsg = 'unhandled error message'; | ||||
|     inputs['node-version'] = '20.0.0-v8-canary20221103f7e2421e91'; | ||||
|  | ||||
|     findSpy.mockImplementation(() => { | ||||
|       throw new Error(errMsg); | ||||
|     }); | ||||
|     findAllVersionsSpy.mockImplementation(() => [ | ||||
|       '20.0.0-v8-canary20221103f7e2421e91', | ||||
|       '20.0.0-v8-canary20221030fefe1c0879', | ||||
|       '19.0.0-v8-canary202210172ec229fc56', | ||||
|       '20.0.0-v8-canary2022102310ff1e5a8d' | ||||
|     ]); | ||||
|  | ||||
|     await main.run(); | ||||
|  | ||||
|     expect(cnSpy).toHaveBeenCalledWith('::error::' + errMsg + osm.EOL); | ||||
|   }); | ||||
|  | ||||
|   //-------------------------------------------------- | ||||
|   // Manifest tests | ||||
|   //-------------------------------------------------- | ||||
|   it('falls back to a version from node dist', async () => { | ||||
|     os.platform = 'linux'; | ||||
|     os.arch = 'x64'; | ||||
|  | ||||
|     // a version which is not in the manifest but is in node dist | ||||
|     let versionSpec = '11.15.0'; | ||||
|  | ||||
|     inputs['node-version'] = versionSpec; | ||||
|     inputs['always-auth'] = false; | ||||
|     inputs['token'] = 'faketoken'; | ||||
|  | ||||
|     // ... but not in the local cache | ||||
|     findSpy.mockImplementation(() => ''); | ||||
|  | ||||
|     dlSpy.mockImplementation(async () => '/some/temp/path'); | ||||
|     let toolPath = path.normalize('/cache/node/11.11.0/x64'); | ||||
|     exSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||
|     cacheSpy.mockImplementation(async () => toolPath); | ||||
|  | ||||
|     await main.run(); | ||||
|  | ||||
|     let expPath = path.join(toolPath, 'bin'); | ||||
|  | ||||
|     expect(dlSpy).toHaveBeenCalled(); | ||||
|     expect(exSpy).toHaveBeenCalled(); | ||||
|     expect(logSpy).toHaveBeenCalledWith( | ||||
|       'Not found in manifest. Falling back to download directly from Node' | ||||
|     ); | ||||
|     expect(logSpy).toHaveBeenCalledWith( | ||||
|       `Attempting to download ${versionSpec}...` | ||||
|     ); | ||||
|     expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`); | ||||
|   }); | ||||
|  | ||||
|   it('does not find a version that does not exist', async () => { | ||||
|     os.platform = 'linux'; | ||||
|     os.arch = 'x64'; | ||||
|  | ||||
|     let versionSpec = '23.0.0-v8-canary20221103f7e2421e91'; | ||||
|     inputs['node-version'] = versionSpec; | ||||
|  | ||||
|     findSpy.mockImplementation(() => ''); | ||||
|     findAllVersionsSpy.mockImplementation(() => [ | ||||
|       '20.0.0-v8-canary20221103f7e2421e91', | ||||
|       '20.0.0-v8-canary20221030fefe1c0879', | ||||
|       '19.0.0-v8-canary202210172ec229fc56', | ||||
|       '20.0.0-v8-canary2022102310ff1e5a8d' | ||||
|     ]); | ||||
|     await main.run(); | ||||
|  | ||||
|     expect(cnSpy).toHaveBeenCalledWith( | ||||
|       `::error::Unable to find Node version '${versionSpec}' for platform ${os.platform} and architecture ${os.arch}.${osm.EOL}` | ||||
|     ); | ||||
|   }); | ||||
|  | ||||
|   it('reports a failed download', async () => { | ||||
|     let errMsg = 'unhandled download message'; | ||||
|     os.platform = 'linux'; | ||||
|     os.arch = 'x64'; | ||||
|  | ||||
|     // a version which is in the manifest | ||||
|     let versionSpec = '19.0.0-v8-canary'; | ||||
|  | ||||
|     inputs['node-version'] = versionSpec; | ||||
|     inputs['always-auth'] = false; | ||||
|     inputs['token'] = 'faketoken'; | ||||
|  | ||||
|     findSpy.mockImplementation(() => ''); | ||||
|     findAllVersionsSpy.mockImplementation(() => [ | ||||
|       '20.0.0-v8-canary20221103f7e2421e91', | ||||
|       '20.0.0-v8-canary20221030fefe1c0879', | ||||
|       '20.0.0-v8-canary2022102310ff1e5a8d' | ||||
|     ]); | ||||
|     dlSpy.mockImplementation(() => { | ||||
|       throw new Error(errMsg); | ||||
|     }); | ||||
|     await main.run(); | ||||
|  | ||||
|     expect(cnSpy).toHaveBeenCalledWith(`::error::${errMsg}${osm.EOL}`); | ||||
|   }); | ||||
|  | ||||
|   it('acquires specified architecture of node', async () => { | ||||
|     for (const {arch, version, osSpec} of [ | ||||
|       { | ||||
|         arch: 'x86', | ||||
|         version: '20.0.0-v8-canary20221022e83bcb6c41', | ||||
|         osSpec: 'win32' | ||||
|       }, | ||||
|       { | ||||
|         arch: 'x86', | ||||
|         version: '20.0.0-v8-canary20221103f7e2421e91', | ||||
|         osSpec: 'win32' | ||||
|       } | ||||
|     ]) { | ||||
|       os.platform = osSpec; | ||||
|       os.arch = arch; | ||||
|       const fileExtension = os.platform === 'win32' ? '7z' : 'tar.gz'; | ||||
|       const platform = { | ||||
|         linux: 'linux', | ||||
|         darwin: 'darwin', | ||||
|         win32: 'win' | ||||
|       }[os.platform]; | ||||
|  | ||||
|       inputs['node-version'] = version; | ||||
|       inputs['architecture'] = arch; | ||||
|       inputs['always-auth'] = false; | ||||
|       inputs['token'] = 'faketoken'; | ||||
|  | ||||
|       let expectedUrl = `https://nodejs.org/download/v8-canary/v${version}/node-v${version}-${platform}-${arch}.${fileExtension}`; | ||||
|  | ||||
|       // ... but not in the local cache | ||||
|       findSpy.mockImplementation(() => ''); | ||||
|       findAllVersionsSpy.mockImplementation(() => []); | ||||
|  | ||||
|       dlSpy.mockImplementation(async () => '/some/temp/path'); | ||||
|       let toolPath = path.normalize(`/cache/node/${version}/${arch}`); | ||||
|       exSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||
|       cacheSpy.mockImplementation(async () => toolPath); | ||||
|  | ||||
|       await main.run(); | ||||
|       expect(dlSpy).toHaveBeenCalled(); | ||||
|       expect(logSpy).toHaveBeenCalledWith( | ||||
|         `Acquiring ${version} - ${arch} from ${expectedUrl}` | ||||
|       ); | ||||
|     } | ||||
|   }, 100000); | ||||
|  | ||||
|   describe('nightly versions', () => { | ||||
|     it.each([ | ||||
|       [ | ||||
|         '20.0.0-v8-canary', | ||||
|         '20.0.0-v8-canary20221103f7e2421e91', | ||||
|         'https://nodejs.org/download/v8-canary/v20.0.0-v8-canary20221103f7e2421e91/node-v20.0.0-v8-canary20221103f7e2421e91-linux-x64.tar.gz' | ||||
|       ], | ||||
|       [ | ||||
|         '20-v8-canary', | ||||
|         '20.0.0-v8-canary20221103f7e2421e91', | ||||
|         'https://nodejs.org/download/v8-canary/v20.0.0-v8-canary20221103f7e2421e91/node-v20.0.0-v8-canary20221103f7e2421e91-linux-x64.tar.gz' | ||||
|       ], | ||||
|       [ | ||||
|         '19.0.0-v8-canary', | ||||
|         '19.0.0-v8-canary202210187d6960f23f', | ||||
|         'https://nodejs.org/download/v8-canary/v19.0.0-v8-canary202210187d6960f23f/node-v19.0.0-v8-canary202210187d6960f23f-linux-x64.tar.gz' | ||||
|       ], | ||||
|       [ | ||||
|         '19-v8-canary', | ||||
|         '19.0.0-v8-canary202210187d6960f23f', | ||||
|         'https://nodejs.org/download/v8-canary/v19.0.0-v8-canary202210187d6960f23f/node-v19.0.0-v8-canary202210187d6960f23f-linux-x64.tar.gz' | ||||
|       ], | ||||
|       [ | ||||
|         '19.0.0-v8-canary202210187d6960f23f', | ||||
|         '19.0.0-v8-canary202210187d6960f23f', | ||||
|         'https://nodejs.org/download/v8-canary/v19.0.0-v8-canary202210187d6960f23f/node-v19.0.0-v8-canary202210187d6960f23f-linux-x64.tar.gz' | ||||
|       ] | ||||
|     ])( | ||||
|       'finds the versions in the index.json and installs it', | ||||
|       async (input, expectedVersion, expectedUrl) => { | ||||
|         const toolPath = path.normalize(`/cache/node/${expectedVersion}/x64`); | ||||
|  | ||||
|         findSpy.mockImplementation(() => ''); | ||||
|         findAllVersionsSpy.mockImplementation(() => []); | ||||
|         dlSpy.mockImplementation(async () => '/some/temp/path'); | ||||
|         exSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||
|         cacheSpy.mockImplementation(async () => toolPath); | ||||
|  | ||||
|         inputs['node-version'] = input; | ||||
|         os['arch'] = 'x64'; | ||||
|         os['platform'] = 'linux'; | ||||
|         // act | ||||
|         await main.run(); | ||||
|  | ||||
|         // assert | ||||
|         expect(logSpy).toHaveBeenCalledWith( | ||||
|           `Acquiring ${expectedVersion} - ${os.arch} from ${expectedUrl}` | ||||
|         ); | ||||
|         expect(logSpy).toHaveBeenCalledWith('Extracting ...'); | ||||
|         expect(logSpy).toHaveBeenCalledWith('Adding to the cache ...'); | ||||
|         expect(cnSpy).toHaveBeenCalledWith( | ||||
|           `::add-path::${path.join(toolPath, 'bin')}${osm.EOL}` | ||||
|         ); | ||||
|       } | ||||
|     ); | ||||
|  | ||||
|     it.each([ | ||||
|       [ | ||||
|         '20.0.0-v8-canary20221103f7e2421e91', | ||||
|         '20.0.0-v8-canary20221103f7e2421e91' | ||||
|       ], | ||||
|       ['20.0.0-v8-canary', '20.0.0-v8-canary20221103f7e2421e91'], | ||||
|       ['20-v8-canary', '20.0.0-v8-canary20221103f7e2421e91'] | ||||
|     ])( | ||||
|       'finds the %s version in the hostedToolcache', | ||||
|       async (input, expectedVersion) => { | ||||
|         const toolPath = path.normalize(`/cache/node/${expectedVersion}/x64`); | ||||
|         findSpy.mockReturnValue(toolPath); | ||||
|         findAllVersionsSpy.mockReturnValue([ | ||||
|           '20.0.0-v8-canary20221103f7e2421e91', | ||||
|           '20.0.0-v8-canary20221030fefe1c0879', | ||||
|           '19.0.0-v8-canary202210172ec229fc56', | ||||
|           '20.0.0-v8-canary2022102310ff1e5a8d' | ||||
|         ]); | ||||
|  | ||||
|         inputs['node-version'] = input; | ||||
|         os['arch'] = 'x64'; | ||||
|         os['platform'] = 'linux'; | ||||
|  | ||||
|         // act | ||||
|         await main.run(); | ||||
|  | ||||
|         // assert | ||||
|         expect(findAllVersionsSpy).toHaveBeenCalled(); | ||||
|         expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); | ||||
|         expect(cnSpy).toHaveBeenCalledWith( | ||||
|           `::add-path::${path.join(toolPath, 'bin')}${osm.EOL}` | ||||
|         ); | ||||
|       } | ||||
|     ); | ||||
|  | ||||
|     it.each([ | ||||
|       [ | ||||
|         '20.0.0-v8-canary', | ||||
|         '20.0.0-v8-canary20221103f7e2421e91', | ||||
|         '20.0.0-v8-canary20221030fefe1c0879', | ||||
|         'https://nodejs.org/download/v8-canary/v20.0.0-v8-canary20221103f7e2421e91/node-v20.0.0-v8-canary20221103f7e2421e91-linux-x64.tar.gz' | ||||
|       ], | ||||
|       [ | ||||
|         '20-v8-canary', | ||||
|         '20.0.0-v8-canary20221103f7e2421e91', | ||||
|         '20.0.0-v8-canary20221030fefe1c0879', | ||||
|         'https://nodejs.org/download/v8-canary/v20.0.0-v8-canary20221103f7e2421e91/node-v20.0.0-v8-canary20221103f7e2421e91-linux-x64.tar.gz' | ||||
|       ], | ||||
|       [ | ||||
|         '19.0.0-v8-canary', | ||||
|         '19.0.0-v8-canary202210187d6960f23f', | ||||
|         '19.0.0-v8-canary202210172ec229fc56', | ||||
|         'https://nodejs.org/download/v8-canary/v19.0.0-v8-canary202210187d6960f23f/node-v19.0.0-v8-canary202210187d6960f23f-linux-x64.tar.gz' | ||||
|       ], | ||||
|       [ | ||||
|         '19-v8-canary', | ||||
|         '19.0.0-v8-canary202210187d6960f23f', | ||||
|         '19.0.0-v8-canary202210172ec229fc56', | ||||
|         'https://nodejs.org/download/v8-canary/v19.0.0-v8-canary202210187d6960f23f/node-v19.0.0-v8-canary202210187d6960f23f-linux-x64.tar.gz' | ||||
|       ] | ||||
|     ])( | ||||
|       'get %s version from dist if check-latest is true', | ||||
|       async (input, expectedVersion, foundVersion, expectedUrl) => { | ||||
|         const foundToolPath = path.normalize(`/cache/node/${foundVersion}/x64`); | ||||
|         const toolPath = path.normalize(`/cache/node/${expectedVersion}/x64`); | ||||
|  | ||||
|         inputs['node-version'] = input; | ||||
|         inputs['check-latest'] = 'true'; | ||||
|         os['arch'] = 'x64'; | ||||
|         os['platform'] = 'linux'; | ||||
|  | ||||
|         findSpy.mockReturnValue(foundToolPath); | ||||
|         findAllVersionsSpy.mockReturnValue([ | ||||
|           '20.0.0-v8-canary20221030fefe1c0879', | ||||
|           '19.0.0-v8-canary202210172ec229fc56', | ||||
|           '20.0.0-v8-canary2022102310ff1e5a8d' | ||||
|         ]); | ||||
|         dlSpy.mockImplementation(async () => '/some/temp/path'); | ||||
|         exSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||
|         cacheSpy.mockImplementation(async () => toolPath); | ||||
|  | ||||
|         // act | ||||
|         await main.run(); | ||||
|  | ||||
|         // assert | ||||
|         expect(findAllVersionsSpy).toHaveBeenCalled(); | ||||
|         expect(logSpy).toHaveBeenCalledWith( | ||||
|           `Acquiring ${expectedVersion} - ${os.arch} from ${expectedUrl}` | ||||
|         ); | ||||
|         expect(logSpy).toHaveBeenCalledWith('Extracting ...'); | ||||
|         expect(logSpy).toHaveBeenCalledWith('Adding to the cache ...'); | ||||
|         expect(cnSpy).toHaveBeenCalledWith( | ||||
|           `::add-path::${path.join(toolPath, 'bin')}${osm.EOL}` | ||||
|         ); | ||||
|       } | ||||
|     ); | ||||
|   }); | ||||
|  | ||||
|   describe('setup-node v8 canary tests', () => { | ||||
|     it('v8 canary setup node flow with cached', async () => { | ||||
|       let versionSpec = 'v20-v8-canary'; | ||||
|  | ||||
|       inputs['node-version'] = versionSpec; | ||||
|       inputs['always-auth'] = false; | ||||
|       inputs['token'] = 'faketoken'; | ||||
|  | ||||
|       os.platform = 'linux'; | ||||
|       os.arch = 'x64'; | ||||
|  | ||||
|       const versionExpected = 'v20.0.0-v8-canary20221103f7e2421e91'; | ||||
|       findAllVersionsSpy.mockImplementation(() => [versionExpected]); | ||||
|  | ||||
|       const toolPath = path.normalize(`/cache/node/${versionExpected}/x64`); | ||||
|       findSpy.mockImplementation(version => toolPath); | ||||
|  | ||||
|       await main.run(); | ||||
|  | ||||
|       expect(cnSpy).toHaveBeenCalledWith( | ||||
|         `::add-path::${toolPath}${path.sep}bin${osm.EOL}` | ||||
|       ); | ||||
|  | ||||
|       expect(dlSpy).not.toHaveBeenCalled(); | ||||
|       expect(exSpy).not.toHaveBeenCalled(); | ||||
|       expect(cacheSpy).not.toHaveBeenCalled(); | ||||
|     }); | ||||
|   }); | ||||
| }); | ||||
							
								
								
									
										537
									
								
								__tests__/data/v8-canary-dist-index.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										537
									
								
								__tests__/data/v8-canary-dist-index.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,537 @@ | ||||
| [ | ||||
|   { | ||||
|     "version": "v20.0.0-v8-canary20221103f7e2421e91", | ||||
|     "date": "2022-11-03", | ||||
|     "files": [ | ||||
|       "headers", | ||||
|       "linux-arm64", | ||||
|       "linux-armv7l", | ||||
|       "linux-ppc64le", | ||||
|       "linux-s390x", | ||||
|       "linux-x64", | ||||
|       "osx-arm64-tar", | ||||
|       "osx-x64-pkg", | ||||
|       "osx-x64-tar", | ||||
|       "src", | ||||
|       "win-x64-7z", | ||||
|       "win-x64-exe", | ||||
|       "win-x64-msi", | ||||
|       "win-x64-zip", | ||||
|       "win-x86-7z", | ||||
|       "win-x86-exe", | ||||
|       "win-x86-msi", | ||||
|       "win-x86-zip" | ||||
|     ], | ||||
|     "npm": "8.19.2", | ||||
|     "v8": "10.9.138.0", | ||||
|     "uv": "1.43.0", | ||||
|     "zlib": "1.2.11", | ||||
|     "openssl": "3.0.5+quic", | ||||
|     "modules": "112", | ||||
|     "lts": false, | ||||
|     "security": false | ||||
|   }, | ||||
|   { | ||||
|     "version": "v20.0.0-v8-canary202211026bf85d0fb4", | ||||
|     "date": "2022-11-02", | ||||
|     "files": [ | ||||
|       "headers", | ||||
|       "linux-arm64", | ||||
|       "linux-armv7l", | ||||
|       "linux-ppc64le", | ||||
|       "linux-s390x", | ||||
|       "linux-x64", | ||||
|       "osx-arm64-tar", | ||||
|       "osx-x64-pkg", | ||||
|       "osx-x64-tar", | ||||
|       "src", | ||||
|       "win-x64-7z", | ||||
|       "win-x64-exe", | ||||
|       "win-x64-msi", | ||||
|       "win-x64-zip", | ||||
|       "win-x86-7z", | ||||
|       "win-x86-exe", | ||||
|       "win-x86-msi", | ||||
|       "win-x86-zip" | ||||
|     ], | ||||
|     "npm": "8.19.2", | ||||
|     "v8": "10.9.130.0", | ||||
|     "uv": "1.43.0", | ||||
|     "zlib": "1.2.11", | ||||
|     "openssl": "3.0.5+quic", | ||||
|     "modules": "112", | ||||
|     "lts": false, | ||||
|     "security": false | ||||
|   }, | ||||
|   { | ||||
|     "version": "v20.0.0-v8-canary20221101e50e45c9f8", | ||||
|     "date": "2022-11-01", | ||||
|     "files": [ | ||||
|       "headers", | ||||
|       "linux-arm64", | ||||
|       "linux-armv7l", | ||||
|       "linux-ppc64le", | ||||
|       "linux-s390x", | ||||
|       "linux-x64", | ||||
|       "osx-arm64-tar", | ||||
|       "osx-x64-tar", | ||||
|       "src", | ||||
|       "win-x64-7z", | ||||
|       "win-x64-exe", | ||||
|       "win-x64-msi", | ||||
|       "win-x64-zip", | ||||
|       "win-x86-7z", | ||||
|       "win-x86-exe", | ||||
|       "win-x86-msi", | ||||
|       "win-x86-zip" | ||||
|     ], | ||||
|     "npm": "8.19.2", | ||||
|     "v8": "10.9.129.0", | ||||
|     "uv": "1.43.0", | ||||
|     "zlib": "1.2.11", | ||||
|     "openssl": "3.0.5+quic", | ||||
|     "modules": "112", | ||||
|     "lts": false, | ||||
|     "security": false | ||||
|   }, | ||||
|   { | ||||
|     "version": "v20.0.0-v8-canary202210311b1e675ad0", | ||||
|     "date": "2022-10-31", | ||||
|     "files": [ | ||||
|       "headers", | ||||
|       "linux-arm64", | ||||
|       "linux-armv7l", | ||||
|       "linux-ppc64le", | ||||
|       "linux-s390x", | ||||
|       "linux-x64", | ||||
|       "osx-arm64-tar", | ||||
|       "osx-x64-tar", | ||||
|       "src", | ||||
|       "win-x64-7z", | ||||
|       "win-x64-exe", | ||||
|       "win-x64-msi", | ||||
|       "win-x64-zip", | ||||
|       "win-x86-7z", | ||||
|       "win-x86-exe", | ||||
|       "win-x86-msi", | ||||
|       "win-x86-zip" | ||||
|     ], | ||||
|     "npm": "8.19.2", | ||||
|     "v8": "10.9.125.0", | ||||
|     "uv": "1.43.0", | ||||
|     "zlib": "1.2.11", | ||||
|     "openssl": "3.0.5+quic", | ||||
|     "modules": "112", | ||||
|     "lts": false, | ||||
|     "security": false | ||||
|   }, | ||||
|   { | ||||
|     "version": "v20.0.0-v8-canary20221030fefe1c0879", | ||||
|     "date": "2022-10-30", | ||||
|     "files": [ | ||||
|       "headers", | ||||
|       "linux-arm64", | ||||
|       "linux-armv7l", | ||||
|       "linux-ppc64le", | ||||
|       "linux-s390x", | ||||
|       "linux-x64", | ||||
|       "osx-arm64-tar", | ||||
|       "osx-x64-pkg", | ||||
|       "osx-x64-tar", | ||||
|       "src", | ||||
|       "win-x64-7z", | ||||
|       "win-x64-exe", | ||||
|       "win-x64-msi", | ||||
|       "win-x64-zip", | ||||
|       "win-x86-7z", | ||||
|       "win-x86-exe", | ||||
|       "win-x86-msi", | ||||
|       "win-x86-zip" | ||||
|     ], | ||||
|     "npm": "8.19.2", | ||||
|     "v8": "10.9.125.0", | ||||
|     "uv": "1.43.0", | ||||
|     "zlib": "1.2.11", | ||||
|     "openssl": "3.0.5+quic", | ||||
|     "modules": "112", | ||||
|     "lts": false, | ||||
|     "security": false | ||||
|   }, | ||||
|   { | ||||
|     "version": "v20.0.0-v8-canary202210293881e51ba2", | ||||
|     "date": "2022-10-29", | ||||
|     "files": [ | ||||
|       "headers", | ||||
|       "linux-arm64", | ||||
|       "linux-armv7l", | ||||
|       "linux-ppc64le", | ||||
|       "linux-s390x", | ||||
|       "linux-x64", | ||||
|       "osx-arm64-tar", | ||||
|       "osx-x64-pkg", | ||||
|       "osx-x64-tar", | ||||
|       "src", | ||||
|       "win-x64-7z", | ||||
|       "win-x64-exe", | ||||
|       "win-x64-msi", | ||||
|       "win-x64-zip", | ||||
|       "win-x86-7z", | ||||
|       "win-x86-exe", | ||||
|       "win-x86-msi", | ||||
|       "win-x86-zip" | ||||
|     ], | ||||
|     "npm": "8.19.2", | ||||
|     "v8": "10.9.122.0", | ||||
|     "uv": "1.43.0", | ||||
|     "zlib": "1.2.11", | ||||
|     "openssl": "3.0.5+quic", | ||||
|     "modules": "112", | ||||
|     "lts": false, | ||||
|     "security": false | ||||
|   }, | ||||
|   { | ||||
|     "version": "v20.0.0-v8-canary202210286fe49d2a49", | ||||
|     "date": "2022-10-28", | ||||
|     "files": [ | ||||
|       "osx-arm64-tar", | ||||
|       "osx-x64-pkg", | ||||
|       "osx-x64-tar", | ||||
|       "win-x64-7z", | ||||
|       "win-x64-exe", | ||||
|       "win-x64-msi", | ||||
|       "win-x64-zip", | ||||
|       "win-x86-7z", | ||||
|       "win-x86-exe", | ||||
|       "win-x86-msi", | ||||
|       "win-x86-zip" | ||||
|     ], | ||||
|     "npm": "8.19.2", | ||||
|     "v8": "10.9.112.0", | ||||
|     "uv": "1.43.0", | ||||
|     "zlib": "1.2.11", | ||||
|     "openssl": "3.0.5+quic", | ||||
|     "modules": "112", | ||||
|     "lts": false, | ||||
|     "security": false | ||||
|   }, | ||||
|   { | ||||
|     "version": "v20.0.0-v8-canary20221027c470b3108c", | ||||
|     "date": "2022-10-27", | ||||
|     "files": [ | ||||
|       "headers", | ||||
|       "linux-arm64", | ||||
|       "linux-armv7l", | ||||
|       "linux-ppc64le", | ||||
|       "linux-s390x", | ||||
|       "linux-x64", | ||||
|       "osx-arm64-tar", | ||||
|       "osx-x64-pkg", | ||||
|       "osx-x64-tar", | ||||
|       "src", | ||||
|       "win-x64-7z", | ||||
|       "win-x64-exe", | ||||
|       "win-x64-msi", | ||||
|       "win-x64-zip", | ||||
|       "win-x86-7z", | ||||
|       "win-x86-exe", | ||||
|       "win-x86-msi", | ||||
|       "win-x86-zip" | ||||
|     ], | ||||
|     "npm": "8.19.2", | ||||
|     "v8": "10.9.101.0", | ||||
|     "uv": "1.43.0", | ||||
|     "zlib": "1.2.11", | ||||
|     "openssl": "3.0.5+quic", | ||||
|     "modules": "112", | ||||
|     "lts": false, | ||||
|     "security": false | ||||
|   }, | ||||
|   { | ||||
|     "version": "v20.0.0-v8-canary20221026c24f7d1e4a", | ||||
|     "date": "2022-10-26", | ||||
|     "files": [ | ||||
|       "headers", | ||||
|       "linux-arm64", | ||||
|       "linux-armv7l", | ||||
|       "linux-ppc64le", | ||||
|       "linux-s390x", | ||||
|       "linux-x64", | ||||
|       "osx-arm64-tar", | ||||
|       "osx-x64-pkg", | ||||
|       "osx-x64-tar", | ||||
|       "src", | ||||
|       "win-x64-7z", | ||||
|       "win-x64-exe", | ||||
|       "win-x64-msi", | ||||
|       "win-x64-zip", | ||||
|       "win-x86-7z", | ||||
|       "win-x86-exe", | ||||
|       "win-x86-msi", | ||||
|       "win-x86-zip" | ||||
|     ], | ||||
|     "npm": "8.19.2", | ||||
|     "v8": "10.9.88.0", | ||||
|     "uv": "1.43.0", | ||||
|     "zlib": "1.2.11", | ||||
|     "openssl": "3.0.5+quic", | ||||
|     "modules": "112", | ||||
|     "lts": false, | ||||
|     "security": false | ||||
|   }, | ||||
|   { | ||||
|     "version": "v20.0.0-v8-canary20221025b063237e20", | ||||
|     "date": "2022-10-25", | ||||
|     "files": [ | ||||
|       "headers", | ||||
|       "linux-arm64", | ||||
|       "linux-armv7l", | ||||
|       "linux-ppc64le", | ||||
|       "linux-x64", | ||||
|       "osx-arm64-tar", | ||||
|       "osx-x64-pkg", | ||||
|       "osx-x64-tar", | ||||
|       "src", | ||||
|       "win-x64-7z", | ||||
|       "win-x64-exe", | ||||
|       "win-x64-msi", | ||||
|       "win-x64-zip", | ||||
|       "win-x86-7z", | ||||
|       "win-x86-exe", | ||||
|       "win-x86-msi", | ||||
|       "win-x86-zip" | ||||
|     ], | ||||
|     "npm": "8.19.2", | ||||
|     "v8": "10.9.73.0", | ||||
|     "uv": "1.43.0", | ||||
|     "zlib": "1.2.11", | ||||
|     "openssl": "3.0.5+quic", | ||||
|     "modules": "112", | ||||
|     "lts": false, | ||||
|     "security": false | ||||
|   }, | ||||
|   { | ||||
|     "version": "v20.0.0-v8-canary2022102454996f930f", | ||||
|     "date": "2022-10-24", | ||||
|     "files": [ | ||||
|       "headers", | ||||
|       "linux-arm64", | ||||
|       "linux-armv7l", | ||||
|       "linux-ppc64le", | ||||
|       "linux-x64", | ||||
|       "osx-arm64-tar", | ||||
|       "osx-x64-pkg", | ||||
|       "osx-x64-tar", | ||||
|       "src", | ||||
|       "win-x64-7z", | ||||
|       "win-x64-exe", | ||||
|       "win-x64-msi", | ||||
|       "win-x64-zip", | ||||
|       "win-x86-7z", | ||||
|       "win-x86-exe", | ||||
|       "win-x86-msi", | ||||
|       "win-x86-zip" | ||||
|     ], | ||||
|     "npm": "8.19.2", | ||||
|     "v8": "10.9.61.0", | ||||
|     "uv": "1.43.0", | ||||
|     "zlib": "1.2.11", | ||||
|     "openssl": "3.0.5+quic", | ||||
|     "modules": "112", | ||||
|     "lts": false, | ||||
|     "security": false | ||||
|   }, | ||||
|   { | ||||
|     "version": "v20.0.0-v8-canary2022102310ff1e5a8d", | ||||
|     "date": "2022-10-23", | ||||
|     "files": [ | ||||
|       "headers", | ||||
|       "linux-arm64", | ||||
|       "linux-armv7l", | ||||
|       "linux-ppc64le", | ||||
|       "linux-x64", | ||||
|       "osx-arm64-tar", | ||||
|       "osx-x64-tar", | ||||
|       "src", | ||||
|       "win-x64-7z", | ||||
|       "win-x64-exe", | ||||
|       "win-x64-msi", | ||||
|       "win-x64-zip", | ||||
|       "win-x86-7z", | ||||
|       "win-x86-exe", | ||||
|       "win-x86-msi", | ||||
|       "win-x86-zip" | ||||
|     ], | ||||
|     "npm": "8.19.2", | ||||
|     "v8": "10.9.61.0", | ||||
|     "uv": "1.43.0", | ||||
|     "zlib": "1.2.11", | ||||
|     "openssl": "3.0.5+quic", | ||||
|     "modules": "112", | ||||
|     "lts": false, | ||||
|     "security": false | ||||
|   }, | ||||
|   { | ||||
|     "version": "v20.0.0-v8-canary20221022e83bcb6c41", | ||||
|     "date": "2022-10-22", | ||||
|     "files": [ | ||||
|       "headers", | ||||
|       "linux-arm64", | ||||
|       "linux-armv7l", | ||||
|       "linux-x64", | ||||
|       "osx-arm64-tar", | ||||
|       "osx-x64-tar", | ||||
|       "src", | ||||
|       "win-x64-7z", | ||||
|       "win-x64-exe", | ||||
|       "win-x64-msi", | ||||
|       "win-x64-zip", | ||||
|       "win-x86-7z", | ||||
|       "win-x86-exe", | ||||
|       "win-x86-msi", | ||||
|       "win-x86-zip" | ||||
|     ], | ||||
|     "npm": "8.19.2", | ||||
|     "v8": "10.9.60.0", | ||||
|     "uv": "1.43.0", | ||||
|     "zlib": "1.2.11", | ||||
|     "openssl": "3.0.5+quic", | ||||
|     "modules": "112", | ||||
|     "lts": false, | ||||
|     "security": false | ||||
|   }, | ||||
|   { | ||||
|     "version": "v20.0.0-v8-canary20221021f6d5f347fa", | ||||
|     "date": "2022-10-21", | ||||
|     "files": [ | ||||
|       "headers", | ||||
|       "linux-arm64", | ||||
|       "linux-armv7l", | ||||
|       "linux-x64", | ||||
|       "osx-arm64-tar", | ||||
|       "osx-x64-tar", | ||||
|       "src", | ||||
|       "win-x64-7z", | ||||
|       "win-x64-exe", | ||||
|       "win-x64-msi", | ||||
|       "win-x64-zip" | ||||
|     ], | ||||
|     "npm": "8.19.2", | ||||
|     "v8": "10.9.48.0", | ||||
|     "uv": "1.43.0", | ||||
|     "zlib": "1.2.11", | ||||
|     "openssl": "3.0.5+quic", | ||||
|     "modules": "112", | ||||
|     "lts": false, | ||||
|     "security": false | ||||
|   }, | ||||
|   { | ||||
|     "version": "v20.0.0-v8-canary20221020f78c149307", | ||||
|     "date": "2022-10-20", | ||||
|     "files": [ | ||||
|       "headers", | ||||
|       "linux-arm64", | ||||
|       "linux-armv7l", | ||||
|       "linux-x64", | ||||
|       "osx-arm64-tar", | ||||
|       "osx-x64-pkg", | ||||
|       "osx-x64-tar", | ||||
|       "src", | ||||
|       "win-x64-7z", | ||||
|       "win-x64-exe", | ||||
|       "win-x64-msi", | ||||
|       "win-x64-zip" | ||||
|     ], | ||||
|     "npm": "8.19.2", | ||||
|     "v8": "10.9.38.0", | ||||
|     "uv": "1.43.0", | ||||
|     "zlib": "1.2.11", | ||||
|     "openssl": "3.0.5+quic", | ||||
|     "modules": "112", | ||||
|     "lts": false, | ||||
|     "security": false | ||||
|   }, | ||||
|   { | ||||
|     "version": "v20.0.0-v8-canary20221019d52c76f76e", | ||||
|     "date": "2022-10-19", | ||||
|     "files": [ | ||||
|       "aix-ppc64", | ||||
|       "headers", | ||||
|       "linux-arm64", | ||||
|       "linux-armv7l", | ||||
|       "linux-ppc64le", | ||||
|       "linux-x64", | ||||
|       "osx-arm64-tar", | ||||
|       "osx-x64-pkg", | ||||
|       "osx-x64-tar", | ||||
|       "src", | ||||
|       "win-x64-7z", | ||||
|       "win-x64-exe", | ||||
|       "win-x64-msi", | ||||
|       "win-x64-zip" | ||||
|     ], | ||||
|     "npm": "8.19.2", | ||||
|     "v8": "10.9.27.0", | ||||
|     "uv": "1.43.0", | ||||
|     "zlib": "1.2.11", | ||||
|     "openssl": "3.0.5+quic", | ||||
|     "modules": "112", | ||||
|     "lts": false, | ||||
|     "security": false | ||||
|   }, | ||||
|   { | ||||
|     "version": "v19.0.0-v8-canary202210187d6960f23f", | ||||
|     "date": "2022-10-18", | ||||
|     "files": [ | ||||
|       "aix-ppc64", | ||||
|       "headers", | ||||
|       "linux-arm64", | ||||
|       "linux-armv7l", | ||||
|       "linux-ppc64le", | ||||
|       "linux-s390x", | ||||
|       "linux-x64", | ||||
|       "osx-arm64-tar", | ||||
|       "osx-x64-tar", | ||||
|       "src", | ||||
|       "win-x64-7z", | ||||
|       "win-x64-exe", | ||||
|       "win-x64-msi", | ||||
|       "win-x64-zip" | ||||
|     ], | ||||
|     "npm": "8.19.2", | ||||
|     "v8": "10.9.12.0", | ||||
|     "uv": "1.43.0", | ||||
|     "zlib": "1.2.11", | ||||
|     "openssl": "3.0.5+quic", | ||||
|     "modules": "112", | ||||
|     "lts": false, | ||||
|     "security": false | ||||
|   }, | ||||
|   { | ||||
|     "version": "v19.0.0-v8-canary202210172ec229fc56", | ||||
|     "date": "2022-10-17", | ||||
|     "files": [ | ||||
|       "aix-ppc64", | ||||
|       "headers", | ||||
|       "linux-arm64", | ||||
|       "linux-armv7l", | ||||
|       "linux-ppc64le", | ||||
|       "linux-s390x", | ||||
|       "linux-x64", | ||||
|       "osx-arm64-tar", | ||||
|       "osx-x64-tar", | ||||
|       "src", | ||||
|       "win-x64-7z", | ||||
|       "win-x64-exe", | ||||
|       "win-x64-msi", | ||||
|       "win-x64-zip" | ||||
|     ], | ||||
|     "npm": "8.19.2", | ||||
|     "v8": "10.9.6.0", | ||||
|     "uv": "1.43.0", | ||||
|     "zlib": "1.2.11", | ||||
|     "openssl": "3.0.5+quic", | ||||
|     "modules": "112", | ||||
|     "lts": false, | ||||
|     "security": false | ||||
|   } | ||||
| ] | ||||
							
								
								
									
										303
									
								
								__tests__/main.test.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										303
									
								
								__tests__/main.test.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,303 @@ | ||||
| import * as core from '@actions/core'; | ||||
| import * as exec from '@actions/exec'; | ||||
| import * as tc from '@actions/tool-cache'; | ||||
| import * as cache from '@actions/cache'; | ||||
|  | ||||
| import fs from 'fs'; | ||||
| import path from 'path'; | ||||
| import osm from 'os'; | ||||
|  | ||||
| import each from 'jest-each'; | ||||
|  | ||||
| import * as main from '../src/main'; | ||||
| import * as util from '../src/util'; | ||||
| import OfficialBuilds from '../src/distributions/official_builds/official_builds'; | ||||
|  | ||||
| describe('main tests', () => { | ||||
|   let inputs = {} as any; | ||||
|   let os = {} as any; | ||||
|  | ||||
|   let infoSpy: jest.SpyInstance; | ||||
|   let warningSpy: jest.SpyInstance; | ||||
|   let inSpy: jest.SpyInstance; | ||||
|   let setOutputSpy: jest.SpyInstance; | ||||
|   let startGroupSpy: jest.SpyInstance; | ||||
|   let endGroupSpy: jest.SpyInstance; | ||||
|  | ||||
|   let existsSpy: jest.SpyInstance; | ||||
|  | ||||
|   let getExecOutputSpy: jest.SpyInstance; | ||||
|  | ||||
|   let parseNodeVersionSpy: jest.SpyInstance; | ||||
|   let cnSpy: jest.SpyInstance; | ||||
|   let findSpy: jest.SpyInstance; | ||||
|   let isCacheActionAvailable: jest.SpyInstance; | ||||
|  | ||||
|   let setupNodeJsSpy: jest.SpyInstance; | ||||
|  | ||||
|   beforeEach(() => { | ||||
|     inputs = {}; | ||||
|  | ||||
|     // node | ||||
|     os = {}; | ||||
|     console.log('::stop-commands::stoptoken'); | ||||
|     process.env['GITHUB_PATH'] = ''; // Stub out ENV file functionality so we can verify it writes to standard out | ||||
|     process.env['GITHUB_OUTPUT'] = ''; // Stub out ENV file functionality so we can verify it writes to standard out | ||||
|     infoSpy = jest.spyOn(core, 'info'); | ||||
|     infoSpy.mockImplementation(() => {}); | ||||
|     setOutputSpy = jest.spyOn(core, 'setOutput'); | ||||
|     setOutputSpy.mockImplementation(() => {}); | ||||
|     warningSpy = jest.spyOn(core, 'warning'); | ||||
|     warningSpy.mockImplementation(() => {}); | ||||
|     startGroupSpy = jest.spyOn(core, 'startGroup'); | ||||
|     startGroupSpy.mockImplementation(() => {}); | ||||
|     endGroupSpy = jest.spyOn(core, 'endGroup'); | ||||
|     endGroupSpy.mockImplementation(() => {}); | ||||
|     inSpy = jest.spyOn(core, 'getInput'); | ||||
|     inSpy.mockImplementation(name => inputs[name]); | ||||
|  | ||||
|     getExecOutputSpy = jest.spyOn(exec, 'getExecOutput'); | ||||
|  | ||||
|     findSpy = jest.spyOn(tc, 'find'); | ||||
|  | ||||
|     isCacheActionAvailable = jest.spyOn(cache, 'isFeatureAvailable'); | ||||
|  | ||||
|     existsSpy = jest.spyOn(fs, 'existsSync'); | ||||
|  | ||||
|     cnSpy = jest.spyOn(process.stdout, 'write'); | ||||
|     cnSpy.mockImplementation(line => { | ||||
|       // uncomment to debug | ||||
|       // process.stderr.write('write:' + line + '\n'); | ||||
|     }); | ||||
|  | ||||
|     setupNodeJsSpy = jest.spyOn(OfficialBuilds.prototype, 'setupNodeJs'); | ||||
|     setupNodeJsSpy.mockImplementation(() => {}); | ||||
|   }); | ||||
|  | ||||
|   afterEach(() => { | ||||
|     jest.resetAllMocks(); | ||||
|     jest.clearAllMocks(); | ||||
|     //jest.restoreAllMocks(); | ||||
|   }); | ||||
|  | ||||
|   afterAll(async () => { | ||||
|     console.log('::stoptoken::'); | ||||
|     jest.restoreAllMocks(); | ||||
|   }, 100000); | ||||
|  | ||||
|   describe('parseNodeVersionFile', () => { | ||||
|     each` | ||||
|       contents                                     | expected | ||||
|       ${'12'}                                      | ${'12'} | ||||
|       ${'12.3'}                                    | ${'12.3'} | ||||
|       ${'12.3.4'}                                  | ${'12.3.4'} | ||||
|       ${'v12.3.4'}                                 | ${'12.3.4'} | ||||
|       ${'lts/erbium'}                              | ${'lts/erbium'} | ||||
|       ${'lts/*'}                                   | ${'lts/*'} | ||||
|       ${'nodejs 12.3.4'}                           | ${'12.3.4'} | ||||
|       ${'ruby 2.3.4\nnodejs 12.3.4\npython 3.4.5'} | ${'12.3.4'} | ||||
|       ${''}                                        | ${''} | ||||
|       ${'unknown format'}                          | ${'unknown format'} | ||||
|       ${'  14.1.0  '}                              | ${'14.1.0'} | ||||
|       ${'{"volta": {"node": ">=14.0.0 <=17.0.0"}}'}| ${'>=14.0.0 <=17.0.0'} | ||||
|       ${'{"engines": {"node": "17.0.0"}}'}         | ${'17.0.0'} | ||||
|     `.it('parses "$contents"', ({contents, expected}) => { | ||||
|       expect(util.parseNodeVersionFile(contents)).toBe(expected); | ||||
|     }); | ||||
|   }); | ||||
|  | ||||
|   describe('printEnvDetailsAndSetOutput', () => { | ||||
|     it.each([ | ||||
|       [{node: '12.0.2', npm: '6.3.3', yarn: '1.22.11'}], | ||||
|       [{node: '16.0.2', npm: '7.3.3', yarn: '2.22.11'}], | ||||
|       [{node: '14.0.1', npm: '8.1.0', yarn: '3.2.1'}], | ||||
|       [{node: '17.0.2', npm: '6.3.3', yarn: ''}] | ||||
|     ])('Tools versions %p', async obj => { | ||||
|       getExecOutputSpy.mockImplementation(async command => { | ||||
|         if (Reflect.has(obj, command) && !obj[command]) { | ||||
|           return { | ||||
|             stdout: '', | ||||
|             stderr: `${command} does not exist`, | ||||
|             exitCode: 1 | ||||
|           }; | ||||
|         } | ||||
|  | ||||
|         return {stdout: obj[command], stderr: '', exitCode: 0}; | ||||
|       }); | ||||
|  | ||||
|       await util.printEnvDetailsAndSetOutput(); | ||||
|  | ||||
|       expect(setOutputSpy).toHaveBeenCalledWith('node-version', obj['node']); | ||||
|       Object.getOwnPropertyNames(obj).forEach(name => { | ||||
|         if (!obj[name]) { | ||||
|           expect(infoSpy).toHaveBeenCalledWith( | ||||
|             `[warning]${name} does not exist` | ||||
|           ); | ||||
|         } | ||||
|         expect(infoSpy).toHaveBeenCalledWith(`${name}: ${obj[name]}`); | ||||
|       }); | ||||
|     }); | ||||
|   }); | ||||
|  | ||||
|   describe('node-version-file flag', () => { | ||||
|     beforeEach(() => { | ||||
|       parseNodeVersionSpy = jest.spyOn(util, 'parseNodeVersionFile'); | ||||
|     }); | ||||
|  | ||||
|     it('not used if node-version is provided', async () => { | ||||
|       // Arrange | ||||
|       inputs['node-version'] = '12'; | ||||
|  | ||||
|       // Act | ||||
|       await main.run(); | ||||
|  | ||||
|       // Assert | ||||
|       expect(parseNodeVersionSpy).toHaveBeenCalledTimes(0); | ||||
|     }, 10000); | ||||
|  | ||||
|     it('not used if node-version-file not provided', async () => { | ||||
|       // Act | ||||
|       await main.run(); | ||||
|  | ||||
|       // Assert | ||||
|       expect(parseNodeVersionSpy).toHaveBeenCalledTimes(0); | ||||
|     }); | ||||
|  | ||||
|     it('reads node-version-file if provided', async () => { | ||||
|       // Arrange | ||||
|       const versionSpec = 'v14'; | ||||
|       const versionFile = '.nvmrc'; | ||||
|       const expectedVersionSpec = '14'; | ||||
|       process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data'); | ||||
|       inputs['node-version-file'] = versionFile; | ||||
|  | ||||
|       parseNodeVersionSpy.mockImplementation(() => expectedVersionSpec); | ||||
|       existsSpy.mockImplementationOnce( | ||||
|         input => input === path.join(__dirname, 'data', versionFile) | ||||
|       ); | ||||
|  | ||||
|       // Act | ||||
|       await main.run(); | ||||
|  | ||||
|       // Assert | ||||
|       expect(existsSpy).toHaveBeenCalledTimes(1); | ||||
|       expect(existsSpy).toHaveReturnedWith(true); | ||||
|       expect(parseNodeVersionSpy).toHaveBeenCalledWith(versionSpec); | ||||
|       expect(infoSpy).toHaveBeenCalledWith( | ||||
|         `Resolved ${versionFile} as ${expectedVersionSpec}` | ||||
|       ); | ||||
|     }, 10000); | ||||
|  | ||||
|     it('reads package.json as node-version-file if provided', async () => { | ||||
|       // Arrange | ||||
|       const versionSpec = fs.readFileSync( | ||||
|         path.join(__dirname, 'data/package.json'), | ||||
|         'utf-8' | ||||
|       ); | ||||
|       const versionFile = 'package.json'; | ||||
|       const expectedVersionSpec = '14'; | ||||
|       process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data'); | ||||
|       inputs['node-version-file'] = versionFile; | ||||
|  | ||||
|       parseNodeVersionSpy.mockImplementation(() => expectedVersionSpec); | ||||
|       existsSpy.mockImplementationOnce( | ||||
|         input => input === path.join(__dirname, 'data', versionFile) | ||||
|       ); | ||||
|       // Act | ||||
|       await main.run(); | ||||
|  | ||||
|       // Assert | ||||
|       expect(existsSpy).toHaveBeenCalledTimes(1); | ||||
|       expect(existsSpy).toHaveReturnedWith(true); | ||||
|       expect(parseNodeVersionSpy).toHaveBeenCalledWith(versionSpec); | ||||
|       expect(infoSpy).toHaveBeenCalledWith( | ||||
|         `Resolved ${versionFile} as ${expectedVersionSpec}` | ||||
|       ); | ||||
|     }, 10000); | ||||
|  | ||||
|     it('both node-version-file and node-version are provided', async () => { | ||||
|       inputs['node-version'] = '12'; | ||||
|       const versionSpec = 'v14'; | ||||
|       const versionFile = '.nvmrc'; | ||||
|       const expectedVersionSpec = '14'; | ||||
|       process.env['GITHUB_WORKSPACE'] = path.join(__dirname, '..'); | ||||
|       inputs['node-version-file'] = versionFile; | ||||
|  | ||||
|       parseNodeVersionSpy.mockImplementation(() => expectedVersionSpec); | ||||
|  | ||||
|       // Act | ||||
|       await main.run(); | ||||
|  | ||||
|       // Assert | ||||
|       expect(existsSpy).toHaveBeenCalledTimes(0); | ||||
|       expect(parseNodeVersionSpy).not.toHaveBeenCalled(); | ||||
|       expect(warningSpy).toHaveBeenCalledWith( | ||||
|         'Both node-version and node-version-file inputs are specified, only node-version will be used' | ||||
|       ); | ||||
|     }); | ||||
|  | ||||
|     it('should throw an error if node-version-file is not found', async () => { | ||||
|       const versionFile = '.nvmrc'; | ||||
|       const versionFilePath = path.join(__dirname, '..', versionFile); | ||||
|       inputs['node-version-file'] = versionFile; | ||||
|  | ||||
|       inSpy.mockImplementation(name => inputs[name]); | ||||
|       existsSpy.mockImplementationOnce( | ||||
|         input => input === path.join(__dirname, 'data', versionFile) | ||||
|       ); | ||||
|  | ||||
|       // Act | ||||
|       await main.run(); | ||||
|  | ||||
|       // Assert | ||||
|       expect(existsSpy).toHaveBeenCalled(); | ||||
|       expect(existsSpy).toHaveReturnedWith(false); | ||||
|       expect(parseNodeVersionSpy).not.toHaveBeenCalled(); | ||||
|       expect(cnSpy).toHaveBeenCalledWith( | ||||
|         `::error::The specified node version file at: ${versionFilePath} does not exist${osm.EOL}` | ||||
|       ); | ||||
|     }); | ||||
|   }); | ||||
|  | ||||
|   describe('cache on GHES', () => { | ||||
|     it('Should throw an error, because cache is not supported', async () => { | ||||
|       inputs['node-version'] = '12'; | ||||
|       inputs['cache'] = 'npm'; | ||||
|  | ||||
|       inSpy.mockImplementation(name => inputs[name]); | ||||
|  | ||||
|       let toolPath = path.normalize('/cache/node/12.16.1/x64'); | ||||
|       findSpy.mockImplementation(() => toolPath); | ||||
|  | ||||
|       // expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); | ||||
|       process.env['GITHUB_SERVER_URL'] = 'https://www.test.com'; | ||||
|       isCacheActionAvailable.mockImplementation(() => false); | ||||
|  | ||||
|       await main.run(); | ||||
|  | ||||
|       expect(warningSpy).toHaveBeenCalledWith( | ||||
|         `Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.` | ||||
|       ); | ||||
|     }); | ||||
|  | ||||
|     it('Should throw an internal error', async () => { | ||||
|       inputs['node-version'] = '12'; | ||||
|       inputs['cache'] = 'npm'; | ||||
|  | ||||
|       inSpy.mockImplementation(name => inputs[name]); | ||||
|  | ||||
|       let toolPath = path.normalize('/cache/node/12.16.1/x64'); | ||||
|       findSpy.mockImplementation(() => toolPath); | ||||
|  | ||||
|       // expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); | ||||
|       process.env['GITHUB_SERVER_URL'] = ''; | ||||
|       isCacheActionAvailable.mockImplementation(() => false); | ||||
|  | ||||
|       await main.run(); | ||||
|  | ||||
|       expect(warningSpy).toHaveBeenCalledWith( | ||||
|         'The runner was not able to contact the cache service. Caching will be skipped' | ||||
|       ); | ||||
|     }); | ||||
|   }); | ||||
| }); | ||||
							
								
								
									
										517
									
								
								__tests__/nightly-installer.test.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										517
									
								
								__tests__/nightly-installer.test.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,517 @@ | ||||
| import * as core from '@actions/core'; | ||||
| import * as io from '@actions/io'; | ||||
| import * as tc from '@actions/tool-cache'; | ||||
| import * as httpm from '@actions/http-client'; | ||||
| import * as exec from '@actions/exec'; | ||||
| import * as cache from '@actions/cache'; | ||||
| import fs from 'fs'; | ||||
| import cp from 'child_process'; | ||||
| import osm from 'os'; | ||||
| import path from 'path'; | ||||
| import * as main from '../src/main'; | ||||
| import * as auth from '../src/authutil'; | ||||
| import {INodeVersion} from '../src/distributions/base-models'; | ||||
|  | ||||
| const nodeTestManifest = require('./data/versions-manifest.json'); | ||||
| const nodeTestDist = require('./data/node-dist-index.json'); | ||||
| const nodeTestDistNightly = require('./data/node-nightly-index.json'); | ||||
| const nodeTestDistRc = require('./data/node-rc-index.json'); | ||||
| const nodeV8CanaryTestDist = require('./data/v8-canary-dist-index.json'); | ||||
|  | ||||
| describe('setup-node', () => { | ||||
|   let inputs = {} as any; | ||||
|   let os = {} as any; | ||||
|  | ||||
|   let inSpy: jest.SpyInstance; | ||||
|   let findSpy: jest.SpyInstance; | ||||
|   let findAllVersionsSpy: jest.SpyInstance; | ||||
|   let cnSpy: jest.SpyInstance; | ||||
|   let logSpy: jest.SpyInstance; | ||||
|   let warningSpy: jest.SpyInstance; | ||||
|   let getManifestSpy: jest.SpyInstance; | ||||
|   let getDistSpy: jest.SpyInstance; | ||||
|   let platSpy: jest.SpyInstance; | ||||
|   let archSpy: jest.SpyInstance; | ||||
|   let dlSpy: jest.SpyInstance; | ||||
|   let exSpy: jest.SpyInstance; | ||||
|   let cacheSpy: jest.SpyInstance; | ||||
|   let dbgSpy: jest.SpyInstance; | ||||
|   let whichSpy: jest.SpyInstance; | ||||
|   let existsSpy: jest.SpyInstance; | ||||
|   let mkdirpSpy: jest.SpyInstance; | ||||
|   let execSpy: jest.SpyInstance; | ||||
|   let authSpy: jest.SpyInstance; | ||||
|   let parseNodeVersionSpy: jest.SpyInstance; | ||||
|   let isCacheActionAvailable: jest.SpyInstance; | ||||
|   let getExecOutputSpy: jest.SpyInstance; | ||||
|   let getJsonSpy: jest.SpyInstance; | ||||
|  | ||||
|   beforeEach(() => { | ||||
|     // @actions/core | ||||
|     console.log('::stop-commands::stoptoken'); // Disable executing of runner commands when running tests in actions | ||||
|     process.env['GITHUB_PATH'] = ''; // Stub out ENV file functionality so we can verify it writes to standard out | ||||
|     process.env['GITHUB_OUTPUT'] = ''; // Stub out ENV file functionality so we can verify it writes to standard out | ||||
|     inputs = {}; | ||||
|     inSpy = jest.spyOn(core, 'getInput'); | ||||
|     inSpy.mockImplementation(name => inputs[name]); | ||||
|  | ||||
|     // node | ||||
|     os = {}; | ||||
|     platSpy = jest.spyOn(osm, 'platform'); | ||||
|     platSpy.mockImplementation(() => os['platform']); | ||||
|     archSpy = jest.spyOn(osm, 'arch'); | ||||
|     archSpy.mockImplementation(() => os['arch']); | ||||
|     execSpy = jest.spyOn(cp, 'execSync'); | ||||
|  | ||||
|     // @actions/tool-cache | ||||
|     findSpy = jest.spyOn(tc, 'find'); | ||||
|     findAllVersionsSpy = jest.spyOn(tc, 'findAllVersions'); | ||||
|     dlSpy = jest.spyOn(tc, 'downloadTool'); | ||||
|     exSpy = jest.spyOn(tc, 'extractTar'); | ||||
|     cacheSpy = jest.spyOn(tc, 'cacheDir'); | ||||
|     getManifestSpy = jest.spyOn(tc, 'getManifestFromRepo'); | ||||
|  | ||||
|     // http-client | ||||
|     getJsonSpy = jest.spyOn(httpm.HttpClient.prototype, 'getJson'); | ||||
|  | ||||
|     // io | ||||
|     whichSpy = jest.spyOn(io, 'which'); | ||||
|     existsSpy = jest.spyOn(fs, 'existsSync'); | ||||
|     mkdirpSpy = jest.spyOn(io, 'mkdirP'); | ||||
|  | ||||
|     // @actions/tool-cache | ||||
|     isCacheActionAvailable = jest.spyOn(cache, 'isFeatureAvailable'); | ||||
|  | ||||
|     // disable authentication portion for installer tests | ||||
|     authSpy = jest.spyOn(auth, 'configAuthentication'); | ||||
|     authSpy.mockImplementation(() => {}); | ||||
|  | ||||
|     getJsonSpy.mockImplementation(url => { | ||||
|       let res: any; | ||||
|       if (url.includes('/rc')) { | ||||
|         res = <INodeVersion>nodeTestDistRc; | ||||
|       } else if (url.includes('/nightly')) { | ||||
|         res = <INodeVersion>nodeTestDistNightly; | ||||
|       } else { | ||||
|         res = <INodeVersion>nodeTestDist; | ||||
|       } | ||||
|  | ||||
|       return {result: res}; | ||||
|     }); | ||||
|  | ||||
|     // writes | ||||
|     cnSpy = jest.spyOn(process.stdout, 'write'); | ||||
|     logSpy = jest.spyOn(core, 'info'); | ||||
|     dbgSpy = jest.spyOn(core, 'debug'); | ||||
|     warningSpy = jest.spyOn(core, 'warning'); | ||||
|     cnSpy.mockImplementation(line => { | ||||
|       // uncomment to debug | ||||
|       // process.stderr.write('write:' + line + '\n'); | ||||
|     }); | ||||
|     logSpy.mockImplementation(line => { | ||||
|       // uncomment to debug | ||||
|       // process.stderr.write('log:' + line + '\n'); | ||||
|     }); | ||||
|     dbgSpy.mockImplementation(msg => { | ||||
|       // uncomment to see debug output | ||||
|       // process.stderr.write(msg + '\n'); | ||||
|     }); | ||||
|     warningSpy.mockImplementation(msg => { | ||||
|       // uncomment to debug | ||||
|       // process.stderr.write('log:' + msg + '\n'); | ||||
|     }); | ||||
|  | ||||
|     // @actions/exec | ||||
|     getExecOutputSpy = jest.spyOn(exec, 'getExecOutput'); | ||||
|     getExecOutputSpy.mockImplementation(() => 'v16.15.0'); | ||||
|   }); | ||||
|  | ||||
|   afterEach(() => { | ||||
|     jest.resetAllMocks(); | ||||
|     jest.clearAllMocks(); | ||||
|     //jest.restoreAllMocks(); | ||||
|   }); | ||||
|  | ||||
|   afterAll(async () => { | ||||
|     console.log('::stoptoken::'); // Re-enable executing of runner commands when running tests in actions | ||||
|     jest.restoreAllMocks(); | ||||
|   }, 100000); | ||||
|  | ||||
|   //-------------------------------------------------- | ||||
|   // Found in cache tests | ||||
|   //-------------------------------------------------- | ||||
|  | ||||
|   it('finds version in cache with stable true', async () => { | ||||
|     inputs['node-version'] = '16-nightly'; | ||||
|     os['arch'] = 'x64'; | ||||
|     inputs.stable = 'true'; | ||||
|  | ||||
|     let toolPath = path.normalize( | ||||
|       '/cache/node/16.0.0-nightly20210417bc31dc0e0f/x64' | ||||
|     ); | ||||
|     findSpy.mockImplementation(() => toolPath); | ||||
|     findAllVersionsSpy.mockImplementation(() => [ | ||||
|       '12.0.1', | ||||
|       '16.0.0-nightly20210415c3a5e15ebe', | ||||
|       '16.0.0-nightly20210417bc31dc0e0f', | ||||
|       '16.1.3' | ||||
|     ]); | ||||
|  | ||||
|     await main.run(); | ||||
|  | ||||
|     expect(findSpy).toHaveBeenCalledWith( | ||||
|       'node', | ||||
|       '16.0.0-nightly20210417bc31dc0e0f', | ||||
|       'x64' | ||||
|     ); | ||||
|     expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); | ||||
|   }); | ||||
|  | ||||
|   it('finds version in cache with stable false', async () => { | ||||
|     inputs['node-version'] = '16.0.0-nightly20210415c3a5e15ebe'; | ||||
|     os['arch'] = 'x64'; | ||||
|     inputs.stable = 'false'; | ||||
|  | ||||
|     let toolPath = path.normalize( | ||||
|       '/cache/node/16.0.0-nightly20210415c3a5e15ebe/x64' | ||||
|     ); | ||||
|     findSpy.mockImplementation(() => toolPath); | ||||
|     findAllVersionsSpy.mockImplementation(() => [ | ||||
|       '12.0.1', | ||||
|       '16.0.0-nightly20210415c3a5e15ebe', | ||||
|       '16.0.0-nightly20210417bc31dc0e0f', | ||||
|       '16.1.3' | ||||
|     ]); | ||||
|  | ||||
|     await main.run(); | ||||
|  | ||||
|     expect(findSpy).toHaveBeenCalledWith( | ||||
|       'node', | ||||
|       '16.0.0-nightly20210415c3a5e15ebe', | ||||
|       'x64' | ||||
|     ); | ||||
|     expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); | ||||
|   }); | ||||
|  | ||||
|   it('finds version in cache and adds it to the path', async () => { | ||||
|     inputs['node-version'] = '16-nightly'; | ||||
|     os['arch'] = 'x64'; | ||||
|  | ||||
|     inSpy.mockImplementation(name => inputs[name]); | ||||
|  | ||||
|     let toolPath = path.normalize( | ||||
|       '/cache/node/16.0.0-nightly20210417bc31dc0e0f/x64' | ||||
|     ); | ||||
|     findSpy.mockImplementation(() => toolPath); | ||||
|     findAllVersionsSpy.mockImplementation(() => [ | ||||
|       '12.0.1', | ||||
|       '16.0.0-nightly20210415c3a5e15ebe', | ||||
|       '16.0.0-nightly20210417bc31dc0e0f', | ||||
|       '16.1.3' | ||||
|     ]); | ||||
|  | ||||
|     await main.run(); | ||||
|  | ||||
|     expect(findSpy).toHaveBeenCalledWith( | ||||
|       'node', | ||||
|       '16.0.0-nightly20210417bc31dc0e0f', | ||||
|       'x64' | ||||
|     ); | ||||
|  | ||||
|     let expPath = path.join(toolPath, 'bin'); | ||||
|     expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`); | ||||
|   }); | ||||
|  | ||||
|   it('handles unhandled find error and reports error', async () => { | ||||
|     let errMsg = 'unhandled error message'; | ||||
|     inputs['node-version'] = '16.0.0-nightly20210417bc31dc0e0f'; | ||||
|  | ||||
|     findAllVersionsSpy.mockImplementation(() => [ | ||||
|       '12.0.1', | ||||
|       '16.0.0-nightly20210415c3a5e15ebe', | ||||
|       '16.0.0-nightly20210417bc31dc0e0f', | ||||
|       '16.1.3' | ||||
|     ]); | ||||
|  | ||||
|     findSpy.mockImplementation(() => { | ||||
|       throw new Error(errMsg); | ||||
|     }); | ||||
|  | ||||
|     await main.run(); | ||||
|  | ||||
|     expect(cnSpy).toHaveBeenCalledWith('::error::' + errMsg + osm.EOL); | ||||
|   }); | ||||
|  | ||||
|   it('falls back to a version from node dist', async () => { | ||||
|     os.platform = 'linux'; | ||||
|     os.arch = 'x64'; | ||||
|  | ||||
|     // a version which is not in the manifest but is in node dist | ||||
|     let versionSpec = '13.13.1-nightly20200415947ddec091'; | ||||
|  | ||||
|     inputs['node-version'] = versionSpec; | ||||
|     inputs['always-auth'] = false; | ||||
|     inputs['token'] = 'faketoken'; | ||||
|  | ||||
|     // ... but not in the local cache | ||||
|     findSpy.mockImplementation(() => ''); | ||||
|     findAllVersionsSpy.mockImplementation(() => []); | ||||
|  | ||||
|     dlSpy.mockImplementation(async () => '/some/temp/path'); | ||||
|     let toolPath = path.normalize( | ||||
|       '/cache/node/13.13.1-nightly20200415947ddec091/x64' | ||||
|     ); | ||||
|     exSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||
|     cacheSpy.mockImplementation(async () => toolPath); | ||||
|  | ||||
|     await main.run(); | ||||
|  | ||||
|     let expPath = path.join(toolPath, 'bin'); | ||||
|  | ||||
|     expect(dlSpy).toHaveBeenCalled(); | ||||
|     expect(exSpy).toHaveBeenCalled(); | ||||
|     expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`); | ||||
|   }); | ||||
|  | ||||
|   it('does not find a version that does not exist', async () => { | ||||
|     os.platform = 'linux'; | ||||
|     os.arch = 'x64'; | ||||
|  | ||||
|     let versionSpec = '10.13.1-nightly20200415947ddec091'; | ||||
|     inputs['node-version'] = versionSpec; | ||||
|  | ||||
|     findSpy.mockImplementation(() => ''); | ||||
|     findAllVersionsSpy.mockImplementation(() => []); | ||||
|     await main.run(); | ||||
|  | ||||
|     expect(cnSpy).toHaveBeenCalledWith( | ||||
|       `::error::Unable to find Node version '${versionSpec}' for platform ${os.platform} and architecture ${os.arch}.${osm.EOL}` | ||||
|     ); | ||||
|   }); | ||||
|  | ||||
|   it('reports a failed download', async () => { | ||||
|     let errMsg = 'unhandled download message'; | ||||
|     os.platform = 'linux'; | ||||
|     os.arch = 'x64'; | ||||
|  | ||||
|     // a version which is in the manifest | ||||
|     let versionSpec = '18.0.0-nightly202204180699150267'; | ||||
|  | ||||
|     inputs['node-version'] = versionSpec; | ||||
|     inputs['always-auth'] = false; | ||||
|     inputs['token'] = 'faketoken'; | ||||
|  | ||||
|     findSpy.mockImplementation(() => ''); | ||||
|     findAllVersionsSpy.mockImplementation(() => []); | ||||
|  | ||||
|     dlSpy.mockImplementation(() => { | ||||
|       throw new Error(errMsg); | ||||
|     }); | ||||
|     await main.run(); | ||||
|  | ||||
|     expect(cnSpy).toHaveBeenCalledWith(`::error::${errMsg}${osm.EOL}`); | ||||
|   }); | ||||
|  | ||||
|   it('acquires specified architecture of node', async () => { | ||||
|     for (const {arch, version, osSpec} of [ | ||||
|       { | ||||
|         arch: 'x86', | ||||
|         version: '18.0.0-nightly202110204cb3e06ed8', | ||||
|         osSpec: 'win32' | ||||
|       }, | ||||
|       { | ||||
|         arch: 'x86', | ||||
|         version: '20.0.0-nightly2022101987cdf7d412', | ||||
|         osSpec: 'win32' | ||||
|       } | ||||
|     ]) { | ||||
|       os.platform = osSpec; | ||||
|       os.arch = arch; | ||||
|       const fileExtension = os.platform === 'win32' ? '7z' : 'tar.gz'; | ||||
|       const platform = { | ||||
|         linux: 'linux', | ||||
|         darwin: 'darwin', | ||||
|         win32: 'win' | ||||
|       }[os.platform]; | ||||
|  | ||||
|       inputs['node-version'] = version; | ||||
|       inputs['architecture'] = arch; | ||||
|       inputs['always-auth'] = false; | ||||
|       inputs['token'] = 'faketoken'; | ||||
|  | ||||
|       let expectedUrl = `https://nodejs.org/download/nightly/v${version}/node-v${version}-${platform}-${arch}.${fileExtension}`; | ||||
|  | ||||
|       // ... but not in the local cache | ||||
|       findSpy.mockImplementation(() => ''); | ||||
|       findAllVersionsSpy.mockImplementation(() => []); | ||||
|  | ||||
|       dlSpy.mockImplementation(async () => '/some/temp/path'); | ||||
|       let toolPath = path.normalize(`/cache/node/${version}/${arch}`); | ||||
|       exSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||
|       cacheSpy.mockImplementation(async () => toolPath); | ||||
|  | ||||
|       await main.run(); | ||||
|       expect(dlSpy).toHaveBeenCalled(); | ||||
|       expect(logSpy).toHaveBeenCalledWith( | ||||
|         `Acquiring ${version} - ${arch} from ${expectedUrl}` | ||||
|       ); | ||||
|     } | ||||
|   }, 100000); | ||||
|  | ||||
|   describe('nightly versions', () => { | ||||
|     it.each([ | ||||
|       [ | ||||
|         '17.5.0-nightly', | ||||
|         '17.5.0-nightly20220209e43808936a', | ||||
|         'https://nodejs.org/download/nightly/v17.5.0-nightly20220209e43808936a/node-v17.5.0-nightly20220209e43808936a-linux-x64.tar.gz' | ||||
|       ], | ||||
|       [ | ||||
|         '17-nightly', | ||||
|         '17.5.0-nightly20220209e43808936a', | ||||
|         'https://nodejs.org/download/nightly/v17.5.0-nightly20220209e43808936a/node-v17.5.0-nightly20220209e43808936a-linux-x64.tar.gz' | ||||
|       ], | ||||
|       [ | ||||
|         '18.0.0-nightly', | ||||
|         '18.0.0-nightly20220419bde889bd4e', | ||||
|         'https://nodejs.org/download/nightly/v18.0.0-nightly20220419bde889bd4e/node-v18.0.0-nightly20220419bde889bd4e-linux-x64.tar.gz' | ||||
|       ], | ||||
|       [ | ||||
|         '18-nightly', | ||||
|         '18.0.0-nightly20220419bde889bd4e', | ||||
|         'https://nodejs.org/download/nightly/v18.0.0-nightly20220419bde889bd4e/node-v18.0.0-nightly20220419bde889bd4e-linux-x64.tar.gz' | ||||
|       ], | ||||
|       [ | ||||
|         '20.0.0-nightly', | ||||
|         '20.0.0-nightly2022101987cdf7d412', | ||||
|         'https://nodejs.org/download/nightly/v20.0.0-nightly2022101987cdf7d412/node-v20.0.0-nightly2022101987cdf7d412-linux-x64.tar.gz' | ||||
|       ] | ||||
|     ])( | ||||
|       'finds the versions in the index.json and installs it', | ||||
|       async (input, expectedVersion, expectedUrl) => { | ||||
|         const toolPath = path.normalize(`/cache/node/${expectedVersion}/x64`); | ||||
|  | ||||
|         findSpy.mockImplementation(() => ''); | ||||
|         findAllVersionsSpy.mockImplementation(() => []); | ||||
|         dlSpy.mockImplementation(async () => '/some/temp/path'); | ||||
|         exSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||
|         cacheSpy.mockImplementation(async () => toolPath); | ||||
|  | ||||
|         inputs['node-version'] = input; | ||||
|         os['arch'] = 'x64'; | ||||
|         os['platform'] = 'linux'; | ||||
|         // act | ||||
|         await main.run(); | ||||
|  | ||||
|         // assert | ||||
|         expect(logSpy).toHaveBeenCalledWith( | ||||
|           `Acquiring ${expectedVersion} - ${os.arch} from ${expectedUrl}` | ||||
|         ); | ||||
|         expect(logSpy).toHaveBeenCalledWith('Extracting ...'); | ||||
|         expect(logSpy).toHaveBeenCalledWith('Adding to the cache ...'); | ||||
|         expect(cnSpy).toHaveBeenCalledWith( | ||||
|           `::add-path::${path.join(toolPath, 'bin')}${osm.EOL}` | ||||
|         ); | ||||
|       } | ||||
|     ); | ||||
|  | ||||
|     it.each([ | ||||
|       ['17.5.0-nightly', '17.5.0-nightly20220209e43808936a'], | ||||
|       ['17-nightly', '17.5.0-nightly20220209e43808936a'], | ||||
|       ['20.0.0-nightly', '20.0.0-nightly2022101987cdf7d412'] | ||||
|     ])( | ||||
|       'finds the %s version in the hostedToolcache', | ||||
|       async (input, expectedVersion) => { | ||||
|         const toolPath = path.normalize(`/cache/node/${expectedVersion}/x64`); | ||||
|         findSpy.mockReturnValue(toolPath); | ||||
|         findAllVersionsSpy.mockReturnValue([ | ||||
|           '17.5.0-nightly20220209e43808936a', | ||||
|           '17.5.0-nightly20220209e43808935a', | ||||
|           '20.0.0-nightly2022101987cdf7d412', | ||||
|           '20.0.0-nightly2022101987cdf7d411' | ||||
|         ]); | ||||
|  | ||||
|         inputs['node-version'] = input; | ||||
|         os['arch'] = 'x64'; | ||||
|         os['platform'] = 'linux'; | ||||
|  | ||||
|         // act | ||||
|         await main.run(); | ||||
|  | ||||
|         // assert | ||||
|         expect(findAllVersionsSpy).toHaveBeenCalled(); | ||||
|         expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); | ||||
|         expect(cnSpy).toHaveBeenCalledWith( | ||||
|           `::add-path::${path.join(toolPath, 'bin')}${osm.EOL}` | ||||
|         ); | ||||
|       } | ||||
|     ); | ||||
|  | ||||
|     it.each([ | ||||
|       [ | ||||
|         '17.5.0-nightly', | ||||
|         '17.5.0-nightly20220209e43808936a', | ||||
|         '17.0.0-nightly202110193f11666dc7', | ||||
|         'https://nodejs.org/download/nightly/v17.5.0-nightly20220209e43808936a/node-v17.5.0-nightly20220209e43808936a-linux-x64.tar.gz' | ||||
|       ], | ||||
|       [ | ||||
|         '17-nightly', | ||||
|         '17.5.0-nightly20220209e43808936a', | ||||
|         '17.0.0-nightly202110193f11666dc7', | ||||
|         'https://nodejs.org/download/nightly/v17.5.0-nightly20220209e43808936a/node-v17.5.0-nightly20220209e43808936a-linux-x64.tar.gz' | ||||
|       ], | ||||
|       [ | ||||
|         '18.0.0-nightly', | ||||
|         '18.0.0-nightly20220419bde889bd4e', | ||||
|         '18.0.0-nightly202204180699150267', | ||||
|         'https://nodejs.org/download/nightly/v18.0.0-nightly20220419bde889bd4e/node-v18.0.0-nightly20220419bde889bd4e-linux-x64.tar.gz' | ||||
|       ], | ||||
|       [ | ||||
|         '18-nightly', | ||||
|         '18.0.0-nightly20220419bde889bd4e', | ||||
|         '18.0.0-nightly202204180699150267', | ||||
|         'https://nodejs.org/download/nightly/v18.0.0-nightly20220419bde889bd4e/node-v18.0.0-nightly20220419bde889bd4e-linux-x64.tar.gz' | ||||
|       ], | ||||
|       [ | ||||
|         '20.0.0-nightly', | ||||
|         '20.0.0-nightly2022101987cdf7d412', | ||||
|         '20.0.0-nightly2022101987cdf7d411', | ||||
|         'https://nodejs.org/download/nightly/v20.0.0-nightly2022101987cdf7d412/node-v20.0.0-nightly2022101987cdf7d412-linux-x64.tar.gz' | ||||
|       ] | ||||
|     ])( | ||||
|       'get %s version from dist if check-latest is true', | ||||
|       async (input, expectedVersion, foundVersion, expectedUrl) => { | ||||
|         const foundToolPath = path.normalize(`/cache/node/${foundVersion}/x64`); | ||||
|         const toolPath = path.normalize(`/cache/node/${expectedVersion}/x64`); | ||||
|  | ||||
|         inputs['node-version'] = input; | ||||
|         inputs['check-latest'] = 'true'; | ||||
|         os['arch'] = 'x64'; | ||||
|         os['platform'] = 'linux'; | ||||
|  | ||||
|         findSpy.mockReturnValue(foundToolPath); | ||||
|         findAllVersionsSpy.mockReturnValue([ | ||||
|           '17.0.0-nightly202110193f11666dc7', | ||||
|           '18.0.0-nightly202204180699150267', | ||||
|           '20.0.0-nightly2022101987cdf7d411' | ||||
|         ]); | ||||
|         dlSpy.mockImplementation(async () => '/some/temp/path'); | ||||
|         exSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||
|         cacheSpy.mockImplementation(async () => toolPath); | ||||
|  | ||||
|         // act | ||||
|         await main.run(); | ||||
|  | ||||
|         // assert | ||||
|         expect(findAllVersionsSpy).toHaveBeenCalled(); | ||||
|         expect(logSpy).toHaveBeenCalledWith( | ||||
|           `Acquiring ${expectedVersion} - ${os.arch} from ${expectedUrl}` | ||||
|         ); | ||||
|         expect(logSpy).toHaveBeenCalledWith('Extracting ...'); | ||||
|         expect(logSpy).toHaveBeenCalledWith('Adding to the cache ...'); | ||||
|         expect(cnSpy).toHaveBeenCalledWith( | ||||
|           `::add-path::${path.join(toolPath, 'bin')}${osm.EOL}` | ||||
|         ); | ||||
|       } | ||||
|     ); | ||||
|   }); | ||||
| }); | ||||
| @@ -1,24 +1,26 @@ | ||||
| import * as core from '@actions/core'; | ||||
| import * as io from '@actions/io'; | ||||
| import * as tc from '@actions/tool-cache'; | ||||
| import * as exec from '@actions/exec'; | ||||
| import * as im from '../src/installer'; | ||||
| import * as cache from '@actions/cache'; | ||||
| import * as httpm from '@actions/http-client'; | ||||
| import * as exec from '@actions/exec'; | ||||
| import * as cache from '@actions/cache'; | ||||
| import fs from 'fs'; | ||||
| import cp from 'child_process'; | ||||
| import osm from 'os'; | ||||
| import path from 'path'; | ||||
| import each from 'jest-each'; | ||||
| import * as main from '../src/main'; | ||||
| import * as auth from '../src/authutil'; | ||||
| import OfficialBuilds from '../src/distributions/official_builds/official_builds'; | ||||
| import {INodeVersion} from '../src/distributions/base-models'; | ||||
| 
 | ||||
| const nodeTestManifest = require('./data/versions-manifest.json'); | ||||
| const nodeTestDist = require('./data/node-dist-index.json'); | ||||
| const nodeTestDistNightly = require('./data/node-nightly-index.json'); | ||||
| const nodeTestDistRc = require('./data/node-rc-index.json'); | ||||
| const nodeV8CanaryTestDist = require('./data/v8-canary-dist-index.json'); | ||||
| 
 | ||||
| describe('setup-node', () => { | ||||
|   let build: OfficialBuilds; | ||||
|   let inputs = {} as any; | ||||
|   let os = {} as any; | ||||
| 
 | ||||
| @@ -29,7 +31,6 @@ describe('setup-node', () => { | ||||
|   let logSpy: jest.SpyInstance; | ||||
|   let warningSpy: jest.SpyInstance; | ||||
|   let getManifestSpy: jest.SpyInstance; | ||||
|   let getDistSpy: jest.SpyInstance; | ||||
|   let platSpy: jest.SpyInstance; | ||||
|   let archSpy: jest.SpyInstance; | ||||
|   let dlSpy: jest.SpyInstance; | ||||
| @@ -42,7 +43,6 @@ describe('setup-node', () => { | ||||
|   let mkdirpSpy: jest.SpyInstance; | ||||
|   let execSpy: jest.SpyInstance; | ||||
|   let authSpy: jest.SpyInstance; | ||||
|   let parseNodeVersionSpy: jest.SpyInstance; | ||||
|   let isCacheActionAvailable: jest.SpyInstance; | ||||
|   let getExecOutputSpy: jest.SpyInstance; | ||||
|   let getJsonSpy: jest.SpyInstance; | ||||
| @@ -71,8 +71,6 @@ describe('setup-node', () => { | ||||
|     exSpy = jest.spyOn(tc, 'extractTar'); | ||||
|     cacheSpy = jest.spyOn(tc, 'cacheDir'); | ||||
|     getManifestSpy = jest.spyOn(tc, 'getManifestFromRepo'); | ||||
|     getDistSpy = jest.spyOn(im, 'getVersionsFromDist'); | ||||
|     parseNodeVersionSpy = jest.spyOn(im, 'parseNodeVersionFile'); | ||||
| 
 | ||||
|     // http-client
 | ||||
|     getJsonSpy = jest.spyOn(httpm.HttpClient.prototype, 'getJson'); | ||||
| @@ -94,25 +92,14 @@ describe('setup-node', () => { | ||||
|       () => <tc.IToolRelease[]>nodeTestManifest | ||||
|     ); | ||||
| 
 | ||||
|     getDistSpy.mockImplementation(version => { | ||||
|       const initialUrl = im.getNodejsDistUrl(version); | ||||
|       if (initialUrl.endsWith('/rc')) { | ||||
|         return <im.INodeVersion>nodeTestDistRc; | ||||
|       } else if (initialUrl.endsWith('/nightly')) { | ||||
|         return <im.INodeVersion>nodeTestDistNightly; | ||||
|       } else { | ||||
|         return <im.INodeVersion>nodeTestDist; | ||||
|       } | ||||
|     }); | ||||
| 
 | ||||
|     getJsonSpy.mockImplementation(url => { | ||||
|       let res: any; | ||||
|       if (url.includes('/rc')) { | ||||
|         res = <im.INodeVersion>nodeTestDistRc; | ||||
|         res = <INodeVersion>nodeTestDistRc; | ||||
|       } else if (url.includes('/nightly')) { | ||||
|         res = <im.INodeVersion>nodeTestDistNightly; | ||||
|         res = <INodeVersion>nodeTestDistNightly; | ||||
|       } else { | ||||
|         res = <im.INodeVersion>nodeTestDist; | ||||
|         res = <INodeVersion>nodeTestDist; | ||||
|       } | ||||
| 
 | ||||
|       return {result: res}; | ||||
| @@ -125,11 +112,11 @@ describe('setup-node', () => { | ||||
|     warningSpy = jest.spyOn(core, 'warning'); | ||||
|     cnSpy.mockImplementation(line => { | ||||
|       // uncomment to debug
 | ||||
|       // process.stderr.write('write:' + line + '\n');
 | ||||
|       process.stderr.write('write:' + line + '\n'); | ||||
|     }); | ||||
|     logSpy.mockImplementation(line => { | ||||
|       // uncomment to debug
 | ||||
|       // process.stderr.write('log:' + line + '\n');
 | ||||
|       //   uncomment to debug
 | ||||
|       process.stderr.write('log:' + line + '\n'); | ||||
|     }); | ||||
|     dbgSpy.mockImplementation(msg => { | ||||
|       // uncomment to see debug output
 | ||||
| @@ -137,7 +124,7 @@ describe('setup-node', () => { | ||||
|     }); | ||||
|     warningSpy.mockImplementation(msg => { | ||||
|       // uncomment to debug
 | ||||
|       // process.stderr.write('log:' + line + '\n');
 | ||||
|       // process.stderr.write('log:' + msg + '\n');
 | ||||
|     }); | ||||
| 
 | ||||
|     // @actions/exec
 | ||||
| @@ -159,23 +146,6 @@ describe('setup-node', () => { | ||||
|   //--------------------------------------------------
 | ||||
|   // Manifest find tests
 | ||||
|   //--------------------------------------------------
 | ||||
|   it('can mock manifest versions', async () => { | ||||
|     let versions: tc.IToolRelease[] | null = await tc.getManifestFromRepo( | ||||
|       'actions', | ||||
|       'node-versions', | ||||
|       'mocktoken' | ||||
|     ); | ||||
|     expect(versions).toBeDefined(); | ||||
|     expect(versions?.length).toBe(7); | ||||
|   }); | ||||
| 
 | ||||
|   it('can mock dist versions', async () => { | ||||
|     const versionSpec = '1.2.3'; | ||||
|     let versions: im.INodeVersion[] = await im.getVersionsFromDist(versionSpec); | ||||
|     expect(versions).toBeDefined(); | ||||
|     expect(versions?.length).toBe(23); | ||||
|   }); | ||||
| 
 | ||||
|   it.each([ | ||||
|     ['12.16.2', 'darwin', '12.16.2', 'Erbium'], | ||||
|     ['12', 'linux', '12.16.2', 'Erbium'], | ||||
| @@ -315,35 +285,32 @@ describe('setup-node', () => { | ||||
| 
 | ||||
|     // a version which is not in the manifest but is in node dist
 | ||||
|     let versionSpec = '11.15.0'; | ||||
|     let resolvedVersion = versionSpec; | ||||
| 
 | ||||
|     inputs['node-version'] = versionSpec; | ||||
|     inputs['always-auth'] = false; | ||||
|     inputs['token'] = 'faketoken'; | ||||
| 
 | ||||
|     let expectedUrl = | ||||
|       'https://github.com/actions/node-versions/releases/download/12.16.2-20200507.95/node-12.16.2-linux-x64.tar.gz'; | ||||
| 
 | ||||
|     // ... but not in the local cache
 | ||||
|     findSpy.mockImplementation(() => ''); | ||||
| 
 | ||||
|     dlSpy.mockImplementation(async () => '/some/temp/path'); | ||||
|     let toolPath = path.normalize('/cache/node/11.11.0/x64'); | ||||
|     const toolPath = path.normalize('/cache/node/11.15.0/x64'); | ||||
|     exSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||
|     cacheSpy.mockImplementation(async () => toolPath); | ||||
| 
 | ||||
|     await main.run(); | ||||
| 
 | ||||
|     let expPath = path.join(toolPath, 'bin'); | ||||
|     const expPath = path.join(toolPath, 'bin'); | ||||
| 
 | ||||
|     expect(dlSpy).toHaveBeenCalled(); | ||||
|     expect(exSpy).toHaveBeenCalled(); | ||||
|     expect(logSpy).toHaveBeenCalledWith( | ||||
|       'Not found in manifest.  Falling back to download directly from Node' | ||||
|     ); | ||||
|     expect(getManifestSpy).toHaveBeenCalled(); | ||||
|     expect(logSpy).toHaveBeenCalledWith( | ||||
|       `Attempting to download ${versionSpec}...` | ||||
|     ); | ||||
|     expect(logSpy).toHaveBeenCalledWith( | ||||
|       'Not found in manifest. Falling back to download directly from Node' | ||||
|     ); | ||||
|     expect(dlSpy).toHaveBeenCalled(); | ||||
|     expect(exSpy).toHaveBeenCalled(); | ||||
|     expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`); | ||||
|   }); | ||||
| 
 | ||||
| @@ -358,7 +325,7 @@ describe('setup-node', () => { | ||||
|     await main.run(); | ||||
| 
 | ||||
|     expect(logSpy).toHaveBeenCalledWith( | ||||
|       'Not found in manifest.  Falling back to download directly from Node' | ||||
|       'Not found in manifest. Falling back to download directly from Node' | ||||
|     ); | ||||
|     expect(logSpy).toHaveBeenCalledWith( | ||||
|       `Attempting to download ${versionSpec}...` | ||||
| @@ -596,165 +563,6 @@ describe('setup-node', () => { | ||||
|     }); | ||||
|   }); | ||||
| 
 | ||||
|   describe('node-version-file flag', () => { | ||||
|     it('not used if node-version is provided', async () => { | ||||
|       // Arrange
 | ||||
|       inputs['node-version'] = '12'; | ||||
| 
 | ||||
|       // Act
 | ||||
|       await main.run(); | ||||
| 
 | ||||
|       // Assert
 | ||||
|       expect(parseNodeVersionSpy).toHaveBeenCalledTimes(0); | ||||
|     }); | ||||
| 
 | ||||
|     it('not used if node-version-file not provided', async () => { | ||||
|       // Act
 | ||||
|       await main.run(); | ||||
| 
 | ||||
|       // Assert
 | ||||
|       expect(parseNodeVersionSpy).toHaveBeenCalledTimes(0); | ||||
|     }); | ||||
| 
 | ||||
|     it('reads node-version-file if provided', async () => { | ||||
|       // Arrange
 | ||||
|       const versionSpec = 'v14'; | ||||
|       const versionFile = '.nvmrc'; | ||||
|       const expectedVersionSpec = '14'; | ||||
|       process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data'); | ||||
|       inputs['node-version-file'] = versionFile; | ||||
| 
 | ||||
|       parseNodeVersionSpy.mockImplementation(() => expectedVersionSpec); | ||||
|       existsSpy.mockImplementationOnce( | ||||
|         input => input === path.join(__dirname, 'data', versionFile) | ||||
|       ); | ||||
| 
 | ||||
|       // Act
 | ||||
|       await main.run(); | ||||
| 
 | ||||
|       // Assert
 | ||||
|       expect(existsSpy).toHaveBeenCalledTimes(1); | ||||
|       expect(existsSpy).toHaveReturnedWith(true); | ||||
|       expect(parseNodeVersionSpy).toHaveBeenCalledWith(versionSpec); | ||||
|       expect(logSpy).toHaveBeenCalledWith( | ||||
|         `Resolved ${versionFile} as ${expectedVersionSpec}` | ||||
|       ); | ||||
|     }); | ||||
| 
 | ||||
|     it('reads package.json as node-version-file if provided', async () => { | ||||
|       // Arrange
 | ||||
|       const versionSpec = fs.readFileSync( | ||||
|         path.join(__dirname, 'data/package.json'), | ||||
|         'utf-8' | ||||
|       ); | ||||
|       const versionFile = 'package.json'; | ||||
|       const expectedVersionSpec = '14'; | ||||
|       process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data'); | ||||
|       inputs['node-version-file'] = versionFile; | ||||
| 
 | ||||
|       parseNodeVersionSpy.mockImplementation(() => expectedVersionSpec); | ||||
|       existsSpy.mockImplementationOnce( | ||||
|         input => input === path.join(__dirname, 'data', versionFile) | ||||
|       ); | ||||
|       // Act
 | ||||
|       await main.run(); | ||||
| 
 | ||||
|       // Assert
 | ||||
|       expect(existsSpy).toHaveBeenCalledTimes(1); | ||||
|       expect(existsSpy).toHaveReturnedWith(true); | ||||
|       expect(parseNodeVersionSpy).toHaveBeenCalledWith(versionSpec); | ||||
|       expect(logSpy).toHaveBeenCalledWith( | ||||
|         `Resolved ${versionFile} as ${expectedVersionSpec}` | ||||
|       ); | ||||
|     }); | ||||
| 
 | ||||
|     it('both node-version-file and node-version are provided', async () => { | ||||
|       inputs['node-version'] = '12'; | ||||
|       const versionSpec = 'v14'; | ||||
|       const versionFile = '.nvmrc'; | ||||
|       const expectedVersionSpec = '14'; | ||||
|       process.env['GITHUB_WORKSPACE'] = path.join(__dirname, '..'); | ||||
|       inputs['node-version-file'] = versionFile; | ||||
| 
 | ||||
|       parseNodeVersionSpy.mockImplementation(() => expectedVersionSpec); | ||||
| 
 | ||||
|       // Act
 | ||||
|       await main.run(); | ||||
| 
 | ||||
|       // Assert
 | ||||
|       expect(existsSpy).toHaveBeenCalledTimes(0); | ||||
|       expect(parseNodeVersionSpy).not.toHaveBeenCalled(); | ||||
|       expect(warningSpy).toHaveBeenCalledWith( | ||||
|         'Both node-version and node-version-file inputs are specified, only node-version will be used' | ||||
|       ); | ||||
|     }); | ||||
| 
 | ||||
|     it('should throw an error if node-version-file is not found', async () => { | ||||
|       const versionFile = '.nvmrc'; | ||||
|       const versionFilePath = path.join(__dirname, '..', versionFile); | ||||
|       inputs['node-version-file'] = versionFile; | ||||
| 
 | ||||
|       inSpy.mockImplementation(name => inputs[name]); | ||||
|       existsSpy.mockImplementationOnce( | ||||
|         input => input === path.join(__dirname, 'data', versionFile) | ||||
|       ); | ||||
| 
 | ||||
|       // Act
 | ||||
|       await main.run(); | ||||
| 
 | ||||
|       // Assert
 | ||||
|       expect(existsSpy).toHaveBeenCalled(); | ||||
|       expect(existsSpy).toHaveReturnedWith(false); | ||||
|       expect(parseNodeVersionSpy).not.toHaveBeenCalled(); | ||||
|       expect(cnSpy).toHaveBeenCalledWith( | ||||
|         `::error::The specified node version file at: ${versionFilePath} does not exist${osm.EOL}` | ||||
|       ); | ||||
|     }); | ||||
|   }); | ||||
| 
 | ||||
|   describe('cache on GHES', () => { | ||||
|     it('Should throw an error, because cache is not supported', async () => { | ||||
|       inputs['node-version'] = '12'; | ||||
|       inputs['cache'] = 'npm'; | ||||
| 
 | ||||
|       inSpy.mockImplementation(name => inputs[name]); | ||||
| 
 | ||||
|       let toolPath = path.normalize('/cache/node/12.16.1/x64'); | ||||
|       findSpy.mockImplementation(() => toolPath); | ||||
| 
 | ||||
|       // expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
 | ||||
|       process.env['GITHUB_SERVER_URL'] = 'https://www.test.com'; | ||||
|       isCacheActionAvailable.mockImplementation(() => false); | ||||
| 
 | ||||
|       await main.run(); | ||||
| 
 | ||||
|       expect(warningSpy).toHaveBeenCalledWith( | ||||
|         //  `::error::Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.${osm.EOL}`
 | ||||
|         'Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.' | ||||
|       ); | ||||
|     }); | ||||
| 
 | ||||
|     it('Should throw an internal error', async () => { | ||||
|       inputs['node-version'] = '12'; | ||||
|       inputs['cache'] = 'npm'; | ||||
| 
 | ||||
|       inSpy.mockImplementation(name => inputs[name]); | ||||
| 
 | ||||
|       let toolPath = path.normalize('/cache/node/12.16.1/x64'); | ||||
|       findSpy.mockImplementation(() => toolPath); | ||||
| 
 | ||||
|       // expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
 | ||||
|       process.env['GITHUB_SERVER_URL'] = ''; | ||||
|       isCacheActionAvailable.mockImplementation(() => false); | ||||
| 
 | ||||
|       await main.run(); | ||||
| 
 | ||||
|       expect(warningSpy).toHaveBeenCalledWith( | ||||
|         'The runner was not able to contact the cache service. Caching will be skipped' | ||||
|       ); | ||||
|     }); | ||||
|   }); | ||||
| 
 | ||||
|   describe('LTS version', () => { | ||||
|     beforeEach(() => { | ||||
|       os.platform = 'linux'; | ||||
| @@ -930,277 +738,6 @@ describe('setup-node', () => { | ||||
|     }); | ||||
|   }); | ||||
| 
 | ||||
|   describe('rc versions', () => { | ||||
|     it.each([ | ||||
|       [ | ||||
|         '13.10.1-rc.0', | ||||
|         '13.10.1-rc.0', | ||||
|         'https://nodejs.org/download/rc/v13.10.1-rc.0/node-v13.10.1-rc.0-linux-x64.tar.gz' | ||||
|       ], | ||||
|       [ | ||||
|         '14.15.5-rc.1', | ||||
|         '14.15.5-rc.1', | ||||
|         'https://nodejs.org/download/rc/v14.15.5-rc.1/node-v14.15.5-rc.1-linux-x64.tar.gz' | ||||
|       ], | ||||
|       [ | ||||
|         '16.17.0-rc.1', | ||||
|         '16.17.0-rc.1', | ||||
|         'https://nodejs.org/download/rc/v16.17.0-rc.1/node-v16.17.0-rc.1-linux-x64.tar.gz' | ||||
|       ], | ||||
|       [ | ||||
|         '17.0.0-rc.1', | ||||
|         '17.0.0-rc.1', | ||||
|         'https://nodejs.org/download/rc/v17.0.0-rc.1/node-v17.0.0-rc.1-linux-x64.tar.gz' | ||||
|       ], | ||||
|       [ | ||||
|         '19.0.0-rc.2', | ||||
|         '19.0.0-rc.2', | ||||
|         'https://nodejs.org/download/rc/v19.0.0-rc.2/node-v19.0.0-rc.2-linux-x64.tar.gz' | ||||
|       ] | ||||
|     ])( | ||||
|       'finds the versions in the index.json and installs it', | ||||
|       async (input, expectedVersion, expectedUrl) => { | ||||
|         const toolPath = path.normalize(`/cache/node/${expectedVersion}/x64`); | ||||
| 
 | ||||
|         findSpy.mockImplementation(() => ''); | ||||
|         findAllVersionsSpy.mockImplementation(() => []); | ||||
|         dlSpy.mockImplementation(async () => '/some/temp/path'); | ||||
|         exSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||
|         cacheSpy.mockImplementation(async () => toolPath); | ||||
| 
 | ||||
|         inputs['node-version'] = input; | ||||
|         os['arch'] = 'x64'; | ||||
|         os['platform'] = 'linux'; | ||||
|         // act
 | ||||
|         await main.run(); | ||||
| 
 | ||||
|         // assert
 | ||||
|         expect(logSpy).toHaveBeenCalledWith( | ||||
|           `Attempting to download ${input}...` | ||||
|         ); | ||||
| 
 | ||||
|         expect(logSpy).toHaveBeenCalledWith( | ||||
|           `Acquiring ${expectedVersion} - ${os.arch} from ${expectedUrl}` | ||||
|         ); | ||||
|         expect(logSpy).toHaveBeenCalledWith('Extracting ...'); | ||||
|         expect(logSpy).toHaveBeenCalledWith('Adding to the cache ...'); | ||||
|         expect(cnSpy).toHaveBeenCalledWith( | ||||
|           `::add-path::${path.join(toolPath, 'bin')}${osm.EOL}` | ||||
|         ); | ||||
|       } | ||||
|     ); | ||||
| 
 | ||||
|     it.each([ | ||||
|       ['13.10.1-rc.0', '13.10.1-rc.0'], | ||||
|       ['14.15.5-rc.1', '14.15.5-rc.1'], | ||||
|       ['16.17.0-rc.1', '16.17.0-rc.1'], | ||||
|       ['17.0.0-rc.1', '17.0.0-rc.1'] | ||||
|     ])( | ||||
|       'finds the %s version in the hostedToolcache', | ||||
|       async (input, expectedVersion) => { | ||||
|         const toolPath = path.normalize(`/cache/node/${expectedVersion}/x64`); | ||||
|         findSpy.mockReturnValue(toolPath); | ||||
| 
 | ||||
|         inputs['node-version'] = input; | ||||
|         os['arch'] = 'x64'; | ||||
|         os['platform'] = 'linux'; | ||||
| 
 | ||||
|         // act
 | ||||
|         await main.run(); | ||||
| 
 | ||||
|         // assert
 | ||||
|         expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); | ||||
|         expect(cnSpy).toHaveBeenCalledWith( | ||||
|           `::add-path::${path.join(toolPath, 'bin')}${osm.EOL}` | ||||
|         ); | ||||
|       } | ||||
|     ); | ||||
| 
 | ||||
|     it('throws an error if version is not found', async () => { | ||||
|       const versionSpec = '19.0.0-rc.3'; | ||||
| 
 | ||||
|       findSpy.mockImplementation(() => ''); | ||||
|       findAllVersionsSpy.mockImplementation(() => []); | ||||
|       dlSpy.mockImplementation(async () => '/some/temp/path'); | ||||
|       exSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||
| 
 | ||||
|       inputs['node-version'] = versionSpec; | ||||
|       os['arch'] = 'x64'; | ||||
|       os['platform'] = 'linux'; | ||||
|       // act
 | ||||
|       await main.run(); | ||||
| 
 | ||||
|       // assert
 | ||||
|       expect(logSpy).toHaveBeenCalledWith( | ||||
|         `Attempting to download ${versionSpec}...` | ||||
|       ); | ||||
|       expect(cnSpy).toHaveBeenCalledWith( | ||||
|         `::error::Unable to find Node version '${versionSpec}' for platform ${os.platform} and architecture ${os.arch}.${osm.EOL}` | ||||
|       ); | ||||
|     }); | ||||
|   }); | ||||
| 
 | ||||
|   describe('nightly versions', () => { | ||||
|     it.each([ | ||||
|       [ | ||||
|         '17.5.0-nightly', | ||||
|         '17.5.0-nightly20220209e43808936a', | ||||
|         'https://nodejs.org/download/nightly/v17.5.0-nightly20220209e43808936a/node-v17.5.0-nightly20220209e43808936a-linux-x64.tar.gz' | ||||
|       ], | ||||
|       [ | ||||
|         '17-nightly', | ||||
|         '17.5.0-nightly20220209e43808936a', | ||||
|         'https://nodejs.org/download/nightly/v17.5.0-nightly20220209e43808936a/node-v17.5.0-nightly20220209e43808936a-linux-x64.tar.gz' | ||||
|       ], | ||||
|       [ | ||||
|         '18.0.0-nightly', | ||||
|         '18.0.0-nightly20220419bde889bd4e', | ||||
|         'https://nodejs.org/download/nightly/v18.0.0-nightly20220419bde889bd4e/node-v18.0.0-nightly20220419bde889bd4e-linux-x64.tar.gz' | ||||
|       ], | ||||
|       [ | ||||
|         '18-nightly', | ||||
|         '18.0.0-nightly20220419bde889bd4e', | ||||
|         'https://nodejs.org/download/nightly/v18.0.0-nightly20220419bde889bd4e/node-v18.0.0-nightly20220419bde889bd4e-linux-x64.tar.gz' | ||||
|       ], | ||||
|       [ | ||||
|         '20.0.0-nightly', | ||||
|         '20.0.0-nightly2022101987cdf7d412', | ||||
|         'https://nodejs.org/download/nightly/v20.0.0-nightly2022101987cdf7d412/node-v20.0.0-nightly2022101987cdf7d412-linux-x64.tar.gz' | ||||
|       ] | ||||
|     ])( | ||||
|       'finds the versions in the index.json and installs it', | ||||
|       async (input, expectedVersion, expectedUrl) => { | ||||
|         const toolPath = path.normalize(`/cache/node/${expectedVersion}/x64`); | ||||
| 
 | ||||
|         findSpy.mockImplementation(() => ''); | ||||
|         findAllVersionsSpy.mockImplementation(() => []); | ||||
|         dlSpy.mockImplementation(async () => '/some/temp/path'); | ||||
|         exSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||
|         cacheSpy.mockImplementation(async () => toolPath); | ||||
| 
 | ||||
|         inputs['node-version'] = input; | ||||
|         os['arch'] = 'x64'; | ||||
|         os['platform'] = 'linux'; | ||||
|         // act
 | ||||
|         await main.run(); | ||||
| 
 | ||||
|         // assert
 | ||||
|         expect(logSpy).toHaveBeenCalledWith( | ||||
|           `Attempting to download ${input}...` | ||||
|         ); | ||||
| 
 | ||||
|         expect(logSpy).toHaveBeenCalledWith( | ||||
|           `Acquiring ${expectedVersion} - ${os.arch} from ${expectedUrl}` | ||||
|         ); | ||||
|         expect(logSpy).toHaveBeenCalledWith('Extracting ...'); | ||||
|         expect(logSpy).toHaveBeenCalledWith('Adding to the cache ...'); | ||||
|         expect(cnSpy).toHaveBeenCalledWith( | ||||
|           `::add-path::${path.join(toolPath, 'bin')}${osm.EOL}` | ||||
|         ); | ||||
|       } | ||||
|     ); | ||||
| 
 | ||||
|     it.each([ | ||||
|       ['17.5.0-nightly', '17.5.0-nightly20220209e43808936a'], | ||||
|       ['17-nightly', '17.5.0-nightly20220209e43808936a'], | ||||
|       ['20.0.0-nightly', '20.0.0-nightly2022101987cdf7d412'] | ||||
|     ])( | ||||
|       'finds the %s version in the hostedToolcache', | ||||
|       async (input, expectedVersion) => { | ||||
|         const toolPath = path.normalize(`/cache/node/${expectedVersion}/x64`); | ||||
|         findSpy.mockReturnValue(toolPath); | ||||
|         findAllVersionsSpy.mockReturnValue([ | ||||
|           '17.5.0-nightly20220209e43808936a', | ||||
|           '17.5.0-nightly20220209e43808935a', | ||||
|           '20.0.0-nightly2022101987cdf7d412', | ||||
|           '20.0.0-nightly2022101987cdf7d411' | ||||
|         ]); | ||||
| 
 | ||||
|         inputs['node-version'] = input; | ||||
|         os['arch'] = 'x64'; | ||||
|         os['platform'] = 'linux'; | ||||
| 
 | ||||
|         // act
 | ||||
|         await main.run(); | ||||
| 
 | ||||
|         // assert
 | ||||
|         expect(findAllVersionsSpy).toHaveBeenCalled(); | ||||
|         expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); | ||||
|         expect(cnSpy).toHaveBeenCalledWith( | ||||
|           `::add-path::${path.join(toolPath, 'bin')}${osm.EOL}` | ||||
|         ); | ||||
|       } | ||||
|     ); | ||||
| 
 | ||||
|     it.each([ | ||||
|       [ | ||||
|         '17.5.0-nightly', | ||||
|         '17.5.0-nightly20220209e43808936a', | ||||
|         '17.0.0-nightly202110193f11666dc7', | ||||
|         'https://nodejs.org/download/nightly/v17.5.0-nightly20220209e43808936a/node-v17.5.0-nightly20220209e43808936a-linux-x64.tar.gz' | ||||
|       ], | ||||
|       [ | ||||
|         '17-nightly', | ||||
|         '17.5.0-nightly20220209e43808936a', | ||||
|         '17.0.0-nightly202110193f11666dc7', | ||||
|         'https://nodejs.org/download/nightly/v17.5.0-nightly20220209e43808936a/node-v17.5.0-nightly20220209e43808936a-linux-x64.tar.gz' | ||||
|       ], | ||||
|       [ | ||||
|         '18.0.0-nightly', | ||||
|         '18.0.0-nightly20220419bde889bd4e', | ||||
|         '18.0.0-nightly202204180699150267', | ||||
|         'https://nodejs.org/download/nightly/v18.0.0-nightly20220419bde889bd4e/node-v18.0.0-nightly20220419bde889bd4e-linux-x64.tar.gz' | ||||
|       ], | ||||
|       [ | ||||
|         '18-nightly', | ||||
|         '18.0.0-nightly20220419bde889bd4e', | ||||
|         '18.0.0-nightly202204180699150267', | ||||
|         'https://nodejs.org/download/nightly/v18.0.0-nightly20220419bde889bd4e/node-v18.0.0-nightly20220419bde889bd4e-linux-x64.tar.gz' | ||||
|       ], | ||||
|       [ | ||||
|         '20.0.0-nightly', | ||||
|         '20.0.0-nightly2022101987cdf7d412', | ||||
|         '20.0.0-nightly2022101987cdf7d411', | ||||
|         'https://nodejs.org/download/nightly/v20.0.0-nightly2022101987cdf7d412/node-v20.0.0-nightly2022101987cdf7d412-linux-x64.tar.gz' | ||||
|       ] | ||||
|     ])( | ||||
|       'get %s version from dist if check-latest is true', | ||||
|       async (input, expectedVersion, foundVersion, expectedUrl) => { | ||||
|         const foundToolPath = path.normalize(`/cache/node/${foundVersion}/x64`); | ||||
|         const toolPath = path.normalize(`/cache/node/${expectedVersion}/x64`); | ||||
| 
 | ||||
|         inputs['node-version'] = input; | ||||
|         inputs['check-latest'] = 'true'; | ||||
|         os['arch'] = 'x64'; | ||||
|         os['platform'] = 'linux'; | ||||
| 
 | ||||
|         findSpy.mockReturnValue(foundToolPath); | ||||
|         findAllVersionsSpy.mockReturnValue([ | ||||
|           '17.0.0-nightly202110193f11666dc7', | ||||
|           '18.0.0-nightly202204180699150267', | ||||
|           '20.0.0-nightly2022101987cdf7d411' | ||||
|         ]); | ||||
|         dlSpy.mockImplementation(async () => '/some/temp/path'); | ||||
|         exSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||
|         cacheSpy.mockImplementation(async () => toolPath); | ||||
| 
 | ||||
|         // act
 | ||||
|         await main.run(); | ||||
| 
 | ||||
|         // assert
 | ||||
|         expect(findAllVersionsSpy).toHaveBeenCalled(); | ||||
|         expect(logSpy).toHaveBeenCalledWith( | ||||
|           `Acquiring ${expectedVersion} - ${os.arch} from ${expectedUrl}` | ||||
|         ); | ||||
|         expect(logSpy).toHaveBeenCalledWith('Extracting ...'); | ||||
|         expect(logSpy).toHaveBeenCalledWith('Adding to the cache ...'); | ||||
|         expect(cnSpy).toHaveBeenCalledWith( | ||||
|           `::add-path::${path.join(toolPath, 'bin')}${osm.EOL}` | ||||
|         ); | ||||
|       } | ||||
|     ); | ||||
|   }); | ||||
| 
 | ||||
|   describe('latest alias syntax', () => { | ||||
|     it.each(['latest', 'current', 'node'])( | ||||
|       'download the %s version if alias is provided', | ||||
| @@ -1241,36 +778,16 @@ describe('setup-node', () => { | ||||
|         const toolPath = path.normalize( | ||||
|           `/cache/node/${expectedVersion.version}/x64` | ||||
|         ); | ||||
|         findSpy.mockReturnValue(toolPath); | ||||
|         findSpy.mockImplementation(() => toolPath); | ||||
| 
 | ||||
|         // Act
 | ||||
|         await main.run(); | ||||
| 
 | ||||
|         // assert
 | ||||
|         expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); | ||||
| 
 | ||||
|         expect(logSpy).toHaveBeenCalledWith('getting latest node version...'); | ||||
|         expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); | ||||
|       } | ||||
|     ); | ||||
|   }); | ||||
| }); | ||||
| 
 | ||||
| describe('helper methods', () => { | ||||
|   describe('parseNodeVersionFile', () => { | ||||
|     each` | ||||
|       contents                                     | expected | ||||
|       ${'12'}                                      | ${'12'} | ||||
|       ${'12.3'}                                    | ${'12.3'} | ||||
|       ${'12.3.4'}                                  | ${'12.3.4'} | ||||
|       ${'v12.3.4'}                                 | ${'12.3.4'} | ||||
|       ${'lts/erbium'}                              | ${'lts/erbium'} | ||||
|       ${'lts/*'}                                   | ${'lts/*'} | ||||
|       ${'nodejs 12.3.4'}                           | ${'12.3.4'} | ||||
|       ${'ruby 2.3.4\nnodejs 12.3.4\npython 3.4.5'} | ${'12.3.4'} | ||||
|       ${''}                                        | ${''} | ||||
|       ${'unknown format'}                          | ${'unknown format'} | ||||
|     `.it('parses "$contents"', ({contents, expected}) => {
 | ||||
|       expect(im.parseNodeVersionFile(contents)).toBe(expected); | ||||
|     }); | ||||
|   }); | ||||
| }); | ||||
							
								
								
									
										402
									
								
								__tests__/rc-installer.test.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										402
									
								
								__tests__/rc-installer.test.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,402 @@ | ||||
| import * as core from '@actions/core'; | ||||
| import * as io from '@actions/io'; | ||||
| import * as tc from '@actions/tool-cache'; | ||||
| import * as httpm from '@actions/http-client'; | ||||
| import * as exec from '@actions/exec'; | ||||
| import * as cache from '@actions/cache'; | ||||
| import fs from 'fs'; | ||||
| import cp from 'child_process'; | ||||
| import osm from 'os'; | ||||
| import path from 'path'; | ||||
| import * as main from '../src/main'; | ||||
| import * as auth from '../src/authutil'; | ||||
| import {INodeVersion} from '../src/distributions/base-models'; | ||||
|  | ||||
| const nodeTestDist = require('./data/node-dist-index.json'); | ||||
| const nodeTestDistNightly = require('./data/node-nightly-index.json'); | ||||
| const nodeTestDistRc = require('./data/node-rc-index.json'); | ||||
| const nodeV8CanaryTestDist = require('./data/v8-canary-dist-index.json'); | ||||
|  | ||||
| describe('setup-node', () => { | ||||
|   let inputs = {} as any; | ||||
|   let os = {} as any; | ||||
|  | ||||
|   let inSpy: jest.SpyInstance; | ||||
|   let findSpy: jest.SpyInstance; | ||||
|   let findAllVersionsSpy: jest.SpyInstance; | ||||
|   let cnSpy: jest.SpyInstance; | ||||
|   let logSpy: jest.SpyInstance; | ||||
|   let warningSpy: jest.SpyInstance; | ||||
|   let platSpy: jest.SpyInstance; | ||||
|   let archSpy: jest.SpyInstance; | ||||
|   let dlSpy: jest.SpyInstance; | ||||
|   let exSpy: jest.SpyInstance; | ||||
|   let cacheSpy: jest.SpyInstance; | ||||
|   let dbgSpy: jest.SpyInstance; | ||||
|   let whichSpy: jest.SpyInstance; | ||||
|   let existsSpy: jest.SpyInstance; | ||||
|   let mkdirpSpy: jest.SpyInstance; | ||||
|   let execSpy: jest.SpyInstance; | ||||
|   let authSpy: jest.SpyInstance; | ||||
|   let isCacheActionAvailable: jest.SpyInstance; | ||||
|   let getExecOutputSpy: jest.SpyInstance; | ||||
|   let getJsonSpy: jest.SpyInstance; | ||||
|  | ||||
|   beforeEach(() => { | ||||
|     // @actions/core | ||||
|     console.log('::stop-commands::stoptoken'); // Disable executing of runner commands when running tests in actions | ||||
|     process.env['GITHUB_PATH'] = ''; // Stub out ENV file functionality so we can verify it writes to standard out | ||||
|     process.env['GITHUB_OUTPUT'] = ''; // Stub out ENV file functionality so we can verify it writes to standard out | ||||
|     inputs = {}; | ||||
|     inSpy = jest.spyOn(core, 'getInput'); | ||||
|     inSpy.mockImplementation(name => inputs[name]); | ||||
|  | ||||
|     // node | ||||
|     os = {}; | ||||
|     platSpy = jest.spyOn(osm, 'platform'); | ||||
|     platSpy.mockImplementation(() => os['platform']); | ||||
|     archSpy = jest.spyOn(osm, 'arch'); | ||||
|     archSpy.mockImplementation(() => os['arch']); | ||||
|     execSpy = jest.spyOn(cp, 'execSync'); | ||||
|  | ||||
|     // @actions/tool-cache | ||||
|     findSpy = jest.spyOn(tc, 'find'); | ||||
|     findAllVersionsSpy = jest.spyOn(tc, 'findAllVersions'); | ||||
|     dlSpy = jest.spyOn(tc, 'downloadTool'); | ||||
|     exSpy = jest.spyOn(tc, 'extractTar'); | ||||
|     cacheSpy = jest.spyOn(tc, 'cacheDir'); | ||||
|     // getDistSpy = jest.spyOn(im, 'getVersionsFromDist'); | ||||
|  | ||||
|     // http-client | ||||
|     getJsonSpy = jest.spyOn(httpm.HttpClient.prototype, 'getJson'); | ||||
|  | ||||
|     // io | ||||
|     whichSpy = jest.spyOn(io, 'which'); | ||||
|     existsSpy = jest.spyOn(fs, 'existsSync'); | ||||
|     mkdirpSpy = jest.spyOn(io, 'mkdirP'); | ||||
|  | ||||
|     // @actions/tool-cache | ||||
|     isCacheActionAvailable = jest.spyOn(cache, 'isFeatureAvailable'); | ||||
|     isCacheActionAvailable.mockImplementation(() => false); | ||||
|  | ||||
|     // disable authentication portion for installer tests | ||||
|     authSpy = jest.spyOn(auth, 'configAuthentication'); | ||||
|     authSpy.mockImplementation(() => {}); | ||||
|  | ||||
|     getJsonSpy.mockImplementation(url => { | ||||
|       let res: any; | ||||
|       if (url.includes('/rc')) { | ||||
|         res = <INodeVersion>nodeTestDistRc; | ||||
|       } else if (url.includes('/nightly')) { | ||||
|         res = <INodeVersion>nodeTestDistNightly; | ||||
|       } else { | ||||
|         res = <INodeVersion>nodeTestDist; | ||||
|       } | ||||
|  | ||||
|       return {result: res}; | ||||
|     }); | ||||
|  | ||||
|     // writes | ||||
|     cnSpy = jest.spyOn(process.stdout, 'write'); | ||||
|     logSpy = jest.spyOn(core, 'info'); | ||||
|     dbgSpy = jest.spyOn(core, 'debug'); | ||||
|     warningSpy = jest.spyOn(core, 'warning'); | ||||
|     cnSpy.mockImplementation(line => { | ||||
|       // uncomment to debug | ||||
|       // process.stderr.write('write:' + line + '\n'); | ||||
|     }); | ||||
|     logSpy.mockImplementation(line => { | ||||
|       // uncomment to debug | ||||
|       // process.stderr.write('log:' + line + '\n'); | ||||
|     }); | ||||
|     dbgSpy.mockImplementation(msg => { | ||||
|       // uncomment to see debug output | ||||
|       // process.stderr.write(msg + '\n'); | ||||
|     }); | ||||
|     warningSpy.mockImplementation(msg => { | ||||
|       // uncomment to debug | ||||
|       // process.stderr.write('log:' + msg + '\n'); | ||||
|     }); | ||||
|  | ||||
|     // @actions/exec | ||||
|     getExecOutputSpy = jest.spyOn(exec, 'getExecOutput'); | ||||
|     getExecOutputSpy.mockImplementation(() => 'v16.15.0-rc.1'); | ||||
|   }); | ||||
|  | ||||
|   afterEach(() => { | ||||
|     jest.resetAllMocks(); | ||||
|     jest.clearAllMocks(); | ||||
|     //jest.restoreAllMocks(); | ||||
|   }); | ||||
|  | ||||
|   afterAll(async () => { | ||||
|     console.log('::stoptoken::'); // Re-enable executing of runner commands when running tests in actions | ||||
|     jest.restoreAllMocks(); | ||||
|   }, 100000); | ||||
|  | ||||
|   //-------------------------------------------------- | ||||
|   // Found in cache tests | ||||
|   //-------------------------------------------------- | ||||
|  | ||||
|   it('finds version in cache with stable true', async () => { | ||||
|     inputs['node-version'] = '12.0.0-rc.1'; | ||||
|     inputs.stable = 'true'; | ||||
|  | ||||
|     let toolPath = path.normalize('/cache/node/12.0.0-rc.1/x64'); | ||||
|     findSpy.mockImplementation(() => toolPath); | ||||
|     await main.run(); | ||||
|  | ||||
|     expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); | ||||
|   }); | ||||
|  | ||||
|   it('finds version in cache with stable not supplied', async () => { | ||||
|     inputs['node-version'] = '12.0.0-rc.1'; | ||||
|  | ||||
|     inSpy.mockImplementation(name => inputs[name]); | ||||
|  | ||||
|     let toolPath = path.normalize('/cache/node/12.0.0-rc.1/x64'); | ||||
|     findSpy.mockImplementation(() => toolPath); | ||||
|     await main.run(); | ||||
|  | ||||
|     expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); | ||||
|   }); | ||||
|  | ||||
|   it('finds version in cache and adds it to the path', async () => { | ||||
|     inputs['node-version'] = '12.0.0-rc.1'; | ||||
|  | ||||
|     inSpy.mockImplementation(name => inputs[name]); | ||||
|  | ||||
|     let toolPath = path.normalize('/cache/node/12.0.0-rc.1/x64'); | ||||
|     findSpy.mockImplementation(() => toolPath); | ||||
|     await main.run(); | ||||
|  | ||||
|     let expPath = path.join(toolPath, 'bin'); | ||||
|     expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`); | ||||
|   }); | ||||
|  | ||||
|   it('handles unhandled find error and reports error', async () => { | ||||
|     let errMsg = 'unhandled error message'; | ||||
|     inputs['node-version'] = '12.0.0-rc.1'; | ||||
|  | ||||
|     findSpy.mockImplementation(() => { | ||||
|       throw new Error(errMsg); | ||||
|     }); | ||||
|  | ||||
|     await main.run(); | ||||
|  | ||||
|     expect(cnSpy).toHaveBeenCalledWith('::error::' + errMsg + osm.EOL); | ||||
|   }); | ||||
|  | ||||
|   it('falls back to a version from node dist', async () => { | ||||
|     os.platform = 'linux'; | ||||
|     os.arch = 'x64'; | ||||
|  | ||||
|     let versionSpec = '13.0.0-rc.0'; | ||||
|  | ||||
|     inputs['node-version'] = versionSpec; | ||||
|     inputs['always-auth'] = false; | ||||
|     inputs['token'] = 'faketoken'; | ||||
|  | ||||
|     // ... but not in the local cache | ||||
|     findSpy.mockImplementation(() => ''); | ||||
|  | ||||
|     dlSpy.mockImplementation(async () => '/some/temp/path'); | ||||
|     let toolPath = path.normalize('/cache/node/13.0.0-rc.0/x64'); | ||||
|     exSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||
|     cacheSpy.mockImplementation(async () => toolPath); | ||||
|  | ||||
|     await main.run(); | ||||
|  | ||||
|     let expPath = path.join(toolPath, 'bin'); | ||||
|  | ||||
|     expect(dlSpy).toHaveBeenCalled(); | ||||
|     expect(exSpy).toHaveBeenCalled(); | ||||
|     expect(logSpy).toHaveBeenCalledWith('Extracting ...'); | ||||
|     expect(logSpy).toHaveBeenCalledWith('Done'); | ||||
|     expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`); | ||||
|   }); | ||||
|  | ||||
|   it('does not find a version that does not exist', async () => { | ||||
|     os.platform = 'linux'; | ||||
|     os.arch = 'x64'; | ||||
|  | ||||
|     let versionSpec = '9.99.9-rc.1'; | ||||
|     inputs['node-version'] = versionSpec; | ||||
|  | ||||
|     findSpy.mockImplementation(() => ''); | ||||
|     await main.run(); | ||||
|  | ||||
|     expect(cnSpy).toHaveBeenCalledWith( | ||||
|       `::error::Unable to find Node version '${versionSpec}' for platform ${os.platform} and architecture ${os.arch}.${osm.EOL}` | ||||
|     ); | ||||
|   }); | ||||
|  | ||||
|   it('reports a failed download', async () => { | ||||
|     let errMsg = 'unhandled download message'; | ||||
|     os.platform = 'linux'; | ||||
|     os.arch = 'x64'; | ||||
|  | ||||
|     let versionSpec = '14.7.0-rc.1'; | ||||
|  | ||||
|     inputs['node-version'] = versionSpec; | ||||
|     inputs['always-auth'] = false; | ||||
|     inputs['token'] = 'faketoken'; | ||||
|  | ||||
|     findSpy.mockImplementation(() => ''); | ||||
|     findAllVersionsSpy.mockImplementation(() => []); | ||||
|     dlSpy.mockImplementation(() => { | ||||
|       throw new Error(errMsg); | ||||
|     }); | ||||
|     await main.run(); | ||||
|  | ||||
|     expect(cnSpy).toHaveBeenCalledWith(`::error::${errMsg}${osm.EOL}`); | ||||
|   }); | ||||
|  | ||||
|   it('acquires specified architecture of node', async () => { | ||||
|     for (const {arch, version, osSpec} of [ | ||||
|       {arch: 'x86', version: '13.4.0-rc.0', osSpec: 'win32'}, | ||||
|       {arch: 'x86', version: '14.15.5-rc.0', osSpec: 'win32'} | ||||
|     ]) { | ||||
|       os.platform = osSpec; | ||||
|       os.arch = arch; | ||||
|       const fileExtension = os.platform === 'win32' ? '7z' : 'tar.gz'; | ||||
|       const platform = { | ||||
|         linux: 'linux', | ||||
|         darwin: 'darwin', | ||||
|         win32: 'win' | ||||
|       }[os.platform]; | ||||
|  | ||||
|       inputs['node-version'] = version; | ||||
|       inputs['architecture'] = arch; | ||||
|       inputs['always-auth'] = false; | ||||
|       inputs['token'] = 'faketoken'; | ||||
|  | ||||
|       let expectedUrl = `https://nodejs.org/download/rc/v${version}/node-v${version}-${platform}-${arch}.${fileExtension}`; | ||||
|  | ||||
|       // ... but not in the local cache | ||||
|       findSpy.mockImplementation(() => ''); | ||||
|       findAllVersionsSpy.mockImplementation(() => []); | ||||
|  | ||||
|       dlSpy.mockImplementation(async () => '/some/temp/path'); | ||||
|       let toolPath = path.normalize(`/cache/node/${version}/${arch}`); | ||||
|       exSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||
|       cacheSpy.mockImplementation(async () => toolPath); | ||||
|  | ||||
|       await main.run(); | ||||
|       expect(dlSpy).toHaveBeenCalled(); | ||||
|       expect(logSpy).toHaveBeenCalledWith( | ||||
|         `Acquiring ${version} - ${arch} from ${expectedUrl}` | ||||
|       ); | ||||
|     } | ||||
|   }, 100000); | ||||
|  | ||||
|   describe('rc versions', () => { | ||||
|     it.each([ | ||||
|       [ | ||||
|         '13.10.1-rc.0', | ||||
|         '13.10.1-rc.0', | ||||
|         'https://nodejs.org/download/rc/v13.10.1-rc.0/node-v13.10.1-rc.0-linux-x64.tar.gz' | ||||
|       ], | ||||
|       [ | ||||
|         '14.15.5-rc.1', | ||||
|         '14.15.5-rc.1', | ||||
|         'https://nodejs.org/download/rc/v14.15.5-rc.1/node-v14.15.5-rc.1-linux-x64.tar.gz' | ||||
|       ], | ||||
|       [ | ||||
|         '16.17.0-rc.1', | ||||
|         '16.17.0-rc.1', | ||||
|         'https://nodejs.org/download/rc/v16.17.0-rc.1/node-v16.17.0-rc.1-linux-x64.tar.gz' | ||||
|       ], | ||||
|       [ | ||||
|         '17.0.0-rc.1', | ||||
|         '17.0.0-rc.1', | ||||
|         'https://nodejs.org/download/rc/v17.0.0-rc.1/node-v17.0.0-rc.1-linux-x64.tar.gz' | ||||
|       ], | ||||
|       [ | ||||
|         '19.0.0-rc.2', | ||||
|         '19.0.0-rc.2', | ||||
|         'https://nodejs.org/download/rc/v19.0.0-rc.2/node-v19.0.0-rc.2-linux-x64.tar.gz' | ||||
|       ] | ||||
|     ])( | ||||
|       'finds the versions in the index.json and installs it', | ||||
|       async (input, expectedVersion, expectedUrl) => { | ||||
|         const toolPath = path.normalize(`/cache/node/${expectedVersion}/x64`); | ||||
|  | ||||
|         findSpy.mockImplementation(() => ''); | ||||
|         findAllVersionsSpy.mockImplementation(() => []); | ||||
|         dlSpy.mockImplementation(async () => '/some/temp/path'); | ||||
|         exSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||
|         cacheSpy.mockImplementation(async () => toolPath); | ||||
|  | ||||
|         inputs['node-version'] = input; | ||||
|         os['arch'] = 'x64'; | ||||
|         os['platform'] = 'linux'; | ||||
|         // act | ||||
|         await main.run(); | ||||
|  | ||||
|         // assert | ||||
|         expect(logSpy).toHaveBeenCalledWith('Extracting ...'); | ||||
|         expect(logSpy).toHaveBeenCalledWith('Adding to the cache ...'); | ||||
|         expect(cnSpy).toHaveBeenCalledWith( | ||||
|           `::add-path::${path.join(toolPath, 'bin')}${osm.EOL}` | ||||
|         ); | ||||
|       } | ||||
|     ); | ||||
|  | ||||
|     it.each([ | ||||
|       ['13.10.1-rc.0', '13.10.1-rc.0'], | ||||
|       ['14.15.5-rc.1', '14.15.5-rc.1'], | ||||
|       ['16.17.0-rc.1', '16.17.0-rc.1'], | ||||
|       ['17.0.0-rc.1', '17.0.0-rc.1'] | ||||
|     ])( | ||||
|       'finds the %s version in the hostedToolcache', | ||||
|       async (input, expectedVersion) => { | ||||
|         const toolPath = path.normalize(`/cache/node/${expectedVersion}/x64`); | ||||
|         findSpy.mockImplementation((_, version) => | ||||
|           path.normalize(`/cache/node/${version}/x64`) | ||||
|         ); | ||||
|         findAllVersionsSpy.mockReturnValue([ | ||||
|           '2.2.2-rc.2', | ||||
|           '1.1.1-rc.1', | ||||
|           '99.1.1', | ||||
|           expectedVersion, | ||||
|           '88.1.1', | ||||
|           '3.3.3-rc.3' | ||||
|         ]); | ||||
|  | ||||
|         inputs['node-version'] = input; | ||||
|         os['arch'] = 'x64'; | ||||
|         os['platform'] = 'linux'; | ||||
|  | ||||
|         // act | ||||
|         await main.run(); | ||||
|  | ||||
|         // assert | ||||
|         expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`); | ||||
|         expect(cnSpy).toHaveBeenCalledWith( | ||||
|           `::add-path::${path.join(toolPath, 'bin')}${osm.EOL}` | ||||
|         ); | ||||
|       } | ||||
|     ); | ||||
|  | ||||
|     it('throws an error if version is not found', async () => { | ||||
|       const versionSpec = '19.0.0-rc.3'; | ||||
|  | ||||
|       findSpy.mockImplementation(() => ''); | ||||
|       findAllVersionsSpy.mockImplementation(() => []); | ||||
|       dlSpy.mockImplementation(async () => '/some/temp/path'); | ||||
|       exSpy.mockImplementation(async () => '/some/other/temp/path'); | ||||
|  | ||||
|       inputs['node-version'] = versionSpec; | ||||
|       os['arch'] = 'x64'; | ||||
|       os['platform'] = 'linux'; | ||||
|       // act | ||||
|       await main.run(); | ||||
|  | ||||
|       // assert | ||||
|       expect(cnSpy).toHaveBeenCalledWith( | ||||
|         `::error::Unable to find Node version '${versionSpec}' for platform ${os.platform} and architecture ${os.arch}.${osm.EOL}` | ||||
|       ); | ||||
|     }); | ||||
|   }); | ||||
| }); | ||||
		Reference in New Issue
	
	Block a user
	 Dmitry Shibanov
					Dmitry Shibanov