mirror of
				https://github.com/shivammathur/setup-php.git
				synced 2025-11-04 08:56:36 +07:00 
			
		
		
		
	Update Node.js dependencies Migrate eslint config to a mjs file Fix imports in tests Bump to Node.js 20.x in workflows
		
			
				
	
	
		
			40 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			40 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
import * as fetch from '../src/fetch';
 | 
						|
import nock from 'nock';
 | 
						|
 | 
						|
it('checking fetch', async () => {
 | 
						|
  const host_url = 'https://example.com';
 | 
						|
  const manifest_url = host_url + '/manifest';
 | 
						|
  const ping_url = host_url + '/ping';
 | 
						|
 | 
						|
  nock(host_url)
 | 
						|
    .get('/manifest')
 | 
						|
    .reply(200, {latest: 'latest'})
 | 
						|
    .get('/manifest', '', {
 | 
						|
      reqheaders: {authorization: 'Bearer invalid_token'}
 | 
						|
    })
 | 
						|
    .reply(401, {error: '401: Unauthorized'})
 | 
						|
    .get('/ping')
 | 
						|
    .twice()
 | 
						|
    .reply(301, undefined, {
 | 
						|
      Location: host_url + '/pong'
 | 
						|
    })
 | 
						|
    .get('/pong')
 | 
						|
    .reply(200, 'pong');
 | 
						|
 | 
						|
  let response: Record<string, string> = await fetch.fetch(manifest_url);
 | 
						|
  expect(response.error).toBe(undefined);
 | 
						|
  expect(response.data).toContain('latest');
 | 
						|
 | 
						|
  response = await fetch.fetch(ping_url, '', 1);
 | 
						|
  expect(response.error).toBe(undefined);
 | 
						|
  expect(response.data).toContain('pong');
 | 
						|
 | 
						|
  response = await fetch.fetch(ping_url, '', 0);
 | 
						|
  expect(response.error).toBe('301: Redirect error');
 | 
						|
  expect(response.data).toBe(undefined);
 | 
						|
 | 
						|
  response = await fetch.fetch(manifest_url, 'invalid_token');
 | 
						|
  expect(response.error).not.toBe(undefined);
 | 
						|
  expect(response.data).toBe(undefined);
 | 
						|
});
 |