chore: bump got from 9.x to 10.x (#3875)

This commit is contained in:
DIYgod
2020-02-04 01:09:14 +08:00
committed by GitHub
parent 4be7802b27
commit 77d55262ff
99 changed files with 483 additions and 445 deletions
+4 -27
View File
@@ -16,29 +16,22 @@ describe('got', () => {
it('retry', async () => {
const requestRun = jest.fn();
let requestTime;
nock('http://rsshub.test')
.get('/testRerty')
.times(config.requestRetry + 1)
.reply(function() {
requestRun();
const now = new Date();
if (requestTime) {
expect(now - requestTime).toBeGreaterThanOrEqual(100);
expect(now - requestTime).toBeLessThan(120);
}
requestTime = new Date();
return [404, '0'];
});
try {
await got.get('http://rsshub.test/testRerty');
} catch (error) {
expect(error.name).toBe('RequestError');
expect(error.name).toBe('HTTPError');
}
// retries
expect(requestRun).toHaveBeenCalledTimes(config.requestRetry);
expect(requestRun).toHaveBeenCalledTimes(config.requestRetry + 1);
});
it('axios', async () => {
@@ -48,10 +41,8 @@ describe('got', () => {
return [200, '{"code": 0}'];
});
const response1 = await got.post('post', {
baseUrl: 'http://rsshub.test/',
form: true,
data: {
const response1 = await got.post('http://rsshub.test/post', {
form: {
test: 1,
},
});
@@ -59,19 +50,5 @@ describe('got', () => {
expect(response1.status).toBe(200);
expect(response1.body).toBe('{"code": 0}');
expect(response1.data.code).toBe(0);
nock('http://rsshub.test')
.get(/^\/params/)
.reply(function() {
expect(this.req.path).toBe('/params?test=1');
return [200, ''];
});
await got.get('http://rsshub.test/params', {
params: {
test: 1,
},
responseType: 'buffer',
});
});
});
+16 -20
View File
@@ -21,7 +21,11 @@ afterEach(() => {
const origin = func;
return function(url, request) {
if (typeof url === 'object') {
check(url);
if (url instanceof URL) {
check(request);
} else {
check(url);
}
} else {
check(request);
}
@@ -34,26 +38,18 @@ afterEach(() => {
describe('got', () => {
it('headers', async () => {
nock('http://rsshub.test')
nock(/rsshub\.test/)
.get(/.*/)
.times(3)
.times(4)
.reply(function() {
expect(this.req.headers.server).toBe('RSSHub');
expect(this.req.headers.referer).toBe('http://www.rsshub.test');
return [200, simpleResponse];
});
nock(/rsshub\.test/)
.get(/.*/)
.times(2)
.reply(function() {
expect(this.req.headers.referer).toBe('https://www.rsshub.test');
return [200, simpleResponse];
});
await got.get('http://rsshub.test/test');
await got.get('http://rsshub.test');
await got.get('rsshub.test/test');
await got.get('api.rsshub.test/test');
await got.get('http://api.rsshub.test/test');
await parser.parseURL('http://rsshub.test/test');
});
@@ -67,10 +63,10 @@ describe('got', () => {
require('../../lib/utils/request-wrapper');
check = (request) => {
expect(request.agent.constructor.name).toBe('SocksProxyAgent');
expect(request.agent.options.href).toBe('socks://rsshub.proxy:2333');
expect(request.agent.proxy.href).toBe('socks://rsshub.proxy:2333');
};
nock('http://rsshub.test')
nock(/rsshub\.test/)
.get('/proxy')
.times(2)
.reply(200, simpleResponse);
@@ -92,7 +88,7 @@ describe('got', () => {
expect(request.agent.options.proxy.port).toBe(2333);
};
nock('http://rsshub.test')
nock(/rsshub\.test/)
.get('/proxy')
.times(2)
.reply(200, simpleResponse);
@@ -114,7 +110,7 @@ describe('got', () => {
expect(request.agent.options.proxy.port).toBe(2333);
};
nock('http://rsshub.test')
nock(/rsshub\.test/)
.get('/proxy')
.times(2)
.reply(200, simpleResponse);
@@ -132,7 +128,7 @@ describe('got', () => {
jest.resetModules();
require('../../lib/utils/request-wrapper');
nock('http://rsshub.test')
nock(/rsshub\.test/)
.get('/auth')
.times(2)
.reply(function() {
@@ -155,17 +151,17 @@ describe('got', () => {
check = (request) => {
if (request.path === '/url_regex') {
expect(request.agent.constructor.name).toBe('SocksProxyAgent');
expect(request.agent.options.href).toBe('socks://rsshub.proxy:2333');
expect(request.agent.proxy.href).toBe('socks://rsshub.proxy:2333');
} else if (request.path === '/proxy') {
expect(request.agent).toBe(undefined);
}
};
nock('http://rsshub.test')
nock(/rsshub\.test/)
.get('/url_regex')
.times(2)
.reply(() => [200, simpleResponse]);
nock('http://rsshub.test')
nock(/rsshub\.test/)
.get('/proxy')
.times(2)
.reply(() => [200, simpleResponse]);