|
@ -1,5 +1,5 @@ |
|
|
'use strict'; |
|
|
'use strict'; |
|
|
var tape = require('tape'); |
|
|
var test = require('tap').test; |
|
|
var got = require('../'); |
|
|
var got = require('../'); |
|
|
var server = require('./server.js'); |
|
|
var server = require('./server.js'); |
|
|
var s = server.createServer(); |
|
|
var s = server.createServer(); |
|
@ -23,13 +23,13 @@ s.on('/?recent=true', function (req, res) { |
|
|
res.end('recent'); |
|
|
res.end('recent'); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
tape('setup', function (t) { |
|
|
test('setup', function (t) { |
|
|
s.listen(s.port, function () { |
|
|
s.listen(s.port, function () { |
|
|
t.end(); |
|
|
t.end(); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
tape('callback mode', function (t) { |
|
|
test('callback mode', function (t) { |
|
|
got(s.url, function (err, data) { |
|
|
got(s.url, function (err, data) { |
|
|
t.error(err); |
|
|
t.error(err); |
|
|
t.equal(data, 'ok'); |
|
|
t.equal(data, 'ok'); |
|
@ -37,7 +37,7 @@ tape('callback mode', function (t) { |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
tape('protocol-less URLs', function (t) { |
|
|
test('protocol-less URLs', function (t) { |
|
|
got(s.url.replace(/^http:\/\//, ''), function (err, data) { |
|
|
got(s.url.replace(/^http:\/\//, ''), function (err, data) { |
|
|
t.error(err); |
|
|
t.error(err); |
|
|
t.equal(data, 'ok'); |
|
|
t.equal(data, 'ok'); |
|
@ -45,7 +45,7 @@ tape('protocol-less URLs', function (t) { |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
tape('empty response', function (t) { |
|
|
test('empty response', function (t) { |
|
|
got(s.url + '/empty', function (err, data) { |
|
|
got(s.url + '/empty', function (err, data) { |
|
|
t.error(err); |
|
|
t.error(err); |
|
|
t.equal(data, ''); |
|
|
t.equal(data, ''); |
|
@ -53,7 +53,7 @@ tape('empty response', function (t) { |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
tape('error with code', function (t) { |
|
|
test('error with code', function (t) { |
|
|
got(s.url + '/404', function (err, data) { |
|
|
got(s.url + '/404', function (err, data) { |
|
|
t.ok(err); |
|
|
t.ok(err); |
|
|
t.equal(err.code, 404); |
|
|
t.equal(err.code, 404); |
|
@ -62,7 +62,7 @@ tape('error with code', function (t) { |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
tape('buffer on encoding === null', function (t) { |
|
|
test('buffer on encoding === null', function (t) { |
|
|
got(s.url, {encoding: null}, function (err, data) { |
|
|
got(s.url, {encoding: null}, function (err, data) { |
|
|
t.error(err); |
|
|
t.error(err); |
|
|
t.ok(Buffer.isBuffer(data)); |
|
|
t.ok(Buffer.isBuffer(data)); |
|
@ -70,7 +70,7 @@ tape('buffer on encoding === null', function (t) { |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
tape('stream mode', function (t) { |
|
|
test('stream mode', function (t) { |
|
|
got(s.url) |
|
|
got(s.url) |
|
|
.on('data', function (data) { |
|
|
.on('data', function (data) { |
|
|
t.equal(data.toString(), 'ok'); |
|
|
t.equal(data.toString(), 'ok'); |
|
@ -78,7 +78,7 @@ tape('stream mode', function (t) { |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
tape('emit response object to stream', function (t) { |
|
|
test('emit response object to stream', function (t) { |
|
|
got(s.url) |
|
|
got(s.url) |
|
|
.on('response', function (res) { |
|
|
.on('response', function (res) { |
|
|
t.ok(res); |
|
|
t.ok(res); |
|
@ -87,7 +87,7 @@ tape('emit response object to stream', function (t) { |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
tape('proxy errors to the stream', function (t) { |
|
|
test('proxy errors to the stream', function (t) { |
|
|
got(s.url + '/404') |
|
|
got(s.url + '/404') |
|
|
.on('error', function (err, data, res) { |
|
|
.on('error', function (err, data, res) { |
|
|
t.equal(err.code, 404); |
|
|
t.equal(err.code, 404); |
|
@ -97,7 +97,7 @@ tape('proxy errors to the stream', function (t) { |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
tape('timeout option', function (t) { |
|
|
test('timeout option', function (t) { |
|
|
got(s.url + '/404', {timeout: 1}) |
|
|
got(s.url + '/404', {timeout: 1}) |
|
|
.on('error', function (err) { |
|
|
.on('error', function (err) { |
|
|
t.equal(err.code, 'ETIMEDOUT'); |
|
|
t.equal(err.code, 'ETIMEDOUT'); |
|
@ -105,7 +105,7 @@ tape('timeout option', function (t) { |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
tape('query option', function (t) { |
|
|
test('query option', function (t) { |
|
|
t.plan(2); |
|
|
t.plan(2); |
|
|
|
|
|
|
|
|
got(s.url, {query: {recent: true}}, function (err, data) { |
|
|
got(s.url, {query: {recent: true}}, function (err, data) { |
|
@ -117,7 +117,7 @@ tape('query option', function (t) { |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
tape('cleanup', function (t) { |
|
|
test('cleanup', function (t) { |
|
|
s.close(); |
|
|
s.close(); |
|
|
t.end(); |
|
|
t.end(); |
|
|
}); |
|
|
}); |
|
|