Browse Source

Merge pull request #65 from sindresorhus/tap

Use node-tap for tests
http2
Sindre Sorhus 10 years ago
parent
commit
ad6c4a49e9
  1. 5
      package.json
  2. 12
      test/test-arguments.js
  3. 12
      test/test-error.js
  4. 12
      test/test-gzip.js
  5. 16
      test/test-headers.js
  6. 10
      test/test-helpers.js
  7. 26
      test/test-http.js
  8. 14
      test/test-https.js
  9. 16
      test/test-json.js
  10. 18
      test/test-post.js
  11. 20
      test/test-redirects.js

5
package.json

@ -20,7 +20,7 @@
"node": ">=0.10.0" "node": ">=0.10.0"
}, },
"scripts": { "scripts": {
"test": "tape test/test-*.js | tap-dot", "test": "tap test/test-*.js",
"coverage": "istanbul cover tape --report html -- test/test-*.js" "coverage": "istanbul cover tape --report html -- test/test-*.js"
}, },
"files": [ "files": [
@ -57,7 +57,6 @@
"from2-array": "0.0.3", "from2-array": "0.0.3",
"istanbul": "^0.3.13", "istanbul": "^0.3.13",
"pem": "^1.4.4", "pem": "^1.4.4",
"tap-dot": "^1.0.0", "tap": "^1.0.0"
"tape": "^3.5.0"
} }
} }

12
test/test-arguments.js

@ -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();
@ -12,20 +12,20 @@ s.on('/?test=wow', function (req, res) {
res.end(req.url); res.end(req.url);
}); });
tape('setup', function (t) { test('setup', function (t) {
s.listen(s.port, function () { s.listen(s.port, function () {
t.end(); t.end();
}); });
}); });
tape('url argument is required', function (t) { test('url argument is required', function (t) {
t.throws(function () { t.throws(function () {
got(); got();
}, /Parameter `url` must be a string or object, not undefined/); }, /Parameter `url` must be a string or object, not undefined/);
t.end(); t.end();
}); });
tape('accepts url.parse object as first argument', function (t) { test('accepts url.parse object as first argument', function (t) {
got({host: s.host, port: s.port, path: '/test'}, function (err, data) { got({host: s.host, port: s.port, path: '/test'}, function (err, data) {
t.error(err); t.error(err);
t.equal(data, '/test'); t.equal(data, '/test');
@ -33,7 +33,7 @@ tape('accepts url.parse object as first argument', function (t) {
}); });
}); });
tape('overrides querystring from opts', function (t) { test('overrides querystring from opts', function (t) {
got(s.url + '/?test=doge', {query: {test: 'wow'}}, function (err, data) { got(s.url + '/?test=doge', {query: {test: 'wow'}}, function (err, data) {
t.error(err); t.error(err);
t.equal(data, '/?test=wow'); t.equal(data, '/?test=wow');
@ -41,7 +41,7 @@ tape('overrides querystring from opts', function (t) {
}); });
}); });
tape('cleanup', function (t) { test('cleanup', function (t) {
s.close(); s.close();
t.end(); t.end();
}); });

12
test/test-error.js

@ -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();
@ -9,13 +9,13 @@ s.on('/', function (req, res) {
res.end('not'); res.end('not');
}); });
tape('setup', function (t) { test('setup', function (t) {
s.listen(s.port, function () { s.listen(s.port, function () {
t.end(); t.end();
}); });
}); });
tape('error message', function (t) { test('error message', function (t) {
got(s.url, function (err) { got(s.url, function (err) {
t.ok(err); t.ok(err);
t.equal(err.message, 'GET http://localhost:6767 response code is 404 (Not Found)'); t.equal(err.message, 'GET http://localhost:6767 response code is 404 (Not Found)');
@ -23,7 +23,7 @@ tape('error message', function (t) {
}); });
}); });
tape('dns error message', function (t) { test('dns error message', function (t) {
got('.com', function (err) { got('.com', function (err) {
t.ok(err); t.ok(err);
t.equal(err.message, 'Request to http://.com failed'); t.equal(err.message, 'Request to http://.com failed');
@ -33,14 +33,14 @@ tape('dns error message', function (t) {
}); });
}); });
tape('options.body error message', function (t) { test('options.body error message', function (t) {
t.throws(function () { t.throws(function () {
got(s.url, {body: {}}); got(s.url, {body: {}});
}, /options.body must be a ReadableStream, string or Buffer/); }, /options.body must be a ReadableStream, string or Buffer/);
t.end(); t.end();
}); });
tape('cleanup', function (t) { test('cleanup', function (t) {
s.close(); s.close();
t.end(); t.end();
}); });

12
test/test-gzip.js

@ -1,6 +1,6 @@
'use strict'; 'use strict';
var zlib = require('zlib'); var zlib = require('zlib');
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();
@ -22,13 +22,13 @@ s.on('/corrupted', function (req, res) {
res.end('Not gzipped content'); res.end('Not gzipped content');
}); });
tape('setup', function (t) { test('setup', function (t) {
s.listen(s.port, function () { s.listen(s.port, function () {
t.end(); t.end();
}); });
}); });
tape('ungzip content', function (t) { test('ungzip content', function (t) {
got(s.url, function (err, data) { got(s.url, function (err, data) {
t.error(err); t.error(err);
t.equal(data, testContent); t.equal(data, testContent);
@ -36,7 +36,7 @@ tape('ungzip content', function (t) {
}); });
}); });
tape('ungzip error', function (t) { test('ungzip error', function (t) {
got(s.url + '/corrupted', function (err) { got(s.url + '/corrupted', function (err) {
t.ok(err); t.ok(err);
t.equal(err.message, 'Reading ' + s.url + '/corrupted response failed'); t.equal(err.message, 'Reading ' + s.url + '/corrupted response failed');
@ -44,7 +44,7 @@ tape('ungzip error', function (t) {
}); });
}); });
tape('preserve headers property', function (t) { test('preserve headers property', function (t) {
got(s.url, function (err, data, res) { got(s.url, function (err, data, res) {
t.error(err); t.error(err);
t.ok(res.headers); t.ok(res.headers);
@ -52,7 +52,7 @@ tape('preserve headers property', function (t) {
}); });
}); });
tape('cleanup', function (t) { test('cleanup', function (t) {
s.close(); s.close();
t.end(); t.end();
}); });

16
test/test-headers.js

@ -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();
@ -8,13 +8,13 @@ s.on('/', function (req, res) {
res.end(JSON.stringify(req.headers)); res.end(JSON.stringify(req.headers));
}); });
tape('setup', function (t) { test('setup', function (t) {
s.listen(s.port, function () { s.listen(s.port, function () {
t.end(); t.end();
}); });
}); });
tape('send user-agent header by default', function (t) { test('send user-agent header by default', function (t) {
got(s.url, function (err, data) { got(s.url, function (err, data) {
var headers = JSON.parse(data); var headers = JSON.parse(data);
@ -23,7 +23,7 @@ tape('send user-agent header by default', function (t) {
}); });
}); });
tape('send accept-encoding header by default', function (t) { test('send accept-encoding header by default', function (t) {
got(s.url, function (err, data) { got(s.url, function (err, data) {
var headers = JSON.parse(data); var headers = JSON.parse(data);
@ -32,14 +32,14 @@ tape('send accept-encoding header by default', function (t) {
}); });
}); });
tape('send accept header with json option', function (t) { test('send accept header with json option', function (t) {
got(s.url, {json: true}, function (err, headers) { got(s.url, {json: true}, function (err, headers) {
t.equal(headers.accept, 'application/json'); t.equal(headers.accept, 'application/json');
t.end(); t.end();
}); });
}); });
tape('send host header by default', function (t) { test('send host header by default', function (t) {
got(s.url, function (err, data) { got(s.url, function (err, data) {
var headers = JSON.parse(data); var headers = JSON.parse(data);
@ -48,7 +48,7 @@ tape('send host header by default', function (t) {
}); });
}); });
tape('transform headers names to lowercase', function (t) { test('transform headers names to lowercase', function (t) {
got(s.url, {headers: {'USER-AGENT': 'test'}}, function (err, data) { got(s.url, {headers: {'USER-AGENT': 'test'}}, function (err, data) {
var headers = JSON.parse(data); var headers = JSON.parse(data);
@ -57,7 +57,7 @@ tape('transform headers names to lowercase', function (t) {
}); });
}); });
tape('cleanup', function (t) { test('cleanup', function (t) {
s.close(); s.close();
t.end(); t.end();
}); });

10
test/test-helpers.js

@ -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();
@ -8,13 +8,13 @@ s.on('/', function (req, res) {
res.end('ok'); res.end('ok');
}); });
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', {timeout: 1000}, function (t) { test('callback mode', {timeout: 1000}, function (t) {
got.get(s.url, function (err, data) { got.get(s.url, function (err, data) {
t.error(err); t.error(err);
t.equal(data, 'ok'); t.equal(data, 'ok');
@ -22,7 +22,7 @@ tape('callback mode', {timeout: 1000}, function (t) {
}); });
}); });
tape('stream mode', {timeout: 1000}, function (t) { test('stream mode', {timeout: 1000}, function (t) {
got.get(s.url) got.get(s.url)
.on('data', function (data) { .on('data', function (data) {
t.equal(data.toString(), 'ok'); t.equal(data.toString(), 'ok');
@ -30,7 +30,7 @@ tape('stream mode', {timeout: 1000}, function (t) {
}); });
}); });
tape('cleanup', function (t) { test('cleanup', function (t) {
s.close(); s.close();
t.end(); t.end();
}); });

26
test/test-http.js

@ -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();
}); });

14
test/test-https.js

@ -1,5 +1,5 @@
'use strict'; 'use strict';
var tape = require('tape'); var test = require('tap').test;
var pem = require('pem'); var pem = require('pem');
var got = require('../'); var got = require('../');
var server = require('./server.js'); var server = require('./server.js');
@ -10,7 +10,7 @@ var cert;
var caRootKey; var caRootKey;
var caRootCert; var caRootCert;
tape('root pem', function (t) { test('root pem', function (t) {
pem.createCertificate({ pem.createCertificate({
days: 1, days: 1,
selfSigned: true selfSigned: true
@ -21,7 +21,7 @@ tape('root pem', function (t) {
}); });
}); });
tape('pem', function (t) { test('pem', function (t) {
pem.createCertificate({ pem.createCertificate({
serviceCertificate: caRootCert, serviceCertificate: caRootCert,
serviceKey: caRootKey, serviceKey: caRootKey,
@ -40,7 +40,7 @@ tape('pem', function (t) {
}); });
}); });
tape('setup', function (t) { test('setup', function (t) {
s = server.createSSLServer(server.portSSL + 1, { s = server.createSSLServer(server.portSSL + 1, {
key: key, key: key,
cert: cert cert: cert
@ -55,7 +55,7 @@ tape('setup', function (t) {
}); });
}); });
tape('make request to https server', function (t) { test('make request to https server', function (t) {
got('https://google.com', { got('https://google.com', {
strictSSL: true strictSSL: true
}, function (err, data) { }, function (err, data) {
@ -65,7 +65,7 @@ tape('make request to https server', function (t) {
}); });
}); });
tape('make request to https server with ca', function (t) { test('make request to https server with ca', function (t) {
got(s.url, { got(s.url, {
strictSSL: true, strictSSL: true,
ca: caRootCert, ca: caRootCert,
@ -77,7 +77,7 @@ tape('make request to https server with ca', function (t) {
}); });
}); });
tape('cleanup', function (t) { test('cleanup', function (t) {
s.close(); s.close();
t.end(); t.end();
}); });

16
test/test-json.js

@ -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();
@ -22,20 +22,20 @@ s.on('/non200-invalid', function (req, res) {
res.end('Internal error'); res.end('Internal error');
}); });
tape('setup', function (t) { test('setup', function (t) {
s.listen(s.port, function () { s.listen(s.port, function () {
t.end(); t.end();
}); });
}); });
tape('json option can not be used in stream mode', function (t) { test('json option can not be used in stream mode', function (t) {
t.throws(function () { t.throws(function () {
got(s.url, {json: true}); got(s.url, {json: true});
}, 'got can not be used as stream when options.json is used'); }, 'got can not be used as stream when options.json is used');
t.end(); t.end();
}); });
tape('json option should parse response', function (t) { test('json option should parse response', function (t) {
got(s.url, {json: true}, function (err, json) { got(s.url, {json: true}, function (err, json) {
t.error(err); t.error(err);
t.deepEqual(json, {data: 'dog'}); t.deepEqual(json, {data: 'dog'});
@ -43,7 +43,7 @@ tape('json option should parse response', function (t) {
}); });
}); });
tape('json option wrap parsing errors', function (t) { test('json option wrap parsing errors', function (t) {
got(s.url + '/invalid', {json: true}, function (err) { got(s.url + '/invalid', {json: true}, function (err) {
t.ok(err); t.ok(err);
t.equal(err.message, 'Parsing ' + s.url + '/invalid response failed'); t.equal(err.message, 'Parsing ' + s.url + '/invalid response failed');
@ -53,7 +53,7 @@ tape('json option wrap parsing errors', function (t) {
}); });
}); });
tape('json option should parse non-200 responses', function (t) { test('json option should parse non-200 responses', function (t) {
got(s.url + '/non200', {json: true}, function (err, json) { got(s.url + '/non200', {json: true}, function (err, json) {
t.ok(err); t.ok(err);
t.deepEqual(json, {data: 'dog'}); t.deepEqual(json, {data: 'dog'});
@ -61,7 +61,7 @@ tape('json option should parse non-200 responses', function (t) {
}); });
}); });
tape('json option should catch errors on invalid non-200 responses', function (t) { test('json option should catch errors on invalid non-200 responses', function (t) {
got(s.url + '/non200-invalid', {json: true}, function (err, json) { got(s.url + '/non200-invalid', {json: true}, function (err, json) {
t.ok(err); t.ok(err);
t.deepEqual(json, 'Internal error'); t.deepEqual(json, 'Internal error');
@ -74,7 +74,7 @@ tape('json option should catch errors on invalid non-200 responses', function (t
}); });
}); });
tape('cleanup', function (t) { test('cleanup', function (t) {
s.close(); s.close();
t.end(); t.end();
}); });

18
test/test-post.js

@ -1,5 +1,5 @@
'use strict'; 'use strict';
var tape = require('tape'); var test = require('tap').test;
var from2Array = require('from2-array'); var from2Array = require('from2-array');
var got = require('../'); var got = require('../');
var server = require('./server.js'); var server = require('./server.js');
@ -18,13 +18,13 @@ s.on('/empty', function (req, res) {
res.end(); res.end();
}); });
tape('setup', function (t) { test('setup', function (t) {
s.listen(s.port, function () { s.listen(s.port, function () {
t.end(); t.end();
}); });
}); });
tape('GET can have body', function (t) { test('GET can have body', function (t) {
t.plan(3); t.plan(3);
var stream = from2Array(['wow']); var stream = from2Array(['wow']);
@ -39,7 +39,7 @@ tape('GET can have body', function (t) {
}); });
}); });
tape('send data from options with post request', function (t) { test('send data from options with post request', function (t) {
t.plan(3); t.plan(3);
got(s.url, {body: 'wow'}, function (err, data) { got(s.url, {body: 'wow'}, function (err, data) {
@ -55,14 +55,14 @@ tape('send data from options with post request', function (t) {
}); });
}); });
tape('works with empty post response', function (t) { test('works with empty post response', function (t) {
got(s.url + '/empty', {body: 'wow'}, function (err, data) { got(s.url + '/empty', {body: 'wow'}, function (err, data) {
t.equal(data, ''); t.equal(data, '');
t.end(); t.end();
}); });
}); });
tape('return readable stream', function (t) { test('return readable stream', function (t) {
got.post(s.url, {body: from2Array(['wow'])}) got.post(s.url, {body: from2Array(['wow'])})
.on('data', function (data) { .on('data', function (data) {
t.equal(data.toString(), 'wow'); t.equal(data.toString(), 'wow');
@ -70,7 +70,7 @@ tape('return readable stream', function (t) {
}); });
}); });
tape('return writeable stream', function (t) { test('return writeable stream', function (t) {
got.post(s.url) got.post(s.url)
.on('data', function (data) { .on('data', function (data) {
t.equal(data.toString(), 'wow'); t.equal(data.toString(), 'wow');
@ -79,14 +79,14 @@ tape('return writeable stream', function (t) {
.end('wow'); .end('wow');
}); });
tape('throws on write to stream with body specified', function (t) { test('throws on write to stream with body specified', function (t) {
t.throws(function () { t.throws(function () {
got(s.url, {body: 'wow'}).write('wow'); got(s.url, {body: 'wow'}).write('wow');
}); });
setTimeout(t.end.bind(t), 10); // wait for request to end setTimeout(t.end.bind(t), 10); // wait for request to end
}); });
tape('cleanup', function (t) { test('cleanup', function (t) {
s.close(); s.close();
t.end(); t.end();
}); });

20
test/test-redirects.js

@ -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();
@ -36,13 +36,13 @@ s.on('/', function (req, res) {
res.end('reached'); res.end('reached');
}); });
tape('setup', function (t) { test('setup', function (t) {
s.listen(s.port, function () { s.listen(s.port, function () {
t.end(); t.end();
}); });
}); });
tape('follows redirect', function (t) { test('follows redirect', function (t) {
got(s.url + '/finite', function (err, data) { got(s.url + '/finite', function (err, data) {
t.error(err); t.error(err);
t.equal(data, 'reached'); t.equal(data, 'reached');
@ -50,7 +50,7 @@ tape('follows redirect', function (t) {
}); });
}); });
tape('follows relative redirect', function (t) { test('follows relative redirect', function (t) {
got(s.url + '/relative', function (err, data) { got(s.url + '/relative', function (err, data) {
t.error(err); t.error(err);
t.equal(data, 'reached'); t.equal(data, 'reached');
@ -58,7 +58,7 @@ tape('follows relative redirect', function (t) {
}); });
}); });
tape('throws on endless redirect', function (t) { test('throws on endless redirect', function (t) {
got(s.url + '/endless', function (err) { got(s.url + '/endless', function (err) {
t.ok(err, 'should get error'); t.ok(err, 'should get error');
t.equal(err.message, 'Redirected 10 times. Aborting.'); t.equal(err.message, 'Redirected 10 times. Aborting.');
@ -66,7 +66,7 @@ tape('throws on endless redirect', function (t) {
}); });
}); });
tape('query in options are not breaking redirects', function (t) { test('query in options are not breaking redirects', function (t) {
got(s.url + '/relativeQuery', {query: 'bang'}, function (err, data) { got(s.url + '/relativeQuery', {query: 'bang'}, function (err, data) {
t.error(err); t.error(err);
t.equal(data, 'reached'); t.equal(data, 'reached');
@ -74,7 +74,7 @@ tape('query in options are not breaking redirects', function (t) {
}); });
}); });
tape('host+path in options are not breaking redirects', function (t) { test('host+path in options are not breaking redirects', function (t) {
got(s.url + '/relative', {host: s.url, path: '/relative'}, function (err, data) { got(s.url + '/relative', {host: s.url, path: '/relative'}, function (err, data) {
t.error(err); t.error(err);
t.equal(data, 'reached'); t.equal(data, 'reached');
@ -82,7 +82,7 @@ tape('host+path in options are not breaking redirects', function (t) {
}); });
}); });
tape('redirect only GET and HEAD requests', function (t) { test('redirect only GET and HEAD requests', function (t) {
got(s.url + '/relative', {body: 'wow'}, function (err, data) { got(s.url + '/relative', {body: 'wow'}, function (err, data) {
t.equal(err.message, 'POST http://localhost:6767/relative response code is 302 (Found)'); t.equal(err.message, 'POST http://localhost:6767/relative response code is 302 (Found)');
t.equal(err.code, 302); t.equal(err.code, 302);
@ -90,7 +90,7 @@ tape('redirect only GET and HEAD requests', function (t) {
}); });
}); });
tape('redirect event', function (t) { test('redirect event', function (t) {
got(s.url + '/endless') got(s.url + '/endless')
.on('redirect', function (res, opts) { .on('redirect', function (res, opts) {
t.equal(res.headers.location, s.url + '/endless'); t.equal(res.headers.location, s.url + '/endless');
@ -102,7 +102,7 @@ tape('redirect event', function (t) {
}); });
}); });
tape('cleanup', function (t) { test('cleanup', function (t) {
s.close(); s.close();
t.end(); t.end();
}); });

Loading…
Cancel
Save