mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-03 10:38:03 +08:00
feat: got request timeout
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
process.env.REQUEST_TIMEOUT = '500';
|
||||
const got = require('../../lib/utils/got');
|
||||
const config = require('../../lib/config').value;
|
||||
const nock = require('nock');
|
||||
|
||||
afterAll(() => {
|
||||
delete process.env.REQUEST_TIMEOUT;
|
||||
});
|
||||
|
||||
describe('got', () => {
|
||||
it('headers', async () => {
|
||||
nock('http://rsshub.test')
|
||||
@@ -51,4 +56,20 @@ describe('got', () => {
|
||||
expect(response1.body).toBe('{"code": 0}');
|
||||
expect(response1.data.code).toBe(0);
|
||||
});
|
||||
|
||||
it('timeout', async () => {
|
||||
nock('http://rsshub.test')
|
||||
.get('/timeout')
|
||||
.delay(600)
|
||||
.reply(function () {
|
||||
return [200, '{"code": 0}'];
|
||||
});
|
||||
|
||||
try {
|
||||
await got.get('http://rsshub.test/timeout');
|
||||
throw Error('Timeout Invalid');
|
||||
} catch (error) {
|
||||
expect(error.name).toBe('RequestError');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user