diff --git a/benchmark/index.ts b/benchmark/index.ts index 41de63de3..d97e0f355 100644 --- a/benchmark/index.ts +++ b/benchmark/index.ts @@ -66,20 +66,20 @@ const suite = new Benchmark.Suite(); // Benchmarking suite.add('got - promise', { defer: true, - fn: async (deferred: {resolve: () => void}) => { + async fn(deferred: {resolve: () => void}) { await got(url, gotOptions); deferred.resolve(); }, }).add('got - stream', { defer: true, - fn: async (deferred: {resolve: () => void}) => { + async fn(deferred: {resolve: () => void}) { got.stream(url, gotOptions).resume().once('end', () => { deferred.resolve(); }); }, }).add('got - core', { defer: true, - fn: async (deferred: {resolve: () => void}) => { + async fn(deferred: {resolve: () => void}) { const stream = new Request(url, gotOptions); void stream.flush(); stream.resume().once('end', () => { @@ -88,7 +88,7 @@ suite.add('got - promise', { }, }).add('got - core - normalized options', { defer: true, - fn: async (deferred: {resolve: () => void}) => { + async fn(deferred: {resolve: () => void}) { const stream = new Request(undefined, undefined, normalizedGotOptions); void stream.flush(); stream.resume().once('end', () => { @@ -97,7 +97,7 @@ suite.add('got - promise', { }, }).add('request - callback', { defer: true, - fn: (deferred: {resolve: () => void}) => { + fn(deferred: {resolve: () => void}) { request(urlString, requestOptions, (error: Error) => { if (error) { throw error; @@ -108,7 +108,7 @@ suite.add('got - promise', { }, }).add('request - stream', { defer: true, - fn: (deferred: {resolve: () => void}) => { + fn(deferred: {resolve: () => void}) { const stream = request(urlString, requestOptions); stream.resume(); stream.once('end', () => { @@ -117,7 +117,7 @@ suite.add('got - promise', { }, }).add('node-fetch - promise', { defer: true, - fn: async (deferred: {resolve: () => void}) => { + async fn(deferred: {resolve: () => void}) { const response = await fetch(urlString, fetchOptions); await response.text(); @@ -125,7 +125,7 @@ suite.add('got - promise', { }, }).add('node-fetch - stream', { defer: true, - fn: async (deferred: {resolve: () => void}) => { + async fn(deferred: {resolve: () => void}) { const {body} = await fetch(urlString, fetchOptions); body!.resume(); @@ -135,13 +135,13 @@ suite.add('got - promise', { }, }).add('axios - promise', { defer: true, - fn: async (deferred: {resolve: () => void}) => { + async fn(deferred: {resolve: () => void}) { await axios.request(axiosOptions); deferred.resolve(); }, }).add('axios - stream', { defer: true, - fn: async (deferred: {resolve: () => void}) => { + async fn(deferred: {resolve: () => void}) { const result = await axios.request(axiosStreamOptions); const {data}: any = result; @@ -152,7 +152,7 @@ suite.add('got - promise', { }, }).add('https - stream', { defer: true, - fn: (deferred: {resolve: () => void}) => { + fn(deferred: {resolve: () => void}) { https.request(urlString, httpsOptions, response => { response.resume(); response.once('end', () => { @@ -173,7 +173,7 @@ const internalBenchmark = (): void => { const internalSuite = new Benchmark.Suite(); internalSuite.add('got - normalize options', { - fn: () => { + fn() { // eslint-disable-next-line no-new new Options(url, gotOptions); }, diff --git a/package.json b/package.json index 201c49d79..1869ef6e0 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "ky" ], "dependencies": { - "@sindresorhus/is": "^4.2.0", + "@sindresorhus/is": "^4.6.0", "@szmarczak/http-timer": "^5.0.1", "@types/cacheable-request": "^6.0.2", "@types/responselike": "^1.0.0", @@ -53,7 +53,7 @@ "decompress-response": "^6.0.0", "form-data-encoder": "1.7.1", "get-stream": "^6.0.1", - "http2-wrapper": "^2.1.9", + "http2-wrapper": "^2.1.10", "lowercase-keys": "^3.0.0", "p-cancelable": "^3.0.0", "responselike": "^2.0.0" @@ -61,47 +61,47 @@ "devDependencies": { "@hapi/bourne": "^2.0.0", "@sindresorhus/tsconfig": "^2.0.0", - "@sinonjs/fake-timers": "^8.1.0", + "@sinonjs/fake-timers": "^9.1.1", "@types/benchmark": "^2.1.1", "@types/express": "^4.17.13", - "@types/node": "^16.11.12", + "@types/node": "^17.0.21", "@types/pem": "^1.9.6", "@types/pify": "^5.0.1", - "@types/readable-stream": "^2.3.12", - "@types/request": "^2.48.7", - "@types/sinon": "^10.0.6", + "@types/readable-stream": "^2.3.13", + "@types/request": "^2.48.8", + "@types/sinon": "^10.0.11", "@types/sinonjs__fake-timers": "^8.1.1", "@types/tough-cookie": "^4.0.1", "ava": "^3.15.0", - "axios": "^0.24.0", + "axios": "^0.26.1", "benchmark": "^2.1.4", "bluebird": "^3.7.2", - "body-parser": "^1.19.0", + "body-parser": "^1.19.2", "create-cert": "^1.0.6", "create-test-server": "^3.0.1", "del-cli": "^4.0.1", "delay": "^5.0.0", - "express": "^4.17.1", + "express": "^4.17.3", "form-data": "^4.0.0", - "formdata-node": "^4.3.1", - "nock": "^13.2.1", - "node-fetch": "^3.1.0", + "formdata-node": "^4.3.2", + "nock": "^13.2.4", + "node-fetch": "^3.2.3", "np": "^7.6.0", "nyc": "^15.1.0", "p-event": "^5.0.1", - "pem": "^1.14.4", + "pem": "^1.14.6", "pify": "^5.0.0", "readable-stream": "^3.6.0", "request": "^2.88.2", - "sinon": "^12.0.1", + "sinon": "^13.0.1", "slow-stream": "0.0.4", "tempy": "^2.0.0", "then-busboy": "^5.1.1", "to-readable-stream": "^3.0.0", "tough-cookie": "^4.0.0", - "ts-node": "^10.4.0", - "typescript": "4.5.3", - "xo": "^0.47.0" + "ts-node": "^10.7.0", + "typescript": "4.6.2", + "xo": "^0.48.0" }, "types": "dist/source", "sideEffects": false, diff --git a/source/core/index.ts b/source/core/index.ts index 3d8d5b3b7..873c54067 100644 --- a/source/core/index.ts +++ b/source/core/index.ts @@ -448,8 +448,9 @@ export default class Request extends Duplex implements RequestEvents { } let data; + while ((data = response.read()) !== null) { - this._downloadedSize += data.length; + this._downloadedSize += data.length; // eslint-disable-line @typescript-eslint/restrict-plus-operands const progress = this.downloadProgress; @@ -462,7 +463,7 @@ export default class Request extends Duplex implements RequestEvents { } } - override _write(chunk: unknown, encoding: BufferEncoding | undefined, callback: (error?: Error | null) => void): void { + override _write(chunk: unknown, encoding: BufferEncoding | undefined, callback: (error?: Error | null) => void): void { // eslint-disable-line @typescript-eslint/ban-types const write = (): void => { this._writeRequest(chunk, encoding, callback); }; @@ -474,7 +475,7 @@ export default class Request extends Duplex implements RequestEvents { } } - override _final(callback: (error?: Error | null) => void): void { + override _final(callback: (error?: Error | null) => void): void { // eslint-disable-line @typescript-eslint/ban-types const endRequest = (): void => { // We need to check if `this._request` is present, // because it isn't when we use cache. @@ -483,7 +484,7 @@ export default class Request extends Duplex implements RequestEvents { return; } - this._request.end((error?: Error | null) => { + this._request.end((error?: Error | null) => { // eslint-disable-line @typescript-eslint/ban-types // The request has been destroyed before `_final` finished. // See https://github.com/nodejs/node/issues/39356 if ((this._request as any)._writableState?.errored) { @@ -508,7 +509,7 @@ export default class Request extends Duplex implements RequestEvents { } } - override _destroy(error: Error | null, callback: (error: Error | null) => void): void { + override _destroy(error: Error | null, callback: (error: Error | null) => void): void { // eslint-disable-line @typescript-eslint/ban-types this._stopReading = true; this.flush = async () => {}; @@ -1186,13 +1187,13 @@ export default class Request extends Duplex implements RequestEvents { this.destroy(error); } - private _writeRequest(chunk: any, encoding: BufferEncoding | undefined, callback: (error?: Error | null) => void): void { + private _writeRequest(chunk: any, encoding: BufferEncoding | undefined, callback: (error?: Error | null) => void): void { // eslint-disable-line @typescript-eslint/ban-types if (!this._request || this._request.destroyed) { // Probably the `ClientRequest` instance will throw return; } - this._request.write(chunk, encoding!, (error?: Error | null) => { + this._request.write(chunk, encoding!, (error?: Error | null) => { // eslint-disable-line @typescript-eslint/ban-types if (!error) { this._uploadedSize += Buffer.byteLength(chunk, encoding); diff --git a/source/core/options.ts b/source/core/options.ts index ca7994f3c..ef158ec83 100644 --- a/source/core/options.ts +++ b/source/core/options.ts @@ -56,10 +56,10 @@ export interface Agents { export type Headers = Record; export interface ToughCookieJar { - getCookieString: ((currentUrl: string, options: Record, cb: (error: Error | null, cookies: string) => void) => void) - & ((url: string, callback: (error: Error | null, cookieHeader: string) => void) => void); - setCookie: ((cookieOrString: unknown, currentUrl: string, options: Record, cb: (error: Error | null, cookie: unknown) => void) => void) - & ((rawCookie: string, url: string, callback: (error: Error | null, result: unknown) => void) => void); + getCookieString: ((currentUrl: string, options: Record, cb: (error: Error | null, cookies: string) => void) => void) // eslint-disable-line @typescript-eslint/ban-types + & ((url: string, callback: (error: Error | null, cookieHeader: string) => void) => void); // eslint-disable-line @typescript-eslint/ban-types + setCookie: ((cookieOrString: unknown, currentUrl: string, options: Record, cb: (error: Error | null, cookie: unknown) => void) => void) // eslint-disable-line @typescript-eslint/ban-types + & ((rawCookie: string, url: string, callback: (error: Error | null, result: unknown) => void) => void); // eslint-disable-line @typescript-eslint/ban-types } export interface PromiseCookieJar { @@ -621,9 +621,9 @@ export interface PaginationOptions { stackAllItems?: boolean; } -export type SearchParameters = Record; +export type SearchParameters = Record; // eslint-disable-line @typescript-eslint/ban-types -function validateSearchParameters(searchParameters: Record): asserts searchParameters is Record { +function validateSearchParameters(searchParameters: Record): asserts searchParameters is Record { // eslint-disable-line @typescript-eslint/ban-types // eslint-disable-next-line guard-for-in for (const key in searchParameters) { const value = searchParameters[key]; @@ -794,14 +794,14 @@ const defaultInternals: Options['_internals'] = { responseType: 'text', url: undefined, pagination: { - transform: (response: Response) => { + transform(response: Response) { if (response.request.options.responseType === 'json') { return response.body; } return JSON.parse(response.body as string); }, - paginate: ({response}) => { + paginate({response}) { const rawLinkHeader = response.headers.link; if (typeof rawLinkHeader !== 'string' || rawLinkHeader.trim() === '') { return false; diff --git a/source/core/utils/is-form-data.ts b/source/core/utils/is-form-data.ts index 0f8a5a360..81335ee50 100644 --- a/source/core/utils/is-form-data.ts +++ b/source/core/utils/is-form-data.ts @@ -3,7 +3,7 @@ import is from '@sindresorhus/is'; interface FormData extends Readable { getBoundary: () => string; - getLength: (callback: (error: Error | null, length: number) => void) => void; + getLength: (callback: (error: Error | null, length: number) => void) => void; // eslint-disable-line @typescript-eslint/ban-types } export default function isFormData(body: unknown): body is FormData { diff --git a/source/core/utils/url-to-options.ts b/source/core/utils/url-to-options.ts index 0ad451a76..f880fb33c 100644 --- a/source/core/utils/url-to-options.ts +++ b/source/core/utils/url-to-options.ts @@ -7,8 +7,8 @@ export interface LegacyUrlOptions { protocol: string; hostname: string; host: string; - hash: string | null; - search: string | null; + hash: string | null; // eslint-disable-line @typescript-eslint/ban-types + search: string | null; // eslint-disable-line @typescript-eslint/ban-types pathname: string; href: string; path: string; diff --git a/test/cancel.ts b/test/cancel.ts index a31b9144d..d87b2ed0c 100644 --- a/test/cancel.ts +++ b/test/cancel.ts @@ -68,7 +68,7 @@ test.serial('does not retry after cancelation', withServerAndFakeTimers, async ( const gotPromise = got('redirect', { retry: { - calculateDelay: () => { + calculateDelay() { t.fail('Makes a new try after cancelation'); return 0; }, @@ -94,7 +94,7 @@ test.serial('cleans up request timeouts', withServer, async (t, server, got) => request: 10, }, retry: { - calculateDelay: ({computedValue}) => { + calculateDelay({computedValue}) { process.nextTick(() => { gotPromise.cancel(); }); diff --git a/test/cookies.ts b/test/cookies.ts index c52a71ddc..e706830a4 100644 --- a/test/cookies.ts +++ b/test/cookies.ts @@ -86,15 +86,15 @@ test('does not throw on invalid cookies when options.ignoreInvalidCookies is set test('catches store errors', async t => { const error = 'Some error'; const cookieJar = new toughCookie.CookieJar({ - findCookies: (_, __, ___, callback) => { + findCookies(_, __, ___, callback) { callback(new Error(error), []); }, - findCookie: () => {}, - getAllCookies: () => {}, - putCookie: () => {}, - removeCookies: () => {}, - removeCookie: () => {}, - updateCookie: () => {}, + findCookie() {}, + getAllCookies() {}, + putCookie() {}, + removeCookies() {}, + removeCookie() {}, + updateCookie() {}, synchronous: false, }); @@ -132,8 +132,8 @@ test('no unhandled errors', async t => { const options = { cookieJar: { - setCookie: async (_rawCookie: string, _url: string) => {}, - getCookieString: async (_url: string) => { + async setCookie(_rawCookie: string, _url: string) {}, + async getCookieString(_url: string) { throw new Error(message); }, }, @@ -183,7 +183,7 @@ test('throws on invalid `options.cookieJar.setCookie`', async t => { test('throws on invalid `options.cookieJar.getCookieString`', async t => { await t.throwsAsync(got('https://example.com', { cookieJar: { - setCookie: async () => {}, + async setCookie() {}, // @ts-expect-error Error tests getCookieString: 123, }, diff --git a/test/error.ts b/test/error.ts index 9395aacd7..10c174982 100644 --- a/test/error.ts +++ b/test/error.ts @@ -129,7 +129,7 @@ test('empty status message is overriden by the default one', withServer, async ( test('`http.request` error', async t => { await t.throwsAsync(got('https://example.com', { - request: () => { + request() { throw new TypeError('The header content contains invalid characters'); }, }), { @@ -144,13 +144,13 @@ test('`http.request` pipe error', async t => { await t.throwsAsync(got('https://example.com', { // @ts-expect-error Error tests - request: () => { + request() { const proxy = new stream.PassThrough(); const anyProxy = proxy as any; anyProxy.socket = { remoteAddress: '', - prependOnceListener: () => {}, + prependOnceListener() {}, }; anyProxy.headers = {}; @@ -175,7 +175,7 @@ test('`http.request` pipe error', async t => { test('`http.request` error through CacheableRequest', async t => { await t.throwsAsync(got('https://example.com', { - request: () => { + request() { throw new TypeError('The header content contains invalid characters'); }, cache: new Map(), @@ -301,7 +301,7 @@ test('no uncaught parse errors #2', async t => { // eslint-disable-next-line ava/no-skip-test test.skip('the old stacktrace is recovered', async t => { const error = await t.throwsAsync(got('https://example.com', { - request: () => { + request() { throw new Error('foobar'); }, })); diff --git a/test/hooks.ts b/test/hooks.ts index fb60aff5a..2136a9a00 100644 --- a/test/hooks.ts +++ b/test/hooks.ts @@ -253,7 +253,7 @@ test('catches afterResponse promise rejections', withServer, async (t, server, g test('catches beforeError errors', async t => { await t.throwsAsync(got('https://example.com', { - request: () => { + request() { throw new Error('No way'); }, hooks: { @@ -841,7 +841,7 @@ test('beforeError allows modifications', async t => { const errorString2 = 'foobar'; await t.throwsAsync(got('https://example.com', { - request: () => { + request() { throw error; }, hooks: { diff --git a/test/http.ts b/test/http.ts index 22bdc0b02..8ff23637c 100644 --- a/test/http.ts +++ b/test/http.ts @@ -366,7 +366,7 @@ test('JSON request custom stringifier', withServer, async (t, server, got) => { test('ClientRequest can throw before promise resolves', async t => { await t.throwsAsync(got('http://example.com', { - dnsLookup: ((_hostname: string, _options: unknown, callback: (error: null, hostname: string, family: number) => void) => { + dnsLookup: ((_hostname: string, _options: unknown, callback: (error: null, hostname: string, family: number) => void) => { // eslint-disable-line @typescript-eslint/ban-types queueMicrotask(() => { callback(null, 'fe80::0000:0000:0000:0000', 6); }); diff --git a/test/https.ts b/test/https.ts index 6df5e67ff..7053fcb5d 100644 --- a/test/https.ts +++ b/test/https.ts @@ -80,7 +80,7 @@ test('https request with `checkServerIdentity` OK', withHttpsServer(), async (t, const {body} = await got({ https: { - checkServerIdentity: (hostname: string, certificate: DetailedPeerCertificate) => { + checkServerIdentity(hostname: string, certificate: DetailedPeerCertificate) { t.is(hostname, 'localhost'); t.is(certificate.subject.CN, 'localhost'); t.is(certificate.issuer.CN, 'authority'); @@ -98,7 +98,7 @@ test('https request with `checkServerIdentity` NOT OK', withHttpsServer(), async const promise = got({ https: { - checkServerIdentity: (hostname: string, certificate: DetailedPeerCertificate) => { + checkServerIdentity(hostname: string, certificate: DetailedPeerCertificate) { t.is(hostname, 'localhost'); t.is(certificate.subject.CN, 'localhost'); t.is(certificate.issuer.CN, 'authority'); diff --git a/test/pagination.ts b/test/pagination.ts index af3b6da03..2eae5f4b5 100644 --- a/test/pagination.ts +++ b/test/pagination.ts @@ -100,7 +100,7 @@ test('filters elements', withServer, async (t, server, got) => { const result = await got.paginate.all({ pagination: { - filter: ({item, currentItems, allItems}) => { + filter({item, currentItems, allItems}) { t.true(Array.isArray(allItems)); t.true(Array.isArray(currentItems)); @@ -141,7 +141,7 @@ test('custom paginate function', withServer, async (t, server, got) => { const result = await got.paginate.all({ pagination: { - paginate: ({response}) => { + paginate({response}) { const url = new URL(response.url); if (url.search === '?page=3') { @@ -163,7 +163,7 @@ test('custom paginate function using allItems', withServer, async (t, server, go const result = await got.paginate.all({ pagination: { - paginate: ({allItems, response}) => { + paginate({allItems, response}) { if (allItems.length === 2) { return false; } @@ -184,7 +184,7 @@ test('custom paginate function using currentItems', withServer, async (t, server const result = await got.paginate.all({ pagination: { - paginate: ({currentItems, response}) => { + paginate({currentItems, response}) { if (currentItems[0] === 3) { return false; } @@ -228,7 +228,7 @@ test('`shouldContinue` works', withServer, async (t, server, got) => { const options = { pagination: { - shouldContinue: ({currentItems, allItems}: {allItems: number[]; currentItems: number[]}) => { + shouldContinue({currentItems, allItems}: {allItems: number[]; currentItems: number[]}) { t.true(Array.isArray(allItems)); t.true(Array.isArray(currentItems)); @@ -367,7 +367,7 @@ test('`hooks` are not duplicated', withServer, async (t, server, got) => { const result = await got.paginate.all({ pagination: { - paginate: ({response}) => { + paginate({response}) { if ((response.body as string) === '[3]') { return false; // Stop after page 3 } @@ -421,7 +421,7 @@ test('allowGetBody sends correct json payload with .paginate()', withServer, asy }, json: {body}, pagination: { - paginate: () => { + paginate() { if (body.length === 2) { return false; } @@ -497,17 +497,17 @@ test('`stackAllItems` set to true', withServer, async (t, server, got) => { const result = await got.paginate.all({ pagination: { stackAllItems: true, - filter: ({allItems}) => { + filter({allItems}) { t.is(allItems.length, itemCount); return true; }, - shouldContinue: ({allItems}) => { + shouldContinue({allItems}) { t.is(allItems.length, itemCount); return true; }, - paginate: ({response, currentItems, allItems}) => { + paginate({response, currentItems, allItems}) { itemCount += 1; t.is(allItems.length, itemCount); @@ -525,17 +525,17 @@ test('`stackAllItems` set to false', withServer, async (t, server, got) => { const result = await got.paginate.all({ pagination: { stackAllItems: false, - filter: ({allItems}) => { + filter({allItems}) { t.is(allItems.length, 0); return true; }, - shouldContinue: ({allItems}) => { + shouldContinue({allItems}) { t.is(allItems.length, 0); return true; }, - paginate: ({response, currentItems, allItems}) => { + paginate({response, currentItems, allItems}) { t.is(allItems.length, 0); return got.defaults.options.pagination.paginate!({response, allItems, currentItems}); @@ -569,7 +569,7 @@ test('next url in json response', withServer, async (t, server, got) => { responseType: 'json', pagination: { transform: (response: Response) => [response.body.currentUrl], - paginate: ({response}) => { + paginate({response}) { const {next} = response.body; if (!next) { @@ -616,7 +616,7 @@ test('pagination using searchParams', withServer, async (t, server, got) => { responseType: 'json', pagination: { transform: (response: Response) => [response.body.currentUrl], - paginate: ({response}) => { + paginate({response}) { const {next} = response.body; // eslint-disable-next-line unicorn/prevent-abbreviations const searchParams = response.request.options.searchParams as URLSearchParams; @@ -672,7 +672,7 @@ test('pagination using extended searchParams', withServer, async (t, server, got responseType: 'json', pagination: { transform: (response: Response) => [response.body.currentUrl], - paginate: ({response}) => { + paginate({response}) { const {next} = response.body; // eslint-disable-next-line unicorn/prevent-abbreviations const searchParams = response.request.options.searchParams as URLSearchParams; diff --git a/test/promise.ts b/test/promise.ts index da72d98c0..6de528333 100644 --- a/test/promise.ts +++ b/test/promise.ts @@ -64,9 +64,9 @@ test('promise.json() can be called before a file stream body is open', withServe // @ts-expect-error @types/node has wrong types. const body = new ReadStream('', { fs: { - open: () => {}, - read: () => {}, - close: () => {}, + open() {}, + read() {}, + close() {}, }, }); diff --git a/test/retry.ts b/test/retry.ts index b802c1c70..2edc09b5b 100644 --- a/test/retry.ts +++ b/test/retry.ts @@ -46,11 +46,11 @@ test('works on timeout', withServer, async (t, server, got) => { timeout: { socket: socketTimeout, }, - request: (...args: [ + request(...args: [ string | URL | http.RequestOptions, (http.RequestOptions | ((response: http.IncomingMessage) => void))?, ((response: http.IncomingMessage) => void)?, - ]) => { + ]) { if (knocks === 1) { // @ts-expect-error Overload error return http.request(...args); @@ -76,7 +76,7 @@ test('retry function gets iteration count', withServer, async (t, server, got) = await got({ retry: { - calculateDelay: ({attemptCount}) => { + calculateDelay({attemptCount}) { t.true(is.number(attemptCount)); return attemptCount < 2 ? 1 : 0; }, @@ -88,7 +88,7 @@ test('setting to `0` disables retrying', async t => { await t.throwsAsync(got('https://example.com', { timeout: {socket: socketTimeout}, retry: { - calculateDelay: ({attemptCount}) => { + calculateDelay({attemptCount}) { t.is(attemptCount, 1); return 0; }, @@ -110,7 +110,7 @@ test('custom retries', withServer, async (t, server, got) => { const error = await t.throwsAsync(got({ throwHttpErrors: true, retry: { - calculateDelay: ({attemptCount}) => { + calculateDelay({attemptCount}) { if (attemptCount === 1) { hasTried = true; return 1; @@ -140,7 +140,7 @@ test('custom retries async', withServer, async (t, server, got) => { const error = await t.throwsAsync(got({ throwHttpErrors: true, retry: { - calculateDelay: async ({attemptCount}) => { + async calculateDelay({attemptCount}) { await new Promise(resolve => { setTimeout(resolve, 1000); }); @@ -168,7 +168,7 @@ test('custom error codes', async t => { const errorCode = 'OH_SNAP'; const error = await t.throwsAsync(got('https://example.com', { - request: () => { + request() { const emitter = new EventEmitter() as http.ClientRequest; emitter.abort = () => {}; // @ts-expect-error Imitating a stream @@ -189,7 +189,7 @@ test('custom error codes', async t => { return emitter; }, retry: { - calculateDelay: ({error}) => { + calculateDelay({error}) { t.is(error.code, errorCode); return 0; }, @@ -314,7 +314,7 @@ test('doesn\'t retry on streams', withServer, async (t, server, got) => { request: 1, }, retry: { - calculateDelay: () => { + calculateDelay() { t.fail('Retries on streams'); }, }, @@ -366,7 +366,7 @@ test('retry function can throw', withServer, async (t, server, got) => { const error = 'Simple error'; await t.throwsAsync(got({ retry: { - calculateDelay: () => { + calculateDelay() { throw new Error(error); }, }, diff --git a/test/stream.ts b/test/stream.ts index 30c23ddcf..c54b5e1b9 100644 --- a/test/stream.ts +++ b/test/stream.ts @@ -366,7 +366,7 @@ test('errors have body', withServer, async (t, server, got) => { const error = await t.throwsAsync(getStream(got.stream('', { cookieJar: { - setCookie: async () => { + async setCookie() { throw new Error('snap'); }, getCookieString: async () => '', diff --git a/test/timeout.ts b/test/timeout.ts index daa6b6580..3e53395e1 100644 --- a/test/timeout.ts +++ b/test/timeout.ts @@ -91,7 +91,7 @@ test.serial('socket timeout', async t => { retry: { limit: 0, }, - request: () => { + request() { const stream = new PassThroughStream(); // @ts-expect-error Mocking the behaviour of a ClientRequest stream.setTimeout = (ms, callback) => { @@ -246,7 +246,7 @@ test.serial('response timeout (keepalive)', withServerAndFakeTimers, async (t, s test.serial('connect timeout', withServerAndFakeTimers, async (t, _server, got, clock) => { await t.throwsAsync( got({ - createConnection: options => { + createConnection(options) { const socket = new net.Socket(options as Record as net.SocketConstructorOpts); // @ts-expect-error We know that it is readonly, but we have to test it socket.connecting = true; @@ -275,7 +275,7 @@ test.serial('connect timeout (ip address)', withServerAndFakeTimers, async (t, _ await t.throwsAsync( got({ url: 'http://127.0.0.1', - createConnection: options => { + createConnection(options) { const socket = new net.Socket(options as Record as net.SocketConstructorOpts); // @ts-expect-error We know that it is readonly, but we have to test it socket.connecting = true; @@ -300,7 +300,7 @@ test.serial('connect timeout (ip address)', withServerAndFakeTimers, async (t, _ test.serial('secureConnect timeout', withHttpsServer({}, true), async (t, _server, got, clock) => { await t.throwsAsync( got({ - createConnection: options => { + createConnection(options) { const socket = new net.Socket(options as Record as net.SocketConstructorOpts); // @ts-expect-error We know that it is readonly, but we have to test it socket.connecting = true; @@ -350,7 +350,7 @@ test.serial('lookup timeout', withServerAndFakeTimers, async (t, server, got, cl await t.throwsAsync( got({ - dnsLookup: () => {}, + dnsLookup() {}, timeout: {lookup: 1}, retry: { limit: 0, @@ -406,7 +406,7 @@ test.serial('retries on timeout', withServer, async (t, server, got) => { request: 1, }, retry: { - calculateDelay: () => { + calculateDelay() { if (hasTried) { return 0; } @@ -482,7 +482,7 @@ test.serial('no unhandled timeout errors', withServer, async (t, _server, got) = await t.throwsAsync(got({ retry: {limit: 0}, timeout: {request: 100}, - request: (...args) => { + request(...args) { const result = http.request(...args); result.once('socket', () => { @@ -507,7 +507,7 @@ test.serial('no unhandled timeout errors #2', withServer, async (t, server, got) request: 20, }, retry: { - calculateDelay: ({computedValue}) => { + calculateDelay({computedValue}) { if (computedValue) { return 10; } @@ -645,7 +645,7 @@ test.serial('doesn\'t throw on early lookup', withServerAndFakeTimers, async (t, }, retry: {limit: 0}, // @ts-expect-error FIXME - dnsLookup: (...[_hostname, options, callback]: Parameters) => { + dnsLookup(...[_hostname, options, callback]: Parameters) { if (typeof options === 'function') { callback = options; }