From f57a5e89f8a9e1c2ae420b3027d3d1afcf601a1d Mon Sep 17 00:00:00 2001 From: Vsevolod Strukchinsky Date: Wed, 16 Sep 2015 22:56:34 +0500 Subject: [PATCH] move from tap to ava --- .travis.yml | 2 +- package.json | 5 +-- test/server.js | 4 ++ test/test-arguments.js | 22 +++++------ test/test-error.js | 26 ++++++------- test/test-gzip.js | 24 ++++++------ test/test-headers.js | 36 +++++++++--------- test/test-helpers.js | 18 ++++----- test/test-http.js | 48 ++++++++++++------------ test/test-https.js | 28 +++++++------- test/test-json.js | 34 ++++++++--------- test/test-post.js | 80 ++++++++++++++++++---------------------- test/test-redirects.js | 42 ++++++++++----------- test/test-stream.js | 38 +++++++++---------- test/test-unix-socket.js | 18 ++++----- 15 files changed, 209 insertions(+), 216 deletions(-) diff --git a/.travis.yml b/.travis.yml index dedfc07..52ba159 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ sudo: false language: node_js node_js: - - 'iojs' + - 'stable' - '0.12' - '0.10' diff --git a/package.json b/package.json index 28a9cdf..17eea99 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "node": ">=0.10.0" }, "scripts": { - "test": "xo && tap test/test-*.js" + "test": "xo && ava" }, "files": [ "index.js" @@ -57,10 +57,9 @@ "unzip-response": "^1.0.0" }, "devDependencies": { + "ava": "^0.2.0", "into-stream": "^2.0.0", - "istanbul": "^0.3.13", "pem": "^1.4.4", - "tap": "^1.0.0", "tempfile": "^1.1.1", "xo": "*" } diff --git a/test/server.js b/test/server.js index 77b9d1a..56e3876 100644 --- a/test/server.js +++ b/test/server.js @@ -11,6 +11,8 @@ exports.createServer = function (port) { port = port || exports.port; + exports.port += 1; + var s = http.createServer(function (req, resp) { s.emit(req.url, req, resp); }); @@ -28,6 +30,8 @@ exports.createSSLServer = function (port, opts) { port = port || exports.portSSL; + exports.portSSL += 1; + var s = https.createServer(opts, function (req, resp) { s.emit(req.url, req, resp); }); diff --git a/test/test-arguments.js b/test/test-arguments.js index 121721c..dd804c3 100644 --- a/test/test-arguments.js +++ b/test/test-arguments.js @@ -1,5 +1,5 @@ 'use strict'; -var test = require('tap').test; +var test = require('ava'); var got = require('../'); var server = require('./server.js'); var s = server.createServer(); @@ -17,13 +17,13 @@ s.on('/?test=wow', function (req, res) { res.end(req.url); }); -test('setup', function (t) { +test.before('arguments - setup', function (t) { s.listen(s.port, function () { t.end(); }); }); -test('url argument is required', function (t) { +test('arguments - url argument is required', function (t) { t.plan(2); t.throws(function () { got(undefined, function () {}); @@ -31,27 +31,27 @@ test('url argument is required', function (t) { got() .catch(function (err) { - t.ok(/Parameter `url` must be a string or object, not undefined/.test(err.message)); + t.regexTest(/Parameter `url` must be a string or object, not undefined/, err.message); }); }); -test('accepts url.parse object as first argument', function (t) { +test('arguments - accepts url.parse object as first argument', function (t) { got({hostname: s.host, port: s.port, path: '/test'}, function (err, data) { - t.error(err); - t.equal(data, '/test'); + t.ifError(err); + t.is(data, '/test'); t.end(); }); }); -test('overrides querystring from opts', function (t) { +test('arguments - overrides querystring from opts', function (t) { got(s.url + '/?test=doge', {query: {test: 'wow'}}, function (err, data) { - t.error(err); - t.equal(data, '/?test=wow'); + t.ifError(err); + t.is(data, '/?test=wow'); t.end(); }); }); -test('cleanup', function (t) { +test.after('arguments - cleanup', function (t) { s.close(); t.end(); }); diff --git a/test/test-error.js b/test/test-error.js index 4997b85..1c990ca 100644 --- a/test/test-error.js +++ b/test/test-error.js @@ -1,5 +1,5 @@ 'use strict'; -var test = require('tap').test; +var test = require('ava'); var got = require('../'); var server = require('./server.js'); var s = server.createServer(); @@ -9,33 +9,33 @@ s.on('/', function (req, res) { res.end('not'); }); -test('setup', function (t) { +test.before('error - setup', function (t) { s.listen(s.port, function () { t.end(); }); }); -test('error message', function (t) { +test('error - error message', function (t) { got(s.url, function (err) { t.ok(err); - t.equal(err.message, 'Response code 404 (Not Found)'); - t.equal(err.host, 'localhost:6767'); - t.equal(err.method, 'GET'); + t.is(err.message, 'Response code 404 (Not Found)'); + t.is(err.host, s.host + ':' + s.port); + t.is(err.method, 'GET'); t.end(); }); }); -test('dns error message', function (t) { +test('error - dns error message', function (t) { got('.com', function (err) { t.ok(err); - t.ok(/getaddrinfo ENOTFOUND/.test(err.message)); - t.equal(err.host, '.com'); - t.equal(err.method, 'GET'); + t.regexTest(/getaddrinfo ENOTFOUND/, err.message); + t.is(err.host, '.com'); + t.is(err.method, 'GET'); t.end(); }); }); -test('options.body error message', function (t) { +test('error - options.body error message', function (t) { t.plan(2); t.throws(function () { got(s.url, {body: function () {}}, function () {}); @@ -43,11 +43,11 @@ test('options.body error message', function (t) { got(s.url, {body: function () {}}) .catch(function (err) { - t.ok(/options.body must be a ReadableStream, string, Buffer or plain Object/.test(err.message)); + t.regexTest(/options.body must be a ReadableStream, string, Buffer or plain Object/, err.message); }); }); -test('cleanup', function (t) { +test.after('error - cleanup', function (t) { s.close(); t.end(); }); diff --git a/test/test-gzip.js b/test/test-gzip.js index e877bff..986ddd7 100644 --- a/test/test-gzip.js +++ b/test/test-gzip.js @@ -1,6 +1,6 @@ 'use strict'; var zlib = require('zlib'); -var test = require('tap').test; +var test = require('ava'); var got = require('../'); var server = require('./server.js'); var s = server.createServer(); @@ -22,39 +22,39 @@ s.on('/corrupted', function (req, res) { res.end('Not gzipped content'); }); -test('setup', function (t) { +test.before('gzip - setup', function (t) { s.listen(s.port, function () { t.end(); }); }); -test('ungzip content', function (t) { +test('gzip - ungzip content', function (t) { got(s.url, function (err, data) { - t.error(err); - t.equal(data, testContent); + t.ifError(err); + t.is(data, testContent); t.end(); }); }); -test('ungzip error', function (t) { +test('gzip - ungzip error', function (t) { got(s.url + '/corrupted', function (err) { t.ok(err); - t.equal(err.message, 'incorrect header check'); - t.equal(err.path, '/corrupted'); - t.equal(err.name, 'ReadError'); + t.is(err.message, 'incorrect header check'); + t.is(err.path, '/corrupted'); + t.is(err.name, 'ReadError'); t.end(); }); }); -test('preserve headers property', function (t) { +test('gzip - preserve headers property', function (t) { got(s.url, function (err, data, res) { - t.error(err); + t.ifError(err); t.ok(res.headers); t.end(); }); }); -test('cleanup', function (t) { +test.after('gzip - cleanup', function (t) { s.close(); t.end(); }); diff --git a/test/test-headers.js b/test/test-headers.js index 2f83c5e..02529a7 100644 --- a/test/test-headers.js +++ b/test/test-headers.js @@ -1,5 +1,5 @@ 'use strict'; -var test = require('tap').test; +var test = require('ava'); var got = require('../'); var server = require('./server.js'); var s = server.createServer(); @@ -8,65 +8,65 @@ s.on('/', function (req, res) { res.end(JSON.stringify(req.headers)); }); -test('setup', function (t) { +test.before('headers - setup', function (t) { s.listen(s.port, function () { t.end(); }); }); -test('send user-agent header by default', function (t) { +test('headers - send user-agent header by default', function (t) { got(s.url, function (err, data) { - t.error(err); + t.ifError(err); var headers = JSON.parse(data); - t.equal(headers['user-agent'], 'https://github.com/sindresorhus/got'); + t.is(headers['user-agent'], 'https://github.com/sindresorhus/got'); t.end(); }); }); -test('send accept-encoding header by default', function (t) { +test('headers - send accept-encoding header by default', function (t) { got(s.url, function (err, data) { - t.error(err); + t.ifError(err); var headers = JSON.parse(data); - t.equal(headers['accept-encoding'], 'gzip,deflate'); + t.is(headers['accept-encoding'], 'gzip,deflate'); t.end(); }); }); -test('send accept header with json option', function (t) { +test('headers - 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.ifError(err); + t.is(headers.accept, 'application/json'); t.end(); }); }); -test('send host header by default', function (t) { +test('headers - send host header by default', function (t) { got(s.url, function (err, data) { - t.error(err); + t.ifError(err); var headers = JSON.parse(data); - t.equal(headers.host, 'localhost:' + s.port); + t.is(headers.host, 'localhost:' + s.port); t.end(); }); }); -test('transform headers names to lowercase', function (t) { +test('headers - transform headers names to lowercase', function (t) { got(s.url, {headers: {'USER-AGENT': 'test'}}, function (err, data) { - t.error(err); + t.ifError(err); var headers = JSON.parse(data); - t.equal(headers['user-agent'], 'test'); + t.is(headers['user-agent'], 'test'); t.end(); }); }); -test('cleanup', function (t) { +test.after('headers - cleanup', function (t) { s.close(); t.end(); }); diff --git a/test/test-helpers.js b/test/test-helpers.js index 63849a4..2bca8ae 100644 --- a/test/test-helpers.js +++ b/test/test-helpers.js @@ -1,5 +1,5 @@ 'use strict'; -var test = require('tap').test; +var test = require('ava'); var got = require('../'); var server = require('./server.js'); var s = server.createServer(); @@ -13,31 +13,31 @@ s.on('/404', function (req, res) { res.end('not found'); }); -test('setup', function (t) { +test.before('helpers - setup', function (t) { s.listen(s.port, function () { t.end(); }); }); -test('callback mode', function (t) { +test('helpers - callback mode', function (t) { got.get(s.url, function (err, data) { - t.error(err); - t.equal(data, 'ok'); + t.ifError(err); + t.is(data, 'ok'); t.end(); }); }); -test('promise mode', function (t) { +test('helpers - promise mode', function (t) { t.plan(3); got.get(s.url) .then(function (res) { - t.equal(res.body, 'ok'); + t.is(res.body, 'ok'); }); got.get(s.url + '/404') .catch(function (err) { - t.equal(err.response.body, 'not found'); + t.is(err.response.body, 'not found'); }); got.get('.com') @@ -46,7 +46,7 @@ test('promise mode', function (t) { }); }); -test('cleanup', function (t) { +test.after('helpers - cleanup', function (t) { s.close(); t.end(); }); diff --git a/test/test-http.js b/test/test-http.js index 13319d2..a0f054b 100644 --- a/test/test-http.js +++ b/test/test-http.js @@ -1,5 +1,5 @@ 'use strict'; -var test = require('tap').test; +var test = require('ava'); var got = require('../'); var server = require('./server.js'); var s = server.createServer(); @@ -23,75 +23,75 @@ s.on('/?recent=true', function (req, res) { res.end('recent'); }); -test('setup', function (t) { +test.before('http - setup', function (t) { s.listen(s.port, function () { t.end(); }); }); -test('callback mode', function (t) { +test('http - callback mode', function (t) { got(s.url, function (err, data) { - t.error(err); - t.equal(data, 'ok'); + t.ifError(err); + t.is(data, 'ok'); t.end(); }); }); -test('protocol-less URLs', function (t) { +test('http - protocol-less URLs', function (t) { got(s.url.replace(/^http:\/\//, ''), function (err, data) { - t.error(err); - t.equal(data, 'ok'); + t.ifError(err); + t.is(data, 'ok'); t.end(); }); }); -test('empty response', function (t) { +test('http - empty response', function (t) { got(s.url + '/empty', function (err, data) { - t.error(err); - t.equal(data, ''); + t.ifError(err); + t.is(data, ''); t.end(); }); }); -test('error with code', function (t) { +test('http - error with code', function (t) { got(s.url + '/404', function (err, data) { t.ok(err); - t.equal(err.statusCode, 404); - t.equal(data, 'not'); + t.is(err.statusCode, 404); + t.is(data, 'not'); t.end(); }); }); -test('buffer on encoding === null', function (t) { +test('http - buffer on encoding === null', function (t) { got(s.url, {encoding: null}, function (err, data) { - t.error(err); + t.ifError(err); t.ok(Buffer.isBuffer(data)); t.end(); }); }); -test('timeout option', function (t) { +test('http - timeout option', function (t) { got(s.url + '/404', {timeout: 1}, function (err) { - t.equal(err.code, 'ETIMEDOUT'); + t.is(err.code, 'ETIMEDOUT'); t.end(); }); }); -test('query option', function (t) { +test('http - query option', function (t) { t.plan(4); got(s.url, {query: {recent: true}}, function (err, data) { - t.error(err); - t.equal(data, 'recent'); + t.ifError(err); + t.is(data, 'recent'); }); got(s.url, {query: 'recent=true'}, function (err, data) { - t.error(err); - t.equal(data, 'recent'); + t.ifError(err); + t.is(data, 'recent'); }); }); -test('cleanup', function (t) { +test.after('http - cleanup', function (t) { s.close(); t.end(); }); diff --git a/test/test-https.js b/test/test-https.js index 0eee690..63f8197 100644 --- a/test/test-https.js +++ b/test/test-https.js @@ -1,5 +1,5 @@ 'use strict'; -var test = require('tap').test; +var test = require('ava'); var pem = require('pem'); var got = require('../'); var server = require('./server.js'); @@ -10,19 +10,19 @@ var cert; var caRootKey; var caRootCert; -test('root pem', function (t) { +test.before('https - create root pem', function (t) { pem.createCertificate({ days: 1, selfSigned: true }, function (err, keys) { - t.error(err); + t.ifError(err); caRootKey = keys.serviceKey; caRootCert = keys.certificate; t.end(); }); }); -test('pem', function (t) { +test.before('https - create pem', function (t) { pem.createCertificate({ serviceCertificate: caRootCert, serviceKey: caRootKey, @@ -35,14 +35,14 @@ test('pem', function (t) { organizationUnit: '', commonName: 'sindresorhus.com' }, function (err, keys) { - t.error(err); + t.ifError(err); key = keys.clientKey; cert = keys.certificate; t.end(); }); }); -test('setup', function (t) { +test.before('https - setup', function (t) { s = server.createSSLServer(server.portSSL + 1, { key: key, cert: cert @@ -57,37 +57,37 @@ test('setup', function (t) { }); }); -test('redirects from http to https works', function (t) { +test('https - redirects from http to https works', function (t) { got('http://github.com', function (err, data) { - t.error(err); + t.ifError(err); t.ok(data); t.end(); }); }); -test('make request to https server', function (t) { +test('https - make request to https server', function (t) { got('https://google.com', { strictSSL: true }, function (err, data) { - t.error(err); + t.ifError(err); t.ok(data); t.end(); }); }); -test('make request to https server with ca', function (t) { +test('https - make request to https server with ca', function (t) { got(s.url, { strictSSL: true, ca: caRootCert, headers: {host: 'sindresorhus.com'} }, function (err, data) { - t.error(err); - t.equal(data, 'ok'); + t.ifError(err); + t.is(data, 'ok'); t.end(); }); }); -test('cleanup', function (t) { +test.after('https - cleanup', function (t) { s.close(); t.end(); }); diff --git a/test/test-json.js b/test/test-json.js index 4aba354..5db94af 100644 --- a/test/test-json.js +++ b/test/test-json.js @@ -1,5 +1,5 @@ 'use strict'; -var test = require('tap').test; +var test = require('ava'); var got = require('../'); var server = require('./server.js'); var s = server.createServer(); @@ -27,56 +27,56 @@ s.on('/non200-invalid', function (req, res) { res.end('Internal error'); }); -test('setup', function (t) { +test.before('json - setup', function (t) { s.listen(s.port, function () { t.end(); }); }); -test('json option should parse response', function (t) { +test('json - json option should parse response', function (t) { got(s.url, {json: true}, function (err, json) { - t.error(err); - t.deepEqual(json, {data: 'dog'}); + t.ifError(err); + t.same(json, {data: 'dog'}); t.end(); }); }); -test('json option should not parse responses without a body', function (t) { +test('json - json option should not parse responses without a body', function (t) { got(s.url + '/204', {json: true}, function (err) { - t.error(err); + t.ifError(err); t.end(); }); }); -test('json option wrap parsing errors', function (t) { +test('json - json option wrap parsing errors', function (t) { got(s.url + '/invalid', {json: true}, function (err) { t.ok(err); - t.ok(/Unexpected token/.test(err.message), err.message); + t.regexTest(/Unexpected token/, err.message); t.ok(err.message.indexOf(err.hostname) !== -1, err.message); - t.equal(err.path, '/invalid'); + t.is(err.path, '/invalid'); t.end(); }); }); -test('json option should parse non-200 responses', function (t) { +test('json - json option should parse non-200 responses', function (t) { got(s.url + '/non200', {json: true}, function (err, json) { t.ok(err); - t.deepEqual(json, {data: 'dog'}); + t.same(json, {data: 'dog'}); t.end(); }); }); -test('json option should catch errors on invalid non-200 responses', function (t) { +test('json - json option should catch errors on invalid non-200 responses', function (t) { got(s.url + '/non200-invalid', {json: true}, function (err, json) { t.ok(err); - t.ok(/Unexpected token/.test(err.message), err.message); - t.deepEqual(json, 'Internal error'); - t.equal(err.path, '/non200-invalid'); + t.regexTest(/Unexpected token/, err.message); + t.is(json, 'Internal error'); + t.is(err.path, '/non200-invalid'); t.end(); }); }); -test('cleanup', function (t) { +test.after('json - cleanup', function (t) { s.close(); t.end(); }); diff --git a/test/test-post.js b/test/test-post.js index 4196295..cd2f479 100644 --- a/test/test-post.js +++ b/test/test-post.js @@ -1,11 +1,12 @@ 'use strict'; -var test = require('tap').test; +var test = require('ava'); var intoStream = require('into-stream'); var got = require('../'); var server = require('./server.js'); var s = server.createServer(); s.on('/', function (req, res) { + res.setHeader('method', req.method); req.pipe(res); }); @@ -13,108 +14,97 @@ s.on('/headers', function (req, res) { res.end(JSON.stringify(req.headers)); }); -s.on('/method', function (req, res) { - res.setHeader('method', req.method); - res.end(); -}); - s.on('/empty', function (req, res) { res.end(); }); -test('setup', function (t) { +test.before('post - setup', function (t) { s.listen(s.port, function () { t.end(); }); }); -test('GET can have body', function (t) { +test('post - GET can have body', function (t) { t.plan(3); - var stream = intoStream(['wow']); - - stream.on('end', function () { - // ensure that stream was dumped - t.ok(true); - }); - - got.get(s.url + '/method', {body: stream}, function (err, data, res) { - t.error(err); - t.equal(res.headers.method, 'GET'); + got.get(s.url, {body: 'hi'}, function (err, data, res) { + t.ifError(err); + t.is(data, 'hi'); + t.is(res.headers.method, 'GET'); }); }); -test('send data from options with post request', function (t) { +test('post - send data from options with post request', function (t) { t.plan(6); got(s.url, {body: 'wow'}, function (err, data) { - t.error(err); - t.equal(data, 'wow'); + t.ifError(err); + t.is(data, 'wow'); }); got(s.url, {body: new Buffer('wow')}, function (err, data) { - t.error(err); - t.equal(data, 'wow'); + t.ifError(err); + t.is(data, 'wow'); }); got(s.url, {body: intoStream(['wow'])}, function (err, data) { - t.error(err); - t.equal(data, 'wow'); + t.ifError(err); + t.is(data, 'wow'); }); }); -test('works with empty post response', function (t) { +test('post - works with empty post response', function (t) { got(s.url + '/empty', {body: 'wow'}, function (err, data) { - t.error(err); - t.equal(data, ''); + t.ifError(err); + t.is(data, ''); t.end(); }); }); -test('post have content-length header to string', function (t) { +test('post - post have content-length header to string', function (t) { t.plan(10); got(s.url + '/headers', {body: 'wow', json: true}, function (err, headers) { - t.error(err); - t.equal(headers['content-length'], '3'); + t.ifError(err); + t.is(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'); + t.ifError(err); + t.is(headers['content-length'], '3'); }); got(s.url + '/headers', {body: intoStream(['wow']), json: true}, function (err, headers) { - t.error(err); - t.equal(headers['content-length'], undefined); + t.ifError(err); + t.is(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'); + t.ifError(err); + t.is(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); + t.ifError(err); + t.is(headers['content-length'], undefined); }); }); -test('works with plain object in body', function (t) { +test('post - works with plain object in body', function (t) { t.plan(4); got(s.url, {body: {such: 'wow'}}, function (err, data) { - t.error(err); - t.equal(data, 'such=wow'); + t.ifError(err); + t.is(data, 'such=wow'); }); got(s.url + '/headers', {headers: {'content-type': 'doge'}, body: {such: 'wow'}, json: true}, function (err, headers) { - t.error(err); - t.equal(headers['content-type'], 'doge'); + t.ifError(err); + t.is(headers['content-type'], 'doge'); }); }); -test('cleanup', function (t) { +test.after('post - cleanup', function (t) { s.close(); t.end(); }); diff --git a/test/test-redirects.js b/test/test-redirects.js index 53e90be..ece8d3a 100644 --- a/test/test-redirects.js +++ b/test/test-redirects.js @@ -1,5 +1,5 @@ 'use strict'; -var test = require('tap').test; +var test = require('ava'); var got = require('../'); var server = require('./server.js'); var s = server.createServer(); @@ -36,62 +36,62 @@ s.on('/relativeQuery?bang', function (req, res) { res.end(); }); -test('setup', function (t) { +test.before('redirects - setup', function (t) { s.listen(s.port, function () { t.end(); }); }); -test('follows redirect', function (t) { +test('redirects - follows redirect', function (t) { got(s.url + '/finite', function (err, data) { - t.error(err); - t.equal(data, 'reached'); + t.ifError(err); + t.is(data, 'reached'); t.end(); }); }); -test('follows relative redirect', function (t) { +test('redirects - follows relative redirect', function (t) { got(s.url + '/relative', function (err, data) { - t.error(err); - t.equal(data, 'reached'); + t.ifError(err); + t.is(data, 'reached'); t.end(); }); }); -test('throws on endless redirect', function (t) { +test('redirects - throws on endless redirect', function (t) { got(s.url + '/endless', function (err) { t.ok(err, 'should get error'); - t.equal(err.message, 'Redirected 10 times. Aborting.'); + t.is(err.message, 'Redirected 10 times. Aborting.'); t.end(); }); }); -test('query in options are not breaking redirects', function (t) { +test('redirects - query in options are not breaking redirects', function (t) { got(s.url + '/relativeQuery', {query: 'bang'}, function (err, data) { - t.error(err); - t.equal(data, 'reached'); + t.ifError(err); + t.is(data, 'reached'); t.end(); }); }); -test('hostname+path in options are not breaking redirects', function (t) { +test('redirects - hostname+path in options are not breaking redirects', function (t) { got(s.url + '/relative', {hostname: s.host, path: '/relative'}, function (err, data) { - t.error(err); - t.equal(data, 'reached'); + t.ifError(err); + t.is(data, 'reached'); t.end(); }); }); -test('redirect only GET and HEAD requests', function (t) { +test('redirects - redirect only GET and HEAD requests', function (t) { got(s.url + '/relative', {body: 'wow'}, function (err) { - t.equal(err.message, 'Response code 302 (Moved Temporarily)'); - t.equal(err.path, '/relative'); - t.equal(err.statusCode, 302); + t.is(err.message, 'Response code 302 (Moved Temporarily)'); + t.is(err.path, '/relative'); + t.is(err.statusCode, 302); t.end(); }); }); -test('cleanup', function (t) { +test.after('redirect - cleanup', function (t) { s.close(); t.end(); }); diff --git a/test/test-stream.js b/test/test-stream.js index 00a0dd6..57fb8e5 100644 --- a/test/test-stream.js +++ b/test/test-stream.js @@ -1,5 +1,5 @@ 'use strict'; -var test = require('tap').test; +var test = require('ava'); var got = require('../'); var server = require('./server.js'); var s = server.createServer(); @@ -24,20 +24,20 @@ s.on('/error', function (req, res) { res.end(); }); -test('setup', function (t) { +test.before('stream - setup', function (t) { s.listen(s.port, function () { t.end(); }); }); -test('json option can not be used in stream mode', function (t) { +test('stream - json option can not be used in stream mode', function (t) { t.throws(function () { got.stream(s.url, {json: true}); }, 'got can not be used as stream when options.json is used'); t.end(); }); -test('callback can not be used in stream mode', function (t) { +test('stream - callback can not be used in stream mode', function (t) { t.throws(function () { got.stream(s.url, {json: true}, function () {}); }, 'callback can not be used in stream mode'); @@ -49,24 +49,24 @@ test('callback can not be used in stream mode', function (t) { t.end(); }); -test('return readable stream', function (t) { +test('stream - return readable stream', function (t) { got.stream(s.url) .on('data', function (data) { - t.equal(data.toString(), 'ok'); + t.is(data.toString(), 'ok'); t.end(); }); }); -test('return writeable stream', function (t) { +test('stream - return writeable stream', function (t) { t.plan(1); got.stream.post(s.url + '/post') .on('data', function (data) { - t.equal(data.toString(), 'wow'); + t.is(data.toString(), 'wow'); }) .end('wow'); }); -test('throws on write to stream with body specified', function (t) { +test('stream - throws on write to stream with body specified', function (t) { t.throws(function () { got.stream(s.url, {body: 'wow'}).write('wow'); }, 'got\'s stream is not writable when options.body is used'); @@ -75,7 +75,7 @@ test('throws on write to stream with body specified', function (t) { setTimeout(t.end.bind(t), 10); }); -test('request event', function (t) { +test('stream - request event', function (t) { got.stream(s.url) .on('request', function (req) { t.ok(req); @@ -83,39 +83,39 @@ test('request event', function (t) { }); }); -test('redirect event', function (t) { +test('stream - redirect event', function (t) { got.stream(s.url + '/redirect') .on('redirect', function (res) { - t.equal(res.headers.location, s.url); + t.is(res.headers.location, s.url); t.end(); }); }); -test('response event', function (t) { +test('stream - response event', function (t) { got.stream(s.url) .on('response', function (res) { - t.equal(res.statusCode, 200); + t.is(res.statusCode, 200); t.end(); }); }); -test('error event', function (t) { +test('stream - error event', function (t) { t.plan(4); got.stream(s.url + '/error') .on('error', function (err, data, res) { - t.equal(err.message, 'Response code 404 (Not Found)'); - t.equal(null, data); + t.is(err.message, 'Response code 404 (Not Found)'); + t.is(null, data); t.ok(res); }); got.stream('.com') .on('error', function (err) { - t.ok(/getaddrinfo ENOTFOUND/.test(err.message)); + t.regexTest(/getaddrinfo ENOTFOUND/, err.message); }); }); -test('cleanup', function (t) { +test.after('stream - cleanup', function (t) { s.close(); t.end(); }); diff --git a/test/test-unix-socket.js b/test/test-unix-socket.js index 5919b79..f58693c 100644 --- a/test/test-unix-socket.js +++ b/test/test-unix-socket.js @@ -1,7 +1,7 @@ 'use strict'; var tempfile = require('tempfile'); var format = require('util').format; -var test = require('tap').test; +var test = require('ava'); var got = require('../'); var server = require('./server.js'); var s = server.createServer(); @@ -12,34 +12,34 @@ s.on('/', function (req, res) { res.end('ok'); }); -test('setup', function (t) { +test.before('unix-socket - setup', function (t) { s.listen(socketPath, function () { t.end(); }); }); -test('request via unix socket', function (t) { +test('unix-socket - request via unix socket', function (t) { // borrow unix domain socket url format from request module var url = format('http://unix:%s:%s', socketPath, '/'); got(url, function (err, data) { - t.error(err); - t.equal(data, 'ok'); + t.ifError(err); + t.is(data, 'ok'); t.end(); }); }); -test('protocol-less request', function (t) { +test('unix-socket - protocol-less request', function (t) { var url = format('unix:%s:%s', socketPath, '/'); got(url, function (err, data) { - t.error(err); - t.equal(data, 'ok'); + t.ifError(err); + t.is(data, 'ok'); t.end(); }); }); -test('cleanup', function (t) { +test.after('unix-socket - cleanup', function (t) { s.close(); t.end(); });