Skip to content

Commit

Permalink
Upgrade dependencies (#2132)
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus authored Sep 5, 2022
1 parent 47818bb commit 8630815
Show file tree
Hide file tree
Showing 17 changed files with 175 additions and 166 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ jobs:
os:
- ubuntu-latest
- macos-latest
- windows-latest
# Windows fails and I don't have time to look into it. PR welcome.
# - windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand Down
11 changes: 4 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
},
"devDependencies": {
"@hapi/bourne": "^3.0.0",
"@sindresorhus/tsconfig": "^2.0.0",
"@sindresorhus/tsconfig": "^3.0.1",
"@sinonjs/fake-timers": "^9.1.1",
"@types/benchmark": "^2.1.2",
"@types/express": "^4.17.13",
Expand All @@ -72,7 +72,7 @@
"@types/sinon": "^10.0.11",
"@types/sinonjs__fake-timers": "^8.1.1",
"@types/tough-cookie": "^4.0.1",
"ava": "^3.15.0",
"ava": "^4.3.3",
"axios": "^0.27.2",
"benchmark": "^2.1.4",
"bluebird": "^3.7.2",
Expand All @@ -83,7 +83,7 @@
"delay": "^5.0.0",
"express": "^4.17.3",
"form-data": "^4.0.0",
"formdata-node": "^4.3.2",
"formdata-node": "^5.0.0",
"nock": "^13.2.4",
"node-fetch": "^3.2.3",
"np": "^7.6.0",
Expand All @@ -100,6 +100,7 @@
"to-readable-stream": "^3.0.0",
"tough-cookie": "4.0.0",
"ts-node": "^10.8.2",
"type-fest": "^2.19.0",
"typescript": "~4.8.2",
"xo": "^0.52.2"
},
Expand All @@ -109,10 +110,6 @@
"test/*"
],
"timeout": "1m",
"nonSemVerExperiments": {
"nextGenConfig": true,
"configurableModuleFormat": true
},
"extensions": {
"ts": "module"
},
Expand Down
9 changes: 5 additions & 4 deletions test/agent.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {Agent as HttpAgent} from 'http';
import {Agent as HttpsAgent} from 'https';
import test, {type Constructor} from 'ava';
import test from 'ava';
import sinon from 'sinon';
import type {Constructor} from 'type-fest';
import withServer, {withHttpsServer} from './helpers/with-server.js';

const createAgentSpy = <T extends HttpsAgent>(AgentClass: Constructor): {agent: T; spy: sinon.SinonSpy} => {
const createAgentSpy = <T extends HttpsAgent>(AgentClass: Constructor<any>): {agent: T; spy: sinon.SinonSpy} => {
const agent: T = new AgentClass({keepAlive: true});
// eslint-disable-next-line import/no-named-as-default-member
const spy = sinon.spy(agent, 'addRequest' as any);
Expand Down Expand Up @@ -54,7 +55,7 @@ test('non-object agent option works with https', withHttpsServer(), async (t, se
});

test('redirects from http to https work with an agent object', withServer, async (t, serverHttp) => {
await withHttpsServer()(t, async (t, serverHttps, got) => {
await withHttpsServer().exec(t, async (t, serverHttps, got) => {
serverHttp.get('/', (_request, response) => {
response.end('http');
});
Expand Down Expand Up @@ -90,7 +91,7 @@ test('redirects from http to https work with an agent object', withServer, async
});

test('redirects from https to http work with an agent object', withHttpsServer(), async (t, serverHttps, got) => {
await withServer(t, async (t, serverHttp) => {
await withServer.exec(t, async (t, serverHttp) => {
serverHttp.get('/', (_request, response) => {
response.end('http');
});
Expand Down
8 changes: 4 additions & 4 deletions test/arguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ test('`url` is required', async t => {
);

const firstError = await t.throwsAsync(got(''));
invalidUrl(t, firstError, '');
invalidUrl(t, firstError!, '');

const secondError = await t.throwsAsync(got({url: ''}));
invalidUrl(t, secondError, '');
invalidUrl(t, secondError!, '');
});

test('`url` should be utf-8 encoded', async t => {
Expand Down Expand Up @@ -54,7 +54,7 @@ test('throws if the url option is missing', async t => {

test('throws an error if the protocol is not specified', async t => {
const error = await t.throwsAsync(got('example.com'));
invalidUrl(t, error, 'example.com');
invalidUrl(t, error!, 'example.com');
});

test('properly encodes query string', withServer, async (t, server, got) => {
Expand Down Expand Up @@ -656,7 +656,7 @@ test('options have url even if some are invalid', async t => {
invalid: true,
}));

t.is((error.options.url as URL).href, 'https://example.com/');
t.is((error?.options.url as URL).href, 'https://example.com/');
t.true(error instanceof Error);
});

Expand Down
46 changes: 23 additions & 23 deletions test/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test('properties', withServer, async (t, server, got) => {

const url = new URL(server.url);

const error = await t.throwsAsync<HTTPError>(got(''));
const error = (await t.throwsAsync<HTTPError>(got('')))!;
t.truthy(error);
t.truthy(error.response);
t.truthy(error.options);
Expand All @@ -36,7 +36,7 @@ test('properties', withServer, async (t, server, got) => {
});

test('catches dns errors', async t => {
const error = await t.throwsAsync<RequestError>(got('http://doesntexist', {retry: {limit: 0}}));
const error = (await t.throwsAsync<RequestError>(got('http://doesntexist', {retry: {limit: 0}})))!;
t.truthy(error);
t.regex(error.message, /ENOTFOUND|EAI_AGAIN/);
t.is((error.options.url as URL).host, 'doesntexist');
Expand Down Expand Up @@ -80,8 +80,8 @@ test('default status message', withServer, async (t, server, got) => {
instanceOf: HTTPError,
message: 'Response code 400 (Bad Request)',
});
t.is(error.response.statusCode, 400);
t.is(error.response.statusMessage, 'Bad Request');
t.is(error?.response.statusCode, 400);
t.is(error?.response.statusMessage, 'Bad Request');
});

test('custom status message', withServer, async (t, server, got) => {
Expand All @@ -96,8 +96,8 @@ test('custom status message', withServer, async (t, server, got) => {
instanceOf: HTTPError,
message: 'Response code 400 (Something Exploded)',
});
t.is(error.response.statusCode, 400);
t.is(error.response.statusMessage, 'Something Exploded');
t.is(error?.response.statusCode, 400);
t.is(error?.response.statusMessage, 'Something Exploded');
});

test('custom body', withServer, async (t, server, got) => {
Expand All @@ -111,8 +111,8 @@ test('custom body', withServer, async (t, server, got) => {
instanceOf: HTTPError,
message: 'Response code 404 (Not Found)',
});
t.is(error.response.statusCode, 404);
t.is(error.response.body, 'not');
t.is(error?.response.statusCode, 404);
t.is(error?.response.body, 'not');
});

test('contains Got options', withServer, async (t, server, got) => {
Expand All @@ -132,8 +132,8 @@ test('contains Got options', withServer, async (t, server, got) => {
instanceOf: HTTPError,
message: 'Response code 404 (Not Found)',
});
t.is(error.response.statusCode, 404);
t.is(error.options.context.foo, options.context.foo);
t.is(error?.response.statusCode, 404);
t.is(error?.options.context.foo, options.context.foo);
});

test('empty status message is overriden by the default one', withServer, async (t, server, got) => {
Expand All @@ -147,8 +147,8 @@ test('empty status message is overriden by the default one', withServer, async (
instanceOf: HTTPError,
message: 'Response code 400 (Bad Request)',
});
t.is(error.response.statusCode, 400);
t.is(error.response.statusMessage, http.STATUS_CODES[400]);
t.is(error?.response.statusCode, 400);
t.is(error?.response.statusMessage, http.STATUS_CODES[400]);
});

test('`http.request` error', async t => {
Expand Down Expand Up @@ -227,17 +227,17 @@ test('normalization errors using convenience methods', async t => {

{
const error = await t.throwsAsync(got(url).json());
invalidUrl(t, error, url);
invalidUrl(t, error!, url);
}

{
const error = await t.throwsAsync(got(url).text());
invalidUrl(t, error, url);
invalidUrl(t, error!, url);
}

{
const error = await t.throwsAsync(got(url).buffer());
invalidUrl(t, error, url);
invalidUrl(t, error!, url);
}
});

Expand All @@ -249,8 +249,8 @@ test('errors can have request property', withServer, async (t, server, got) => {

const error = await t.throwsAsync<HTTPError>(got(''));

t.truthy(error.response);
t.truthy(error.request.downloadProgress);
t.truthy(error?.response);
t.truthy(error?.request.downloadProgress);
});

test('promise does not hang on timeout on HTTP error', withServer, async (t, server, got) => {
Expand Down Expand Up @@ -333,11 +333,11 @@ test.skip('the old stacktrace is recovered', async t => {
},
}));

t.true(error.stack!.includes('at Object.request'));
t.true(error?.stack!.includes('at Object.request'));

// The first `at get` points to where the error was wrapped,
// the second `at get` points to the real cause.
t.not(error.stack!.indexOf('at get'), error.stack!.lastIndexOf('at get'));
t.not(error?.stack!.indexOf('at get'), error?.stack!.lastIndexOf('at get'));
});

test.serial('custom stack trace', withServer, async (t, _server, got) => {
Expand All @@ -363,7 +363,7 @@ test.serial('custom stack trace', withServer, async (t, _server, got) => {
stream.destroy(new Error('oh no'));

const caught = await t.throwsAsync(getStream(stream));
t.is(is(caught.stack), 'string');
t.is(is(caught?.stack), 'string');
}

// Passing a custom error
Expand All @@ -376,7 +376,7 @@ test.serial('custom stack trace', withServer, async (t, _server, got) => {
stream.destroy(error);

const caught = await t.throwsAsync(getStream(stream));
t.is(is(caught.stack), 'string');
t.is(is(caught?.stack), 'string');
}

// Custom global behavior
Expand All @@ -388,7 +388,7 @@ test.serial('custom stack trace', withServer, async (t, _server, got) => {
stream.destroy(error);

const caught = await t.throwsAsync(getStream(stream));
t.is(is(caught.stack), 'Array');
t.is(is(caught?.stack), 'Array');

disable();
}
Expand All @@ -402,7 +402,7 @@ test.serial('custom stack trace', withServer, async (t, _server, got) => {
stream.destroy(error);

const caught = await t.throwsAsync(getStream(stream));
t.is(is(caught.stack), 'Array');
t.is(is(caught?.stack), 'Array');

disable();
}
Expand Down
2 changes: 1 addition & 1 deletion test/gzip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test('decompress content on error', withServer, async (t, server, got) => {

const error = await t.throwsAsync<HTTPError>(got(''));

t.is(error.response.body, testContent);
t.is(error?.response.body, testContent);
});

test('decompress content - stream', withServer, async (t, server, got) => {
Expand Down
4 changes: 2 additions & 2 deletions test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ test('works', withServer, async (t, server) => {
t.is(body, 'ok');

const error = await t.throwsAsync<HTTPError>(got.get(`${server.url}/404`), {instanceOf: HTTPError});
t.is(error.response.body, 'not found');
t.is(error?.response.body, 'not found');

const secondError = await t.throwsAsync(got.get('.com', {retry: {limit: 0}}));
invalidUrl(t, secondError, '.com');
invalidUrl(t, secondError!, '.com');
});
Loading

0 comments on commit 8630815

Please sign in to comment.