Browse Source

catch errors in the tests

http2
Sindre Sorhus 10 years ago
parent
commit
ebf303a8d5
  1. 9
      test/test-headers.js
  2. 4
      test/test-http.js
  3. 2
      test/test-https.js
  4. 13
      test/test-post.js

9
test/test-headers.js

@ -16,6 +16,8 @@ test('setup', function (t) {
test('send user-agent header by default', function (t) {
got(s.url, function (err, data) {
t.error(err);
var headers = JSON.parse(data);
t.equal(headers['user-agent'], 'https://github.com/sindresorhus/got');
@ -25,6 +27,8 @@ test('send user-agent header by default', function (t) {
test('send accept-encoding header by default', function (t) {
got(s.url, function (err, data) {
t.error(err);
var headers = JSON.parse(data);
t.equal(headers['accept-encoding'], 'gzip,deflate');
@ -34,6 +38,7 @@ test('send accept-encoding header by default', function (t) {
test('send accept header with json option', function (t) {
got(s.url, {json: true}, function (err, headers) {
t.error(err);
t.equal(headers.accept, 'application/json');
t.end();
});
@ -41,6 +46,8 @@ test('send accept header with json option', function (t) {
test('send host header by default', function (t) {
got(s.url, function (err, data) {
t.error(err);
var headers = JSON.parse(data);
t.equal(headers.host, 'localhost:' + s.port);
@ -50,6 +57,8 @@ test('send host header by default', function (t) {
test('transform headers names to lowercase', function (t) {
got(s.url, {headers: {'USER-AGENT': 'test'}}, function (err, data) {
t.error(err);
var headers = JSON.parse(data);
t.equal(headers['user-agent'], 'test');

4
test/test-http.js

@ -78,13 +78,15 @@ test('timeout option', function (t) {
});
test('query option', function (t) {
t.plan(2);
t.plan(4);
got(s.url, {query: {recent: true}}, function (err, data) {
t.error(err);
t.equal(data, 'recent');
});
got(s.url, {query: 'recent=true'}, function (err, data) {
t.error(err);
t.equal(data, 'recent');
});
});

2
test/test-https.js

@ -15,6 +15,7 @@ test('root pem', function (t) {
days: 1,
selfSigned: true
}, function (err, keys) {
t.error(err);
caRootKey = keys.serviceKey;
caRootCert = keys.certificate;
t.end();
@ -34,6 +35,7 @@ test('pem', function (t) {
organizationUnit: '',
commonName: 'sindresorhus.com'
}, function (err, keys) {
t.error(err);
key = keys.clientKey;
cert = keys.certificate;
t.end();

13
test/test-post.js

@ -45,48 +45,57 @@ test('GET can have body', function (t) {
});
test('send data from options with post request', function (t) {
t.plan(3);
t.plan(6);
got(s.url, {body: 'wow'}, function (err, data) {
t.error(err);
t.equal(data, 'wow');
});
got(s.url, {body: new Buffer('wow')}, function (err, data) {
t.error(err);
t.equal(data, 'wow');
});
got(s.url, {body: from2Array(['wow'])}, function (err, data) {
t.error(err);
t.equal(data, 'wow');
});
});
test('works with empty post response', function (t) {
got(s.url + '/empty', {body: 'wow'}, function (err, data) {
t.error(err);
t.equal(data, '');
t.end();
});
});
test('post have content-length header to string', function (t) {
t.plan(5);
t.plan(10);
got(s.url + '/headers', {body: 'wow', json: true}, function (err, headers) {
t.error(err);
t.equal(headers['content-length'], '3');
});
got(s.url + '/headers', {body: new Buffer('wow'), json: true}, function (err, headers) {
t.error(err);
t.equal(headers['content-length'], '3');
});
got(s.url + '/headers', {body: from2Array(['wow']), json: true}, function (err, headers) {
t.error(err);
t.equal(headers['content-length'], undefined);
});
got(s.url + '/headers', {body: 'wow', json: true, headers: {'content-length': '10'}}, function (err, headers) {
t.error(err);
t.equal(headers['content-length'], '10');
});
got(s.url + '/headers', {body: '3\r\nwow\r\n0\r\n', json: true, headers: {'transfer-encoding': 'chunked'}}, function (err, headers) {
t.error(err);
t.equal(headers['content-length'], undefined);
});
});

Loading…
Cancel
Save