mirror of
				https://kkgithub.com/actions/checkout
				synced 2025-10-31 22:31:56 +08:00 
			
		
		
		
	url-helper.ts now leverages well-known environment variables. (#1941)
				
					
				
			* `utl-helper.ts` now leverages well-known environment variables. --------- Co-authored-by: Erez Testiler <easyt@github.com>
This commit is contained in:
		 John Wesley Walker III
					John Wesley Walker III
				
			
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			 GitHub
						GitHub
					
				
			
						parent
						
							eef61447b9
						
					
				
				
					commit
					163217dfcd
				
			
							
								
								
									
										55
									
								
								__test__/url-helper.test.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								__test__/url-helper.test.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,55 @@ | ||||
| import * as urlHelper from '../src/url-helper' | ||||
|  | ||||
| describe('getServerUrl tests', () => { | ||||
|   it('basics', async () => { | ||||
|     // Note that URL::toString will append a trailing / when passed just a domain name ... | ||||
|     expect(urlHelper.getServerUrl().toString()).toBe('https://github.com/') | ||||
|     expect(urlHelper.getServerUrl(' ').toString()).toBe('https://github.com/') | ||||
|     expect(urlHelper.getServerUrl('   ').toString()).toBe('https://github.com/') | ||||
|     expect(urlHelper.getServerUrl('http://contoso.com').toString()).toBe( | ||||
|       'http://contoso.com/' | ||||
|     ) | ||||
|     expect(urlHelper.getServerUrl('https://contoso.com').toString()).toBe( | ||||
|       'https://contoso.com/' | ||||
|     ) | ||||
|     expect(urlHelper.getServerUrl('https://contoso.com/').toString()).toBe( | ||||
|       'https://contoso.com/' | ||||
|     ) | ||||
|  | ||||
|     // ... but can't make that same assumption when passed an URL that includes some deeper path. | ||||
|     expect(urlHelper.getServerUrl('https://contoso.com/a/b').toString()).toBe( | ||||
|       'https://contoso.com/a/b' | ||||
|     ) | ||||
|   }) | ||||
| }) | ||||
|  | ||||
| describe('isGhes tests', () => { | ||||
|   it('basics', async () => { | ||||
|     expect(urlHelper.isGhes()).toBeFalsy() | ||||
|     expect(urlHelper.isGhes('https://github.com')).toBeFalsy() | ||||
|     expect(urlHelper.isGhes('https://contoso.ghe.com')).toBeFalsy() | ||||
|     expect(urlHelper.isGhes('https://test.github.localhost')).toBeFalsy() | ||||
|     expect(urlHelper.isGhes('https://src.onpremise.fabrikam.com')).toBeTruthy() | ||||
|   }) | ||||
| }) | ||||
|  | ||||
| describe('getServerApiUrl tests', () => { | ||||
|   it('basics', async () => { | ||||
|     expect(urlHelper.getServerApiUrl()).toBe('https://api.github.com') | ||||
|     expect(urlHelper.getServerApiUrl('https://github.com')).toBe( | ||||
|       'https://api.github.com' | ||||
|     ) | ||||
|     expect(urlHelper.getServerApiUrl('https://GitHub.com')).toBe( | ||||
|       'https://api.github.com' | ||||
|     ) | ||||
|     expect(urlHelper.getServerApiUrl('https://contoso.ghe.com')).toBe( | ||||
|       'https://api.contoso.ghe.com' | ||||
|     ) | ||||
|     expect(urlHelper.getServerApiUrl('https://fabrikam.GHE.COM')).toBe( | ||||
|       'https://api.fabrikam.ghe.com' | ||||
|     ) | ||||
|     expect( | ||||
|       urlHelper.getServerApiUrl('https://src.onpremise.fabrikam.com') | ||||
|     ).toBe('https://src.onpremise.fabrikam.com/api/v3') | ||||
|   }) | ||||
| }) | ||||
		Reference in New Issue
	
	Block a user