http-client/__tests__/keepalive.test.ts

66 lines
2.4 KiB
TypeScript
Raw Normal View History

2020-01-12 02:23:55 +00:00
import * as httpm from '../_out';
2020-01-09 23:32:59 +00:00
describe('basics', () => {
let _http: httpm.HttpClient;
beforeEach(() => {
2020-01-10 03:17:08 +00:00
_http = new httpm.HttpClient('http-client-tests', [], { keepAlive: true });
2020-01-09 23:32:59 +00:00
})
afterEach(() => {
2020-01-10 03:17:08 +00:00
_http.dispose();
2020-01-09 23:32:59 +00:00
})
2020-01-10 03:17:08 +00:00
it('does basic http get request with keepAlive true', async(done) => {
2020-01-09 23:32:59 +00:00
let res: httpm.HttpClientResponse = await _http.get('http://httpbin.org/get');
expect(res.message.statusCode).toBe(200);
let body: string = await res.readBody();
let obj:any = JSON.parse(body);
2020-01-23 14:25:39 +00:00
expect(obj.url).toBe("http://httpbin.org/get");
2020-01-10 03:17:08 +00:00
done();
2020-01-09 23:32:59 +00:00
});
2020-01-10 03:17:08 +00:00
it('does basic head request with keepAlive true', async(done) => {
2020-01-09 23:32:59 +00:00
let res: httpm.HttpClientResponse = await _http.head('http://httpbin.org/get');
expect(res.message.statusCode).toBe(200);
2020-01-10 03:17:08 +00:00
done();
2020-01-09 23:32:59 +00:00
});
2020-01-10 03:17:08 +00:00
it('does basic http delete request with keepAlive true', async(done) => {
2020-01-09 23:32:59 +00:00
let res: httpm.HttpClientResponse = await _http.del('http://httpbin.org/delete');
expect(res.message.statusCode).toBe(200);
let body: string = await res.readBody();
let obj:any = JSON.parse(body);
2020-01-10 03:17:08 +00:00
done();
2020-01-09 23:32:59 +00:00
});
2020-01-10 03:17:08 +00:00
it('does basic http post request with keepAlive true', async(done) => {
2020-01-09 23:32:59 +00:00
let b: string = 'Hello World!';
let res: httpm.HttpClientResponse = await _http.post('http://httpbin.org/post', b);
expect(res.message.statusCode).toBe(200);
let body: string = await res.readBody();
let obj:any = JSON.parse(body);
expect(obj.data).toBe(b);
2020-01-23 14:25:39 +00:00
expect(obj.url).toBe("http://httpbin.org/post");
2020-01-10 03:17:08 +00:00
done();
2020-01-09 23:32:59 +00:00
});
2020-01-10 03:17:08 +00:00
it('does basic http patch request with keepAlive true', async(done) => {
2020-01-09 23:32:59 +00:00
let b: string = 'Hello World!';
let res: httpm.HttpClientResponse = await _http.patch('http://httpbin.org/patch', b);
expect(res.message.statusCode).toBe(200);
let body: string = await res.readBody();
let obj:any = JSON.parse(body);
expect(obj.data).toBe(b);
2020-01-23 14:25:39 +00:00
expect(obj.url).toBe("http://httpbin.org/patch");
2020-01-10 03:17:08 +00:00
done();
2020-01-09 23:32:59 +00:00
});
2020-01-10 03:17:08 +00:00
it('does basic http options request with keepAlive true', async(done) => {
2020-01-09 23:32:59 +00:00
let res: httpm.HttpClientResponse = await _http.options('http://httpbin.org');
expect(res.message.statusCode).toBe(200);
let body: string = await res.readBody();
2020-01-10 03:17:08 +00:00
done();
2020-01-09 23:32:59 +00:00
});
});