mirror of
				https://gitea.com/actions/setup-node.git
				synced 2025-10-29 15:52:42 +08:00 
			
		
		
		
	download from node-versions and fallback to node dist (#147)
* download LTS versions from releases * support upcoiming ghes Co-authored-by: eric sciple <ericsciple@users.noreply.github.com>
This commit is contained in:
		| @@ -1,22 +1,26 @@ | ||||
| import * as io from '@actions/io'; | ||||
| import os = require('os'); | ||||
| import * as fs from 'fs'; | ||||
| import * as path from 'path'; | ||||
| import * as core from '@actions/core'; | ||||
| import * as io from '@actions/io'; | ||||
| import * as auth from '../src/authutil'; | ||||
|  | ||||
| let rcFile: string; | ||||
|  | ||||
| describe('installer tests', () => { | ||||
| describe('authutil tests', () => { | ||||
|   const _runnerDir = path.join(__dirname, 'runner'); | ||||
|  | ||||
|   let cnSpy: jest.SpyInstance; | ||||
|   let logSpy: jest.SpyInstance; | ||||
|   let dbgSpy: jest.SpyInstance; | ||||
|  | ||||
|   beforeAll(async () => { | ||||
|     const tempDir = path.join( | ||||
|       __dirname, | ||||
|       'runner', | ||||
|       path.join( | ||||
|         Math.random() | ||||
|           .toString(36) | ||||
|           .substring(7) | ||||
|       ), | ||||
|       'temp' | ||||
|     const randPath = path.join( | ||||
|       Math.random() | ||||
|         .toString(36) | ||||
|         .substring(7) | ||||
|     ); | ||||
|     const tempDir = path.join(_runnerDir, randPath, 'temp'); | ||||
|     await io.rmRF(tempDir); | ||||
|     await io.mkdirP(tempDir); | ||||
|     process.env['GITHUB_REPOSITORY'] = 'OwnerName/repo'; | ||||
| @@ -24,44 +28,96 @@ describe('installer tests', () => { | ||||
|     rcFile = path.join(tempDir, '.npmrc'); | ||||
|   }, 100000); | ||||
|  | ||||
|   beforeEach(() => { | ||||
|     if (fs.existsSync(rcFile)) { | ||||
|       fs.unlinkSync(rcFile); | ||||
|     } | ||||
|   beforeEach(async () => { | ||||
|     await io.rmRF(rcFile); | ||||
|     // if (fs.existsSync(rcFile)) { | ||||
|     //   fs.unlinkSync(rcFile); | ||||
|     // } | ||||
|     process.env['INPUT_SCOPE'] = ''; | ||||
|   }); | ||||
|  | ||||
|     // writes | ||||
|     cnSpy = jest.spyOn(process.stdout, 'write'); | ||||
|     logSpy = jest.spyOn(console, 'log'); | ||||
|     dbgSpy = jest.spyOn(core, 'debug'); | ||||
|     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'); | ||||
|     }); | ||||
|   }, 100000); | ||||
|  | ||||
|   function dbg(message: string) { | ||||
|     process.stderr.write('dbg::' + message + '::\n'); | ||||
|   } | ||||
|  | ||||
|   afterAll(async () => { | ||||
|     if (_runnerDir) { | ||||
|       await io.rmRF(_runnerDir); | ||||
|     } | ||||
|   }, 100000); | ||||
|  | ||||
|   function readRcFile(rcFile: string) { | ||||
|     let rc = {}; | ||||
|     let contents = fs.readFileSync(rcFile, {encoding: 'utf8'}); | ||||
|     for (const line of contents.split(os.EOL)) { | ||||
|       let parts = line.split('='); | ||||
|       if (parts.length == 2) { | ||||
|         rc[parts[0].trim()] = parts[1].trim(); | ||||
|       } | ||||
|     } | ||||
|     return rc; | ||||
|   } | ||||
|  | ||||
|   it('Sets up npmrc for npmjs', async () => { | ||||
|     await auth.configAuthentication('https://registry.npmjs.org/', 'false'); | ||||
|     expect(fs.existsSync(rcFile)).toBe(true); | ||||
|     expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot(); | ||||
|  | ||||
|     expect(fs.statSync(rcFile)).toBeDefined(); | ||||
|     let contents = fs.readFileSync(rcFile, {encoding: 'utf8'}); | ||||
|     let rc = readRcFile(rcFile); | ||||
|     expect(rc['registry']).toBe('https://registry.npmjs.org/'); | ||||
|     expect(rc['always-auth']).toBe('false'); | ||||
|   }); | ||||
|  | ||||
|   it('Appends trailing slash to registry', async () => { | ||||
|     await auth.configAuthentication('https://registry.npmjs.org', 'false'); | ||||
|  | ||||
|     expect(fs.existsSync(rcFile)).toBe(true); | ||||
|     expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot(); | ||||
|     expect(fs.statSync(rcFile)).toBeDefined(); | ||||
|     let rc = readRcFile(rcFile); | ||||
|     expect(rc['registry']).toBe('https://registry.npmjs.org/'); | ||||
|     expect(rc['always-auth']).toBe('false'); | ||||
|   }); | ||||
|  | ||||
|   it('Configures scoped npm registries', async () => { | ||||
|     process.env['INPUT_SCOPE'] = 'myScope'; | ||||
|     await auth.configAuthentication('https://registry.npmjs.org', 'false'); | ||||
|  | ||||
|     expect(fs.existsSync(rcFile)).toBe(true); | ||||
|     expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot(); | ||||
|     expect(fs.statSync(rcFile)).toBeDefined(); | ||||
|     let rc = readRcFile(rcFile); | ||||
|     expect(rc['@myscope:registry']).toBe('https://registry.npmjs.org/'); | ||||
|     expect(rc['always-auth']).toBe('false'); | ||||
|   }); | ||||
|  | ||||
|   it('Automatically configures GPR scope', async () => { | ||||
|     await auth.configAuthentication('npm.pkg.github.com', 'false'); | ||||
|  | ||||
|     expect(fs.existsSync(rcFile)).toBe(true); | ||||
|     expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot(); | ||||
|     expect(fs.statSync(rcFile)).toBeDefined(); | ||||
|     let rc = readRcFile(rcFile); | ||||
|     expect(rc['@ownername:registry']).toBe('npm.pkg.github.com/'); | ||||
|     expect(rc['always-auth']).toBe('false'); | ||||
|   }); | ||||
|  | ||||
|   it('Sets up npmrc for always-auth true', async () => { | ||||
|     await auth.configAuthentication('https://registry.npmjs.org/', 'true'); | ||||
|     expect(fs.existsSync(rcFile)).toBe(true); | ||||
|     expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot(); | ||||
|     expect(fs.statSync(rcFile)).toBeDefined(); | ||||
|     let rc = readRcFile(rcFile); | ||||
|     expect(rc['registry']).toBe('https://registry.npmjs.org/'); | ||||
|     expect(rc['always-auth']).toBe('true'); | ||||
|   }); | ||||
| }); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user