From 87d984d6719e2c5e8785f41bb731106a89cb1b4d Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 6 Aug 2016 17:23:25 +0200 Subject: [PATCH] bump dependencies --- package.json | 5 +++-- test/arguments.js | 12 ++++-------- test/error.js | 16 ++++++++-------- test/gzip.js | 2 +- test/helpers.js | 8 ++++---- test/http.js | 2 +- test/https.js | 4 ++-- test/json.js | 10 +++++----- test/retry.js | 8 ++++---- test/stream.js | 35 +++++++++++++++++------------------ 10 files changed, 49 insertions(+), 53 deletions(-) diff --git a/package.json b/package.json index f0dba2e..f13dc37 100644 --- a/package.json +++ b/package.json @@ -63,11 +63,12 @@ "url-parse-lax": "^1.0.0" }, "devDependencies": { - "ava": "^0.5.0", + "ava": "^0.16.0", "coveralls": "^2.11.4", "get-port": "^2.0.0", + "get-stream": "^2.3.0", "into-stream": "^2.0.0", - "nyc": "^3.2.2", + "nyc": "^7.1.0", "pem": "^1.4.4", "pify": "^2.3.0", "tempfile": "^1.1.1", diff --git a/test/arguments.js b/test/arguments.js index 8cd856b..063d62d 100644 --- a/test/arguments.js +++ b/test/arguments.js @@ -28,7 +28,7 @@ test('url is required', async t => { await got(); t.fail('Exception was not thrown'); } catch (err) { - t.regexTest(/Parameter `url` must be a string or object, not undefined/, err.message); + t.regex(err.message, /Parameter `url` must be a string or object, not undefined/); } }); @@ -36,7 +36,7 @@ test('options are optional', async t => { t.is((await got(`${s.url}/test`)).body, '/test'); }); -test('options are optional', t => { +test.cb('options are optional with callback', t => { got(`${s.url}/test`, function (err, data) { t.is(data, '/test'); t.end(); @@ -64,14 +64,10 @@ test('should throw with auth in url', async t => { await got(`https://test:45d3ps453@account.myservice.com/api/token`); t.fail('Exception was not thrown'); } catch (err) { - t.regexTest(/Basic authentication must be done with auth option/, err.message); + t.regex(err.message, /Basic authentication must be done with auth option/); } }); -test('accepts url.parse object as first argument', async t => { - t.is((await got({hostname: s.host, port: s.port, path: '/test'})).body, '/test'); -}); - -test.after('cleanup', async t => { +test.after('cleanup', async () => { await s.close(); }); diff --git a/test/error.js b/test/error.js index 87c41c3..5763980 100644 --- a/test/error.js +++ b/test/error.js @@ -20,10 +20,10 @@ test('properties', async t => { await got(s.url); t.fail('Exception was not thrown'); } catch (err) { - t.ok(err); - t.ok(err.response); - t.ok(!err.propertyIsEnumerable('response')); - t.ok(!err.hasOwnProperty('code')); + t.truthy(err); + t.truthy(err.response); + t.truthy(!err.propertyIsEnumerable('response')); + t.truthy(!err.hasOwnProperty('code')); t.is(err.message, 'Response code 404 (Not Found)'); t.is(err.host, `${s.host}:${s.port}`); t.is(err.method, 'GET'); @@ -35,8 +35,8 @@ test('dns message', async t => { await got('.com', {retries: 0}); t.fail('Exception was not thrown'); } catch (err) { - t.ok(err); - t.regexTest(/getaddrinfo ENOTFOUND/, err.message); + t.truthy(err); + t.regex(err.message, /getaddrinfo ENOTFOUND/); t.is(err.host, '.com'); t.is(err.method, 'GET'); } @@ -47,14 +47,14 @@ test('options.body error message', async t => { got(s.url, {body: () => {}}, () => {}); t.fail('Exception was not thrown'); } catch (err) { - t.regexTest(/options.body must be a ReadableStream, string, Buffer or plain Object/, err.message); + t.regex(err.message, /options.body must be a ReadableStream, string, Buffer or plain Object/); } try { await got(s.url, {body: () => {}}); t.fail('Exception was not thrown'); } catch (err) { - t.regexTest(/options.body must be a ReadableStream, string, Buffer or plain Object/, err.message); + t.regex(err.message, /options.body must be a ReadableStream, string, Buffer or plain Object/); } }); diff --git a/test/gzip.js b/test/gzip.js index bd8ba0a..92e7e57 100644 --- a/test/gzip.js +++ b/test/gzip.js @@ -49,7 +49,7 @@ test('handles gzip error', async t => { }); test('preserve headers property', async t => { - t.ok((await got(s.url)).headers); + t.truthy((await got(s.url)).headers); }); test('do not break HEAD responses', async t => { diff --git a/test/helpers.js b/test/helpers.js index 58bead5..baff3b0 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -4,7 +4,7 @@ import {createServer} from './_server'; let s; -test.before('setup', async t => { +test.before('setup', async () => { s = await createServer(); s.on('/', (req, res) => { @@ -19,7 +19,7 @@ test.before('setup', async t => { await s.listen(s.port); }); -test('callback mode', t => { +test.cb('callback mode', t => { got.get(s.url, function (err, body) { t.ifError(err); t.is(body, 'ok'); @@ -41,10 +41,10 @@ test('promise mode', async t => { await got.get('.com', {retries: 0}); t.fail('Exception was not thrown'); } catch (err) { - t.ok(err); + t.truthy(err); } }); -test.after('cleanup', async t => { +test.after('cleanup', async () => { await s.close(); }); diff --git a/test/http.js b/test/http.js index e04ff46..66c458f 100644 --- a/test/http.js +++ b/test/http.js @@ -58,7 +58,7 @@ test('error with code', async t => { test('buffer on encoding === null', async t => { const data = (await got(s.url, {encoding: null})).body; - t.ok(Buffer.isBuffer(data)); + t.truthy(Buffer.isBuffer(data)); }); test('timeout option', async t => { diff --git a/test/https.js b/test/https.js index 1bf5bc8..6a6b9f1 100644 --- a/test/https.js +++ b/test/https.js @@ -42,11 +42,11 @@ test.before('setup', async t => { }); test('redirects from http to https works', async t => { - t.ok((await got('http://github.com')).body); + t.truthy((await got('http://github.com')).body); }); test('make request to https server', async t => { - t.ok((await got('https://google.com', {strictSSL: true})).body); + t.truthy((await got('https://google.com', {strictSSL: true})).body); }); test('make request to https server with ca', async t => { diff --git a/test/json.js b/test/json.js index bd61c0e..5c34c89 100644 --- a/test/json.js +++ b/test/json.js @@ -34,7 +34,7 @@ test.before('setup', async t => { }); test('parses response', async t => { - t.same((await got(s.url, {json: true})).body, {data: 'dog'}); + t.deepEqual((await got(s.url, {json: true})).body, {data: 'dog'}); }); test('not parses responses without a body', async t => { @@ -47,8 +47,8 @@ test('wraps parsing errors', async t => { await got(`${s.url}/invalid`, {json: true}); t.fail('Exception was not thrown'); } catch (err) { - t.regexTest(/Unexpected token/, err.message); - t.ok(err.message.indexOf(err.hostname) !== -1, err.message); + t.regex(err.message, /Unexpected token/); + t.true(err.message.indexOf(err.hostname) !== -1, err.message); t.is(err.path, '/invalid'); } }); @@ -58,7 +58,7 @@ test('parses non-200 responses', async t => { await got(`${s.url}/non200`, {json: true}); t.fail('Exception was not thrown'); } catch (err) { - t.same(err.response.body, {data: 'dog'}); + t.deepEqual(err.response.body, {data: 'dog'}); } }); @@ -67,7 +67,7 @@ test('catches errors on invalid non-200 responses', async t => { await got(`${s.url}/non200-invalid`, {json: true}); t.fail('Exception was not thrown'); } catch (err) { - t.regexTest(/Unexpected token/, err.message); + t.regex(err.message, /Unexpected token/); t.is(err.response.body, 'Internal error'); t.is(err.path, '/non200-invalid'); } diff --git a/test/retry.js b/test/retry.js index d4f42d0..f1a02d1 100644 --- a/test/retry.js +++ b/test/retry.js @@ -39,7 +39,7 @@ test('can be disabled with option', async t => { try { await got(`${s.url}/try-me`, {timeout: 1000, retries: 0}); } catch (err) { - t.ok(err); + t.truthy(err); } t.is(trys, 1); @@ -54,18 +54,18 @@ test('falsy value prevent retries', async t => { try { await got(`${s.url}/long`, {timeout: 1000, retries: () => 0}); } catch (err) { - t.ok(err); + t.truthy(err); } }); test('falsy value prevent retries', async t => { try { await got(`${s.url}/long`, {timeout: 100, retries: (iter, err) => { - t.ok(err); + t.truthy(err); return false; }}); } catch (err) { - t.ok(err); + t.truthy(err); } }); diff --git a/test/stream.js b/test/stream.js index e4c9846..e65dc37 100644 --- a/test/stream.js +++ b/test/stream.js @@ -31,14 +31,14 @@ test.before('setup', async t => { await s.listen(s.port); }); -test('option.json can not be used', t => { +test.cb('option.json can not be used', t => { t.throws(() => { 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', t => { +test.cb('callback can not be used', t => { t.throws(() => { got.stream(s.url, {json: true}, () => {}); }, 'callback can not be used with stream mode'); @@ -54,7 +54,7 @@ test('callback can not be used', t => { t.end(); }); -test('returns readable stream', t => { +test.cb('returns readable stream', t => { got.stream(s.url) .on('data', data => { t.is(data.toString(), 'ok'); @@ -62,33 +62,33 @@ test('returns readable stream', t => { }); }); -test('returns writeable stream', t => { - t.plan(1); +test.cb('returns writeable stream', t => { got.stream.post(`${s.url}/post`) .on('data', data => { t.is(data.toString(), 'wow'); + t.end(); }) .end('wow'); }); -test('throws on write to stream with body specified', t => { +test.cb('throws on write to stream with body specified', t => { t.throws(() => { got.stream(s.url, {body: 'wow'}).write('wow'); }, 'got\'s stream is not writable when options.body is used'); // wait for request to end - setTimeout(t.end.bind(t), 10); + setTimeout(() => t.end(), 10); }); -test('have request event', t => { +test.cb('have request event', t => { got.stream(s.url) .on('request', req => { - t.ok(req); + t.truthy(req); t.end(); }); }); -test('have redirect event', t => { +test.cb('have redirect event', t => { got.stream(`${s.url}/redirect`) .on('redirect', res => { t.is(res.headers.location, s.url); @@ -96,7 +96,7 @@ test('have redirect event', t => { }); }); -test('have response event', t => { +test.cb('have response event', t => { got.stream(s.url) .on('response', res => { t.is(res.statusCode, 200); @@ -104,7 +104,7 @@ test('have response event', t => { }); }); -test('have error event', t => { +test.cb('have error event', t => { got.stream(`${s.url}/error`, {retries: 0}) .on('response', () => { t.fail('response event should not be emitted'); @@ -112,31 +112,30 @@ test('have error event', t => { .on('error', (err, data, res) => { t.is(err.message, 'Response code 404 (Not Found)'); t.is(null, data); - t.ok(res); + t.truthy(res); t.end(); }); }); -test('have error event', t => { +test.cb('throws error with invalid domain', t => { got.stream('.com', {retries: 0}) .on('response', () => { t.fail('response event should not be emitted'); }) .on('error', err => { - t.regexTest(/getaddrinfo ENOTFOUND/, err.message); + t.regex(err.message, /getaddrinfo ENOTFOUND/); t.end(); }); }); -test('accepts option.body as Stream', t => { +test.cb('accepts option.body as Stream', t => { got.stream(`${s.url}/post`, {body: intoStream(['wow'])}) .on('data', chunk => { t.is(chunk.toString(), 'wow'); t.end(); }); - }); -test.after('cleanup', async t => { +test.after('cleanup', async () => { await s.close(); });