Skip to content

Commit

Permalink
Upgrade to ava@1.0.0-beta.7
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Aug 12, 2018
1 parent f30b623 commit ca2675e
Show file tree
Hide file tree
Showing 17 changed files with 80 additions and 80 deletions.
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -45,7 +45,7 @@
"url-parse-lax": "^3.0.0"
},
"devDependencies": {
"ava": "^1.0.0-beta.6",
"ava": "1.0.0-beta.7",
"coveralls": "^3.0.0",
"delay": "^3.0.0",
"form-data": "^2.1.1",
Expand All @@ -58,7 +58,7 @@
"slow-stream": "0.0.4",
"tempfile": "^2.0.0",
"tempy": "^0.2.1",
"xo": "^0.21.1"
"xo": "^0.22.0"
},
"ava": {
"concurrency": 4
Expand Down
26 changes: 13 additions & 13 deletions test/arguments.js
Expand Up @@ -34,12 +34,12 @@ test.after('cleanup', async () => {
});

test('url is required', async t => {
const error = await t.throws(got());
const error = await t.throwsAsync(got());
t.regex(error.message, /Parameter `url` must be a string or object, not undefined/);
});

test('url should be utf-8 encoded', async t => {
const error = await t.throws(got(`${s.url}/%D2%E0%EB%EB%E8%ED`));
const error = await t.throwsAsync(got(`${s.url}/%D2%E0%EB%EB%E8%ED`));
t.regex(error.message, /Parameter `url` must contain valid UTF-8 character sequences/);
});

Expand Down Expand Up @@ -100,12 +100,12 @@ test('overrides querystring from opts', async t => {
});

test('should throw with auth in url string', async t => {
const error = await t.throws(got('https://test:45d3ps453@account.myservice.com/api/token'));
const error = await t.throwsAsync(got('https://test:45d3ps453@account.myservice.com/api/token'));
t.regex(error.message, /Basic authentication must be done with the `auth` option/);
});

test('does not throw with auth in url object', async t => {
await t.notThrows(got({
await t.notThrowsAsync(got({
auth: 'foo:bar',
hostname: s.host,
port: s.port,
Expand All @@ -114,12 +114,12 @@ test('does not throw with auth in url object', async t => {
});

test('should throw when body is set to object', async t => {
await t.throws(got(`${s.url}/`, {body: {}}), TypeError);
await t.throwsAsync(got(`${s.url}/`, {body: {}}), TypeError);
});

test('WHATWG URL support', async t => {
const wURL = new URL(`${s.url}/test`);
await t.notThrows(got(wURL));
await t.notThrowsAsync(got(wURL));
});

test('should return streams when using stream option', async t => {
Expand All @@ -133,12 +133,12 @@ test('should ignore JSON option when using stream option', async t => {
});

test('throws TypeError when `url` is passed as an option', async t => {
await t.throws(got('', {url: 'example.com'}), {instanceOf: TypeError});
await t.throws(got({url: 'example.com'}), {instanceOf: TypeError});
await t.throwsAsync(got('', {url: 'example.com'}), {instanceOf: TypeError});
await t.throwsAsync(got({url: 'example.com'}), {instanceOf: TypeError});
});

test('throws TypeError when `hooks` is not an object', async t => {
await t.throws(
await t.throwsAsync(
() => got(s.url, {hooks: 'not object'}),
{
instanceOf: TypeError,
Expand All @@ -148,7 +148,7 @@ test('throws TypeError when `hooks` is not an object', async t => {
});

test('throws TypeError when known `hooks` value is not an array', async t => {
await t.throws(
await t.throwsAsync(
() => got(s.url, {hooks: {beforeRequest: {}}}),
{
instanceOf: TypeError,
Expand All @@ -158,7 +158,7 @@ test('throws TypeError when known `hooks` value is not an array', async t => {
});

test('throws TypeError when known `hooks` array item is not a function', async t => {
await t.throws(
await t.throwsAsync(
() => got(s.url, {hooks: {beforeRequest: [{}]}}),
{
instanceOf: TypeError,
Expand All @@ -168,7 +168,7 @@ test('throws TypeError when known `hooks` array item is not a function', async t
});

test('allows extra keys in `hooks`', async t => {
await t.notThrows(() => got(`${s.url}/test`, {hooks: {extra: {}}}));
await t.notThrowsAsync(() => got(`${s.url}/test`, {hooks: {extra: {}}}));
});

test('throws when trying to modify baseUrl after options got normalized', async t => {
Expand All @@ -180,5 +180,5 @@ test('throws when trying to modify baseUrl after options got normalized', async
}
});

await t.throws(instanceA('/'), 'Failed to set baseUrl. Options are normalized already.');
await t.throwsAsync(instanceA('/'), 'Failed to set baseUrl. Options are normalized already.');
});
2 changes: 1 addition & 1 deletion test/cache.js
Expand Up @@ -102,6 +102,6 @@ test('Cache error throws got.CacheError', async t => {
const endpoint = '/no-store';
const cache = {};

const error = await t.throws(got(s.url + endpoint, {cache}));
const error = await t.throwsAsync(got(s.url + endpoint, {cache}));
t.is(error.name, 'CacheError');
});
20 changes: 10 additions & 10 deletions test/cancel.js
Expand Up @@ -53,8 +53,8 @@ test('cancel do not retry after cancelation', async t => {
p.cancel();
});

await t.throws(p, PCancelable.CancelError);
await t.notThrows(helper.aborted, 'Request finished instead of aborting.');
await t.throwsAsync(p, PCancelable.CancelError);
await t.notThrowsAsync(helper.aborted, 'Request finished instead of aborting.');
});

test('cancel in-progress request', async t => {
Expand All @@ -72,8 +72,8 @@ test('cancel in-progress request', async t => {
body.push(null);
});

await t.throws(p, PCancelable.CancelError);
await t.notThrows(helper.aborted, 'Request finished instead of aborting.');
await t.throwsAsync(p, PCancelable.CancelError);
await t.notThrowsAsync(helper.aborted, 'Request finished instead of aborting.');
});

test('cancel in-progress request with timeout', async t => {
Expand All @@ -91,8 +91,8 @@ test('cancel in-progress request with timeout', async t => {
body.push(null);
});

await t.throws(p, PCancelable.CancelError);
await t.notThrows(helper.aborted, 'Request finished instead of aborting.');
await t.throwsAsync(p, PCancelable.CancelError);
await t.notThrowsAsync(helper.aborted, 'Request finished instead of aborting.');
});

test('cancel immediately', async t => {
Expand All @@ -111,8 +111,8 @@ test('cancel immediately', async t => {

const p = got(`${s.url}/abort`);
p.cancel();
await t.throws(p);
await t.notThrows(aborted, 'Request finished instead of aborting.');
await t.throwsAsync(p);
await t.notThrowsAsync(aborted, 'Request finished instead of aborting.');
});

test('recover from cancelation using cancelable promise attribute', async t => {
Expand All @@ -128,7 +128,7 @@ test('recover from cancelation using cancelable promise attribute', async t => {

p.cancel();

await t.notThrows(recover);
await t.notThrowsAsync(recover);
});

test('recover from cancellation using error instance', async t => {
Expand All @@ -144,5 +144,5 @@ test('recover from cancellation using error instance', async t => {

p.cancel();

await t.notThrows(recover);
await t.notThrowsAsync(recover);
});
20 changes: 10 additions & 10 deletions test/error.js
Expand Up @@ -45,7 +45,7 @@ test.after('cleanup', async () => {
});

test('properties', async t => {
const error = await t.throws(got(s.url));
const error = await t.throwsAsync(got(s.url));
t.truthy(error);
t.truthy(error.response);
t.false({}.propertyIsEnumerable.call(error, 'response'));
Expand All @@ -60,27 +60,27 @@ test('properties', async t => {
});

test('dns message', async t => {
const error = await t.throws(got('.com', {retry: 0}));
const error = await t.throwsAsync(got('.com', {retry: 0}));
t.truthy(error);
t.regex(error.message, /getaddrinfo ENOTFOUND/);
t.is(error.host, '.com');
t.is(error.method, 'GET');
});

test('options.body error message', async t => {
await t.throws(got(s.url, {body: {}}), {
await t.throwsAsync(got(s.url, {body: {}}), {
message: 'The `body` option must be a stream.Readable, string or Buffer'
});
});

test('options.body json error message', async t => {
await t.throws(got(s.url, {body: Buffer.from('test'), json: true}), {
await t.throwsAsync(got(s.url, {body: Buffer.from('test'), json: true}), {
message: 'The `body` option must be an Object or Array when the `json` option is used'
});
});

test('options.body form error message', async t => {
await t.throws(got(s.url, {body: Buffer.from('test'), form: true}), {
await t.throwsAsync(got(s.url, {body: Buffer.from('test'), form: true}), {
message: 'The `body` option must be an Object when the `form` option is used'
});
});
Expand All @@ -96,19 +96,19 @@ test('no plain object restriction on body', async t => {
});

test('default status message', async t => {
const error = await t.throws(got(`${s.url}/default-status-message`));
const error = await t.throwsAsync(got(`${s.url}/default-status-message`));
t.is(error.statusCode, 400);
t.is(error.statusMessage, 'Bad Request');
});

test('custom status message', async t => {
const error = await t.throws(got(`${s.url}/custom-status-message`));
const error = await t.throwsAsync(got(`${s.url}/custom-status-message`));
t.is(error.statusCode, 400);
t.is(error.statusMessage, 'Something Exploded');
});

test('no status message is overriden by the default one', async t => {
const error = await t.throws(got(`${s.url}/no-status-message`));
const error = await t.throwsAsync(got(`${s.url}/no-status-message`));
t.is(error.statusCode, 400);
t.is(error.statusMessage, http.STATUS_CODES[400]);
});
Expand All @@ -117,7 +117,7 @@ test.serial('http.request error', async t => {
const stub = sinon.stub(http, 'request').callsFake(() => {
throw new TypeError('The header content contains invalid characters');
});
await t.throws(got(s.url), {instanceOf: got.RequestError, message: 'The header content contains invalid characters'});
await t.throwsAsync(got(s.url), {instanceOf: got.RequestError, message: 'The header content contains invalid characters'});
stub.restore();
});

Expand All @@ -131,7 +131,7 @@ test.serial('catch error in mimicResponse', async t => {
'mimic-response': mimicResponse
});

await t.throws(proxiedGot(s.url), {message: 'Error in mimic-response'});
await t.throwsAsync(proxiedGot(s.url), {message: 'Error in mimic-response'});
});

test('errors are thrown directly when options.stream is true', t => {
Expand Down
4 changes: 2 additions & 2 deletions test/gzip.js
Expand Up @@ -64,14 +64,14 @@ test('decompress content - stream', async t => {
});

test('handles gzip error', async t => {
const error = await t.throws(got(`${s.url}/corrupted`));
const error = await t.throwsAsync(got(`${s.url}/corrupted`));
t.is(error.message, 'incorrect header check');
t.is(error.path, '/corrupted');
t.is(error.name, 'ReadError');
});

test('handles gzip error - stream', async t => {
const error = await t.throws(getStream(got.stream(`${s.url}/corrupted`)));
const error = await t.throwsAsync(getStream(got.stream(`${s.url}/corrupted`)));
t.is(error.message, 'incorrect header check');
t.is(error.path, '/corrupted');
t.is(error.name, 'ReadError');
Expand Down
4 changes: 2 additions & 2 deletions test/helpers.js
Expand Up @@ -26,9 +26,9 @@ test.after('cleanup', async () => {
test('promise mode', async t => {
t.is((await got.get(s.url)).body, 'ok');

const error = await t.throws(got.get(`${s.url}/404`));
const error = await t.throwsAsync(got.get(`${s.url}/404`));
t.is(error.response.body, 'not found');

const error2 = await t.throws(got.get('.com', {retry: 0}));
const error2 = await t.throwsAsync(got.get('.com', {retry: 0}));
t.truthy(error2);
});
4 changes: 2 additions & 2 deletions test/hooks.js
Expand Up @@ -73,7 +73,7 @@ test('beforeRequest awaits async function', async t => {
});

test('beforeRequest rejects when beforeRequest throws', async t => {
await t.throws(
await t.throwsAsync(
() => got(s.url, {
hooks: {
beforeRequest: [
Expand All @@ -91,7 +91,7 @@ test('beforeRequest rejects when beforeRequest throws', async t => {
});

test('beforeRequest rejects when beforeRequest rejects', async t => {
await t.throws(
await t.throwsAsync(
() => got(s.url, {
hooks: {
beforeRequest: [() => Promise.reject(new Error('oops'))]
Expand Down
6 changes: 3 additions & 3 deletions test/http.js
Expand Up @@ -51,14 +51,14 @@ test('requestUrl response', async t => {
});

test('error with code', async t => {
const error = await t.throws(got(`${s.url}/404`));
const error = await t.throwsAsync(got(`${s.url}/404`));
t.is(error.statusCode, 404);
t.is(error.response.body, 'not');
});

test('status code 304 doesn\'t throw', async t => {
const p = got(`${s.url}/304`);
await t.notThrows(p);
await t.notThrowsAsync(p);
const response = await p;
t.is(response.statusCode, 304);
t.is(response.body, '');
Expand All @@ -69,7 +69,7 @@ test('doesn\'t throw on throwHttpErrors === false', async t => {
});

test('invalid protocol throws', async t => {
const error = await t.throws(got('c:/nope.com', {json: true}));
const error = await t.throwsAsync(got('c:/nope.com', {json: true}));
t.is(error.constructor, got.UnsupportedProtocolError);
});

Expand Down
8 changes: 4 additions & 4 deletions test/json-parse.js
Expand Up @@ -51,26 +51,26 @@ test('not parses responses without a body', async t => {
});

test('wraps parsing errors', async t => {
const error = await t.throws(got(`${s.url}/invalid`, {json: true}));
const error = await t.throwsAsync(got(`${s.url}/invalid`, {json: true}));
t.regex(error.message, /Unexpected token/);
t.true(error.message.includes(error.hostname), error.message);
t.is(error.path, '/invalid');
});

test('parses non-200 responses', async t => {
const error = await t.throws(got(`${s.url}/non200`, {json: true}));
const error = await t.throwsAsync(got(`${s.url}/non200`, {json: true}));
t.deepEqual(error.response.body, {data: 'dog'});
});

test('ignores errors on invalid non-200 responses', async t => {
const error = await t.throws(got(`${s.url}/non200-invalid`, {json: true}));
const error = await t.throwsAsync(got(`${s.url}/non200-invalid`, {json: true}));
t.is(error.message, 'Response code 500 (Internal Server Error)');
t.is(error.response.body, 'Internal error');
t.is(error.path, '/non200-invalid');
});

test('should have statusCode in error', async t => {
const error = await t.throws(got(`${s.url}/invalid`, {json: true}));
const error = await t.throwsAsync(got(`${s.url}/invalid`, {json: true}));
t.is(error.constructor, got.ParseError);
t.is(error.statusCode, 200);
});
Expand Down
6 changes: 3 additions & 3 deletions test/post.js
Expand Up @@ -58,7 +58,7 @@ test('sends plain objects as forms', async t => {
});

test('does NOT support sending arrays as forms', async t => {
await t.throws(got(s.url, {
await t.throwsAsync(got(s.url, {
body: ['such', 'wow'],
form: true
}), TypeError);
Expand Down Expand Up @@ -141,9 +141,9 @@ test('content-type header is not overriden when object in options.body', async t
});

test('throws when json body is not a plain object or array', async t => {
await t.throws(got(`${s.url}`, {body: '{}', json: true}), TypeError);
await t.throwsAsync(got(`${s.url}`, {body: '{}', json: true}), TypeError);
});

test('throws when form body is not a plain object or array', async t => {
await t.throws(got(`${s.url}`, {body: 'such=wow', form: true}), TypeError);
await t.throwsAsync(got(`${s.url}`, {body: 'such=wow', form: true}), TypeError);
});

0 comments on commit ca2675e

Please sign in to comment.