http2response.test.js
1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*jshint expr:true */
'use strict';
const Crawler = require('../lib/crawler');
const expect = require('chai').expect;
let c;
describe('request body', function () {
afterEach(function () {
c = {};
});
it('response statusCode', function (finishTest) {
c = new Crawler({
retryTimeout: 1000,
retries: 2,
jquery: false,
http2: true
});
c.queue({
uri: 'https://nghttp2.org/httpbin/status/200',
callback: (error, response, done) => {
expect(response.statusCode).to.equal(200);
done();
finishTest();
}
});
});
it('response headers', function (finishTest) {
c = new Crawler({
retryTimeout: 1000,
retries: 2,
jquery: false,
http2: true
});
c.queue({
uri: 'https://nghttp2.org/httpbin/status/200',
callback: (error, response, done) => {
expect(response.headers).to.exist;
expect(typeof response.headers).to.equal('object');
expect(response.headers['content-type']).to.equal('text/html; charset=utf-8');
done();
finishTest();
}
});
});
it('html response body', function (finishTest) {
c = new Crawler({
retryTimeout: 1000,
retries: 2,
jquery: true,
http2: true
});
c.queue({
uri: 'https://nghttp2.org/httpbin/html',
callback: (error, response, done) => {
const $ = response.$;
expect($).to.exist;
expect(typeof $).to.equal('function');
expect($('body').length).to.equal(1);
done();
finishTest();
}
});
});
});