mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-05 12:21:31 +08:00
test: got axios options
This commit is contained in:
@@ -69,21 +69,12 @@ const custom = got.extend({
|
||||
return response;
|
||||
},
|
||||
],
|
||||
onError: [
|
||||
(error) => {
|
||||
error.response.status = error.response.statusCode;
|
||||
return error;
|
||||
},
|
||||
],
|
||||
init: [
|
||||
(options) => {
|
||||
// compatible with axios api
|
||||
if (options.data) {
|
||||
options.body = options.body || options.data;
|
||||
}
|
||||
if (options.responseType === 'buffer') {
|
||||
options.encoding = null;
|
||||
}
|
||||
if (options.params) {
|
||||
options.query = options.query || queryString.stringify(options.params);
|
||||
options.searchParams = options.query; // for Got v11 after
|
||||
|
||||
@@ -121,9 +121,9 @@ describe('empty', () => {
|
||||
|
||||
describe('allow_empty', () => {
|
||||
it(`allow_empty`, async () => {
|
||||
const response1 = await request.get('/test/allow_empty');
|
||||
expect(response1.status).toBe(200);
|
||||
const parsed = await parser.parseString(response1.text);
|
||||
const response = await request.get('/test/allow_empty');
|
||||
expect(response.status).toBe(200);
|
||||
const parsed = await parser.parseString(response.text);
|
||||
expect(parsed.items.length).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17,17 +17,10 @@ describe('got', () => {
|
||||
.reply(function() {
|
||||
expect(this.req.headers['user-agent']).toBe(config.ua);
|
||||
expect(this.req.headers['x-app']).toBe('RSSHub');
|
||||
return [
|
||||
200,
|
||||
{
|
||||
code: 0,
|
||||
},
|
||||
];
|
||||
return [200, ''];
|
||||
});
|
||||
|
||||
const response = await got.get('http://rsshub.test/test');
|
||||
expect(response.status).toBe(200);
|
||||
expect(response.data.code).toBe(0);
|
||||
await got.get('http://rsshub.test/test');
|
||||
});
|
||||
|
||||
it('retry', async () => {
|
||||
@@ -44,12 +37,7 @@ describe('got', () => {
|
||||
expect(now - requestTime).toBeLessThan(120);
|
||||
}
|
||||
requestTime = new Date();
|
||||
return [
|
||||
404,
|
||||
{
|
||||
code: 1,
|
||||
},
|
||||
];
|
||||
return [404, '0'];
|
||||
});
|
||||
|
||||
try {
|
||||
@@ -62,6 +50,38 @@ describe('got', () => {
|
||||
expect(requestRun).toHaveBeenCalledTimes(config.requestRetry);
|
||||
});
|
||||
|
||||
it('axios', async () => {
|
||||
nock('http://rsshub.test')
|
||||
.post('/post')
|
||||
.reply(function() {
|
||||
return [200, '{"code": 0}'];
|
||||
});
|
||||
|
||||
const response1 = await got.post('http://rsshub.test/post', {
|
||||
form: true,
|
||||
data: {
|
||||
test: 1,
|
||||
},
|
||||
});
|
||||
expect(response1.statusCode).toBe(200);
|
||||
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,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('proxy socks', async () => {
|
||||
process.env.PROXY_PROTOCOL = 'socks';
|
||||
process.env.PROXY_HOST = 'rsshub.proxy';
|
||||
|
||||
Reference in New Issue
Block a user