diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 447e2f1..0000000 --- a/.eslintignore +++ /dev/null @@ -1,3 +0,0 @@ -/tmp -/dist -/examples diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index ec48b3f..0000000 --- a/.eslintrc +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": "@nodesecure/eslint-config", - "rules": { - "@typescript-eslint/no-non-null-assertion": "off" - } -} diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000..8a1e9d0 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,3 @@ +import { typescriptConfig } from "@openally/config.eslint"; + +export default typescriptConfig(); diff --git a/package.json b/package.json index 4b5fe4d..1c7586b 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "types": "dist/index.d.ts", "scripts": { "build": "tsc", + "lint": "eslint src test", "prepublishOnly": "npm run build", "test": "jest" }, @@ -30,7 +31,8 @@ }, "homepage": "https://github.com/MyUnisoft/httpie#readme", "devDependencies": { - "@nodesecure/eslint-config": "^1.9.0", + "@openally/config.eslint": "^1.1.0", + "@openally/config.typescript": "^1.0.3", "@types/content-type": "^1.1.8", "@types/jest": "^29.5.11", "@types/lru-cache": "^7.10.10", diff --git a/src/class/HttpieCommonError.ts b/src/class/HttpieCommonError.ts index 63844f7..d80fbf4 100644 --- a/src/class/HttpieCommonError.ts +++ b/src/class/HttpieCommonError.ts @@ -4,7 +4,7 @@ import { IncomingHttpHeaders } from "undici/types/header"; type CommonResponseData = { statusCode: number; headers: IncomingHttpHeaders; -} +}; export interface HttpieErrorOptions { response: CommonResponseData; diff --git a/src/class/HttpieOnHttpError.ts b/src/class/HttpieOnHttpError.ts index 6bccc61..3eb4855 100644 --- a/src/class/HttpieOnHttpError.ts +++ b/src/class/HttpieOnHttpError.ts @@ -7,7 +7,7 @@ import { RequestResponse } from "../request"; * We attach these to the error so that they can be retrieved by the developer in a Catch block. */ export class HttpieOnHttpError> extends HttpieError { - name = "HttpieOnHttpError"; + override name = "HttpieOnHttpError"; statusMessage: string; data: T["data"]; diff --git a/src/class/Operation.class.ts b/src/class/Operation.class.ts index 52d26bb..c4ddb41 100644 --- a/src/class/Operation.class.ts +++ b/src/class/Operation.class.ts @@ -21,7 +21,7 @@ export interface OperationResult { attempt: number; executionTimestamp: number; elapsedTimeoutTime: number; - } + }; } export default class Operation { diff --git a/src/class/undiciResponseHandler.ts b/src/class/undiciResponseHandler.ts index da5b7e8..f07c5a9 100644 --- a/src/class/undiciResponseHandler.ts +++ b/src/class/undiciResponseHandler.ts @@ -1,4 +1,3 @@ -/* eslint-disable no-dupe-class-members */ // Import Node.js Dependencies import { promisify } from "node:util"; @@ -48,7 +47,7 @@ export class HttpieResponseHandler { try { return Buffer.from(await this.response.body.arrayBuffer()); } - catch (error) { + catch (error: any) { throw new HttpieFetchBodyError({ message: "ResponseFetchError", error, @@ -70,7 +69,7 @@ export class HttpieResponseHandler { encodingHeader.reverse() : encodingHeader.split(",").reverse(); - let decompressedBuffer = Buffer.from(buffer); + let decompressedBuffer: Buffer = Buffer.from(buffer); for (const rawEncoding of encodings) { const encoding = rawEncoding.trim() as TypeOfDecompression; const strategy = kDecompress[encoding]; @@ -90,7 +89,7 @@ export class HttpieResponseHandler { try { decompressedBuffer = await strategy(decompressedBuffer); } - catch (error) { + catch (error: any) { throw new HttpieDecompressionError({ message: "UnexpectedDecompressionError", buffer, @@ -129,7 +128,7 @@ export class HttpieResponseHandler { return bodyAsString; } } - catch (error) { + catch (error: any) { // Note: Even in case of an error we want to be able to recover the body that caused the JSON parsing error. throw new HttpieParserError({ message: "ResponseParsingError", diff --git a/src/common/errors.ts b/src/common/errors.ts index 30d3331..5ff133b 100644 --- a/src/common/errors.ts +++ b/src/common/errors.ts @@ -1,5 +1,3 @@ -/* eslint-disable max-len */ - interface GetErrorOptions { error?: Error; message: keyof T; @@ -26,6 +24,7 @@ const kFetchBodyErrors = { }; const kDecompressionErrors = { + // eslint-disable-next-line @stylistic/max-len UnexpectedDecompressionError: taggedString`An unexpected error occurred when trying to decompress the response body (reason: '${0}').`, DecompressionNotSupported: taggedString`Unsupported encoding '${0}'.` }; diff --git a/src/index.ts b/src/index.ts index e7cf40c..646dbef 100644 --- a/src/index.ts +++ b/src/index.ts @@ -22,7 +22,7 @@ export * from "./request"; export * from "./stream"; export * from "./retry"; export * as policies from "./policies"; -export { agents, computeURI, CustomHttpAgent } from "./agents"; +export { agents, computeURI, type CustomHttpAgent } from "./agents"; export { DEFAULT_HEADER, isHTTPError, isHttpieError } from "./utils"; export { HttpieOnHttpError } from "./class/HttpieOnHttpError"; export * from "./class/undiciResponseHandler"; @@ -34,14 +34,14 @@ export { setGlobalDispatcher, getGlobalDispatcher, Headers, - HeadersInit, + type HeadersInit, FormData, File, - BodyInit, + type BodyInit, BodyMixin, MockAgent, mockErrors, MockPool, - Interceptable, + type Interceptable, Client }; diff --git a/src/request.ts b/src/request.ts index b56aec1..b6843f9 100644 --- a/src/request.ts +++ b/src/request.ts @@ -15,10 +15,10 @@ import { HttpieOnHttpError } from "./class/HttpieOnHttpError"; import { HttpieDecompressionError, HttpieFetchBodyError, HttpieParserError } from "./class/HttpieHandlerError"; export type WebDavMethod = "MKCOL" | "COPY" | "MOVE" | "LOCK" | "UNLOCK" | "PROPFIND" | "PROPPATCH"; -export type HttpMethod = "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "CONNECT" | "OPTIONS" | "TRACE" | "PATCH" ; +export type HttpMethod = "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "CONNECT" | "OPTIONS" | "TRACE" | "PATCH"; export type InlineCallbackAction = (fn: () => Promise) => Promise; -export type RequestError = +export type RequestError = HttpieOnHttpError> | HttpieDecompressionError | HttpieFetchBodyError | diff --git a/src/retry.ts b/src/retry.ts index fa6cd04..3569104 100644 --- a/src/retry.ts +++ b/src/retry.ts @@ -28,7 +28,7 @@ export async function retry( const data = await callback(); op.success(data); } - catch (error) { + catch (error: any) { if (policy(error)) { throw error; } diff --git a/src/utils.ts b/src/utils.ts index 8629e3e..56b0e45 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,3 @@ -/* eslint-disable no-redeclare */ // Import Node.js Dependencies import { IncomingHttpHeaders } from "node:http"; diff --git a/test/HttpieOnHttpError.spec.ts b/test/HttpieOnHttpError.spec.ts index 317911b..93f5626 100644 --- a/test/HttpieOnHttpError.spec.ts +++ b/test/HttpieOnHttpError.spec.ts @@ -33,7 +33,7 @@ describe("HttpieOnHttpError", () => { try { await request(targetUrl.method as any, path); } - catch (error) { + catch (error: any) { expect(error.name).toStrictEqual("HttpieOnHttpError"); expect(error).toMatchObject(expectedResponseData); } diff --git a/test/__snapshots__/request.spec.ts.snap b/test/__snapshots__/request.spec.ts.snap index f81878a..c906e83 100644 --- a/test/__snapshots__/request.spec.ts.snap +++ b/test/__snapshots__/request.spec.ts.snap @@ -7,8 +7,6 @@ exports[`http.get should throw a 404 Not Found error because the path is not kno

Not Found

The requested URL was not found on this server.

-
-
Apache/2.4.58 (Ubuntu) Server at ws.dev.myunisoft.tech Port 80
" `; @@ -20,8 +18,6 @@ exports[`http.safeGet should throw a 404 Not Found error because the path is not

Not Found

The requested URL was not found on this server.

-
-
Apache/2.4.58 (Ubuntu) Server at ws.dev.myunisoft.tech Port 80
" `; diff --git a/test/request.spec.ts b/test/request.spec.ts index d827c19..7c94354 100644 --- a/test/request.spec.ts +++ b/test/request.spec.ts @@ -20,14 +20,14 @@ afterAll(async() => { describe("http.get", () => { it("should GET uptime from local fastify server", async() => { - const { data } = await get<{ uptime: number }>("/local/"); + const { data } = await get<{ uptime: number; }>("/local/"); expect("uptime" in data).toStrictEqual(true); expect(typeof data.uptime).toStrictEqual("number"); }); it("should GET query parameters provided to fastify", async() => { - const { data } = await get<{ name: string }>("/local/qs", { + const { data } = await get<{ name: string; }>("/local/qs", { querystring: new URLSearchParams({ name: "foobar" }) @@ -38,7 +38,7 @@ describe("http.get", () => { }); it("should GET uptime by following an HTTP redirection from local fastify server", async() => { - const { data } = await get<{ uptime: number }>("/local/redirect", { maxRedirections: 1 }); + const { data } = await get<{ uptime: number; }>("/local/redirect", { maxRedirections: 1 }); expect("uptime" in data).toStrictEqual(true); expect(typeof data.uptime).toStrictEqual("number"); @@ -52,7 +52,7 @@ describe("http.get", () => { return callback(); }; - const { data } = await get<{ uptime: number }>("/local/", { limit }); + const { data } = await get<{ uptime: number; }>("/local/", { limit }); expect("uptime" in data).toStrictEqual(true); expect(typeof data.uptime).toStrictEqual("number"); @@ -87,7 +87,7 @@ describe("http.get", () => { try { await get("/windev/hlkezcjcke"); } - catch (error) { + catch (error: any) { expect(error.name).toStrictEqual("HttpieOnHttpError"); expect(error.statusCode).toStrictEqual(404); expect(error.statusMessage).toStrictEqual("Not Found"); @@ -102,7 +102,7 @@ describe("http.get", () => { try { await get("/local/jsonError"); } - catch (error) { + catch (error: any) { expect(error.name).toStrictEqual("ResponseParsingError"); expect(error.reason.name).toStrictEqual("SyntaxError"); expect(error.text).toStrictEqual(expectedPayload); @@ -122,13 +122,12 @@ describe("http.post", () => { userId: 1 }; - const { data } = await post("https://jsonplaceholder.typicode.com/posts", { body }); + const { data } = await post("https://jsonplaceholder.typicode.com/posts", { body }); expect(typeof data.userId).toStrictEqual("number"); expect(data).toMatchObject(body); }); }); - describe("http.put", () => { it("should PUT data on jsonplaceholder API", async() => { const body = { @@ -138,7 +137,7 @@ describe("http.put", () => { userId: 1 }; - const { data } = await put("https://jsonplaceholder.typicode.com/posts/1", { body }); + const { data } = await put("https://jsonplaceholder.typicode.com/posts/1", { body }); expect(data).toEqual(body); }); }); @@ -151,7 +150,7 @@ describe("http.patch", () => { userId: 1 }; - const { data } = await patch("https://jsonplaceholder.typicode.com/posts/1", { + const { data } = await patch("https://jsonplaceholder.typicode.com/posts/1", { body: { title: "foo" } }); expect(data).toMatchObject(body); @@ -169,7 +168,7 @@ describe("http.del", () => { describe("http.safeGet", () => { it("should GET uptime from local fastify server", async() => { - const result = await safeGet<{ uptime: number }, any>("/local/"); + const result = await safeGet<{ uptime: number; }, any>("/local/"); expect(result.ok).toStrictEqual(true); const { data } = result.unwrap(); diff --git a/test/request2.spec.ts b/test/request2.spec.ts index 5a1ff36..e0b7766 100644 --- a/test/request2.spec.ts +++ b/test/request2.spec.ts @@ -46,7 +46,7 @@ describe("Httpie.safeRequest", () => { try { await request(target.method as any, kUrl + target.path); } - catch (error) { + catch (error: any) { expect(isHTTPError(error)).toBeTruthy(); expect(error.statusCode).toBe(statusCode); expect(error.data).toBe(payload.toString()); @@ -92,7 +92,7 @@ describe("Httpie.safeRequest", () => { try { await request(target.method as any, kUrl + target.path); } - catch (error) { + catch (error: any) { expect(isHTTPError(error)).toBeTruthy(); expect(error.statusCode).toBe(statusCode); expect(error.data).toBe(payload.toString()); @@ -138,7 +138,7 @@ describe("Httpie.safeRequest", () => { try { await request(target.method as any, kUrl + target.path); } - catch (error) { + catch (error: any) { expect(isHTTPError(error)).toBeTruthy(); expect(error.statusCode).toBe(statusCode); expect(error.data).toBe(payload.toString()); @@ -184,7 +184,7 @@ describe("Httpie.safeRequest", () => { try { await request(target.method as any, kUrl + target.path); } - catch (error) { + catch (error: any) { expect(isHTTPError(error)).toBeTruthy(); expect(error.statusCode).toBe(statusCode); expect(error.data).toBe(payload.toString()); @@ -229,7 +229,6 @@ describe("Httpie.safeRequest", () => { const response = await request(target.method as any, kUrl + target.path, { throwOnHttpError: false }); - expect(response.statusCode).toBe(statusCode); expect(response.data).toBe(payload.toString()); expect(response.headers).toMatchObject(headers); @@ -249,7 +248,6 @@ describe("Httpie.safeRequest", () => { const response = await request(target.method as any, kUrl + target.path, { throwOnHttpError: false }); - expect(response.statusCode).toBe(statusCode); expect(response.data).toBe(payload.toString()); expect(response.headers).toMatchObject(headers); @@ -271,7 +269,6 @@ describe("Httpie.safeRequest", () => { const response = await request(target.method as any, kUrl + target.path, { throwOnHttpError: false }); - expect(response.statusCode).toBe(statusCode); expect(response.data).toBe(payload.toString()); expect(response.headers).toMatchObject(headers); @@ -291,7 +288,6 @@ describe("Httpie.safeRequest", () => { const response = await request(target.method as any, kUrl + target.path, { throwOnHttpError: false }); - expect(response.statusCode).toBe(statusCode); expect(response.data).toBe(payload.toString()); expect(response.headers).toMatchObject(headers); @@ -313,7 +309,6 @@ describe("Httpie.safeRequest", () => { const response = await request(target.method as any, kUrl + target.path, { throwOnHttpError: false }); - expect(response.statusCode).toBe(statusCode); expect(response.data).toBe(payload.toString()); expect(response.headers).toMatchObject(headers); @@ -333,7 +328,6 @@ describe("Httpie.safeRequest", () => { const response = await request(target.method as any, kUrl + target.path, { throwOnHttpError: false }); - expect(response.statusCode).toBe(statusCode); expect(response.data).toBe(payload.toString()); expect(response.headers).toMatchObject(headers); @@ -355,7 +349,6 @@ describe("Httpie.safeRequest", () => { const response = await request(target.method as any, kUrl + target.path, { throwOnHttpError: false }); - expect(response.statusCode).toBe(statusCode); expect(response.data).toBe(payload.toString()); expect(response.headers).toMatchObject(headers); @@ -375,7 +368,6 @@ describe("Httpie.safeRequest", () => { const response = await request(target.method as any, kUrl + target.path, { throwOnHttpError: false }); - expect(response.statusCode).toBe(statusCode); expect(response.data).toBe(payload.toString()); expect(response.headers).toMatchObject(headers); @@ -478,7 +470,7 @@ describe("Httpie.safeRequest", () => { try { await request(target.method as any, kUrl + target.path); } - catch (error) { + catch (error: any) { expect(isHttpieError(error)).toBeTruthy(); expect(error.message).toStrictEqual( "An unexpected error occurred when trying to parse the response body (reason: 'invalid media type')." @@ -506,7 +498,7 @@ describe("Httpie.safeRequest", () => { try { await request(target.method as any, kUrl + target.path); } - catch (error) { + catch (error: any) { expect(error.message).toStrictEqual("Unsupported encoding 'unknown'."); expect(error.buffer).toStrictEqual(payload); expect(error.headers).toMatchObject(headers); @@ -550,7 +542,6 @@ describe("Httpie.safeRequest", () => { const response = await request(target.method as any, kUrl + target.path); - expect(response.data).toStrictEqual(payload); expect(response.headers).toMatchObject(headers); }); @@ -589,7 +580,6 @@ describe("Httpie.safeRequest", () => { const response = await request(target.method as any, kUrl + target.path); - expect(response.data).toStrictEqual(payload); expect(response.headers).toMatchObject(headers); expect(response.statusCode).toBe(200); @@ -690,7 +680,7 @@ describe("Httpie.safeRequest", () => { try { await request(target.method as any, kUrl + target.path); } - catch (error) { + catch (error: any) { expect(isHttpieError(error)).toBeTruthy(); expect(error.message).toStrictEqual( "An unexpected error occurred when trying to parse the response body (reason: 'invalid media type')." @@ -718,7 +708,7 @@ describe("Httpie.safeRequest", () => { try { await request(target.method as any, kUrl + target.path); } - catch (error) { + catch (error: any) { expect(error.message).toStrictEqual("Unsupported encoding 'unknown'."); expect(error.buffer).toStrictEqual(payload); expect(error.headers).toMatchObject(headers); @@ -762,7 +752,6 @@ describe("Httpie.safeRequest", () => { const response = await request(target.method as any, kUrl + target.path); - expect(response.data).toStrictEqual(payload); expect(response.headers).toMatchObject(headers); }); @@ -801,7 +790,6 @@ describe("Httpie.safeRequest", () => { const response = await request(target.method as any, kUrl + target.path); - expect(response.data).toStrictEqual(payload); expect(response.headers).toMatchObject(headers); expect(response.statusCode).toBe(200); @@ -902,7 +890,7 @@ describe("Httpie.safeRequest", () => { try { await request(target.method as any, kUrl + target.path); } - catch (error) { + catch (error: any) { expect(isHttpieError(error)).toBeTruthy(); expect(error.message).toStrictEqual( "An unexpected error occurred when trying to parse the response body (reason: 'invalid media type')." @@ -930,7 +918,7 @@ describe("Httpie.safeRequest", () => { try { await request(target.method as any, kUrl + target.path); } - catch (error) { + catch (error: any) { expect(error.message).toStrictEqual("Unsupported encoding 'unknown'."); expect(error.buffer).toStrictEqual(payload); expect(error.headers).toMatchObject(headers); @@ -974,7 +962,6 @@ describe("Httpie.safeRequest", () => { const response = await request(target.method as any, kUrl + target.path); - expect(response.data).toStrictEqual(payload); expect(response.headers).toMatchObject(headers); }); @@ -1013,7 +1000,6 @@ describe("Httpie.safeRequest", () => { const response = await request(target.method as any, kUrl + target.path); - expect(response.data).toStrictEqual(payload); expect(response.headers).toMatchObject(headers); expect(response.statusCode).toBe(200); @@ -1114,7 +1100,7 @@ describe("Httpie.safeRequest", () => { try { await request(target.method as any, kUrl + target.path); } - catch (error) { + catch (error: any) { expect(isHttpieError(error)).toBeTruthy(); expect(error.message).toStrictEqual( "An unexpected error occurred when trying to parse the response body (reason: 'invalid media type')." @@ -1142,7 +1128,7 @@ describe("Httpie.safeRequest", () => { try { await request(target.method as any, kUrl + target.path); } - catch (error) { + catch (error: any) { expect(error.message).toStrictEqual("Unsupported encoding 'unknown'."); expect(error.buffer).toStrictEqual(payload); expect(error.headers).toMatchObject(headers); @@ -1186,7 +1172,6 @@ describe("Httpie.safeRequest", () => { const response = await request(target.method as any, kUrl + target.path); - expect(response.data).toStrictEqual(payload); expect(response.headers).toMatchObject(headers); }); @@ -1225,7 +1210,6 @@ describe("Httpie.safeRequest", () => { const response = await request(target.method as any, kUrl + target.path); - expect(response.data).toStrictEqual(payload); expect(response.headers).toMatchObject(headers); expect(response.statusCode).toBe(200); @@ -1249,7 +1233,6 @@ describe("Httpie.safeRequest", () => { const response = await request(target.method as any, kUrl + target.path, { mode: "decompress" }); - expect(response.data).toStrictEqual(payload); expect(response.headers).toMatchObject(headers); }); @@ -1271,7 +1254,7 @@ describe("Httpie.safeRequest", () => { try { await request(target.method as any, kUrl + target.path, { mode: "decompress" }); } - catch (error) { + catch (error: any) { expect(error.message).toStrictEqual("Unsupported encoding 'unknown'."); expect(error.buffer).toMatchObject(payload); expect(error.headers).toMatchObject(headers); @@ -1297,7 +1280,7 @@ describe("Httpie.safeRequest", () => { try { await request(target.method as any, kUrl + target.path, { mode: "decompress" }); } - catch (error) { + catch (error: any) { expect(error.reason).toBeTruthy(); expect(error.message).toStrictEqual( "An unexpected error occurred when trying to decompress the response body (reason: 'incorrect header check')." @@ -1363,7 +1346,6 @@ describe("Httpie.safeRequest", () => { pool.intercept(target).reply(statusCode, compressedPayload, { headers }); const response = await request(target.method as any, kUrl + target.path, { mode: "decompress" }); - expect(response.data).toStrictEqual(payload); expect(response.headers).toMatchObject(headers); }); @@ -1383,7 +1365,6 @@ describe("Httpie.safeRequest", () => { pool.intercept(target).reply(statusCode, compressedPayload, { headers }); const response = await request(target.method as any, kUrl + target.path, { mode: "decompress" }); - expect(response.data).toStrictEqual(payload); expect(response.headers).toMatchObject(headers); }); @@ -1404,7 +1385,6 @@ describe("Httpie.safeRequest", () => { const response = await request(target.method as any, kUrl + target.path, { mode: "decompress" }); - expect(response.data).toStrictEqual(payload); expect(response.headers).toMatchObject(headers); }); @@ -1426,7 +1406,7 @@ describe("Httpie.safeRequest", () => { try { await request(target.method as any, kUrl + target.path, { mode: "decompress" }); } - catch (error) { + catch (error: any) { expect(error.message).toStrictEqual("Unsupported encoding 'unknown'."); expect(error.buffer).toMatchObject(payload); expect(error.headers).toMatchObject(headers); @@ -1452,7 +1432,7 @@ describe("Httpie.safeRequest", () => { try { await request(target.method as any, kUrl + target.path, { mode: "decompress" }); } - catch (error) { + catch (error: any) { expect(error.reason).toBeTruthy(); expect(error.message).toStrictEqual( "An unexpected error occurred when trying to decompress the response body (reason: 'incorrect header check')." @@ -1518,7 +1498,6 @@ describe("Httpie.safeRequest", () => { pool.intercept(target).reply(statusCode, compressedPayload, { headers }); const response = await request(target.method as any, kUrl + target.path, { mode: "decompress" }); - expect(response.data).toStrictEqual(payload); expect(response.headers).toMatchObject(headers); }); @@ -1538,7 +1517,6 @@ describe("Httpie.safeRequest", () => { pool.intercept(target).reply(statusCode, compressedPayload, { headers }); const response = await request(target.method as any, kUrl + target.path, { mode: "decompress" }); - expect(response.data).toStrictEqual(payload); expect(response.headers).toMatchObject(headers); }); @@ -1559,7 +1537,6 @@ describe("Httpie.safeRequest", () => { const response = await request(target.method as any, kUrl + target.path, { mode: "decompress" }); - expect(response.data).toStrictEqual(payload); expect(response.headers).toMatchObject(headers); }); @@ -1581,7 +1558,7 @@ describe("Httpie.safeRequest", () => { try { await request(target.method as any, kUrl + target.path, { mode: "decompress" }); } - catch (error) { + catch (error: any) { expect(error.message).toStrictEqual("Unsupported encoding 'unknown'."); expect(error.buffer).toMatchObject(payload); expect(error.headers).toMatchObject(headers); @@ -1607,7 +1584,7 @@ describe("Httpie.safeRequest", () => { try { await request(target.method as any, kUrl + target.path, { mode: "decompress" }); } - catch (error) { + catch (error: any) { expect(error.reason).toBeTruthy(); expect(error.message).toStrictEqual( "An unexpected error occurred when trying to decompress the response body (reason: 'incorrect header check')." @@ -1673,7 +1650,6 @@ describe("Httpie.safeRequest", () => { pool.intercept(target).reply(statusCode, compressedPayload, { headers }); const response = await request(target.method as any, kUrl + target.path, { mode: "decompress" }); - expect(response.data).toStrictEqual(payload); expect(response.headers).toMatchObject(headers); }); @@ -1693,7 +1669,6 @@ describe("Httpie.safeRequest", () => { pool.intercept(target).reply(statusCode, compressedPayload, { headers }); const response = await request(target.method as any, kUrl + target.path, { mode: "decompress" }); - expect(response.data).toStrictEqual(payload); expect(response.headers).toMatchObject(headers); }); @@ -1714,7 +1689,6 @@ describe("Httpie.safeRequest", () => { const response = await request(target.method as any, kUrl + target.path, { mode: "decompress" }); - expect(response.data).toStrictEqual(payload); expect(response.headers).toMatchObject(headers); }); @@ -1736,7 +1710,7 @@ describe("Httpie.safeRequest", () => { try { await request(target.method as any, kUrl + target.path, { mode: "decompress" }); } - catch (error) { + catch (error: any) { expect(error.message).toStrictEqual("Unsupported encoding 'unknown'."); expect(error.buffer).toMatchObject(payload); expect(error.headers).toMatchObject(headers); @@ -1762,7 +1736,7 @@ describe("Httpie.safeRequest", () => { try { await request(target.method as any, kUrl + target.path, { mode: "decompress" }); } - catch (error) { + catch (error: any) { expect(error.reason).toBeTruthy(); expect(error.message).toStrictEqual( "An unexpected error occurred when trying to decompress the response body (reason: 'incorrect header check')." @@ -1828,7 +1802,6 @@ describe("Httpie.safeRequest", () => { pool.intercept(target).reply(statusCode, compressedPayload, { headers }); const response = await request(target.method as any, kUrl + target.path, { mode: "decompress" }); - expect(response.data).toStrictEqual(payload); expect(response.headers).toMatchObject(headers); }); @@ -1848,7 +1821,6 @@ describe("Httpie.safeRequest", () => { pool.intercept(target).reply(statusCode, compressedPayload, { headers }); const response = await request(target.method as any, kUrl + target.path, { mode: "decompress" }); - expect(response.data).toStrictEqual(payload); expect(response.headers).toMatchObject(headers); }); @@ -1888,10 +1860,8 @@ describe("Httpie.safeRequest", () => { pool.intercept(target).reply(statusCode, payload, { headers }); - const response = await request(target.method as any, kUrl + target.path, { mode: "raw" }); - expect(response.data).toStrictEqual(payload); expect(response.headers).toMatchObject(headers); expect(response.statusCode).toBe(200); @@ -1970,10 +1940,8 @@ describe("Httpie.safeRequest", () => { pool.intercept(target).reply(statusCode, payload, { headers }); - const response = await request(target.method as any, kUrl + target.path, { mode: "raw" }); - expect(response.data).toStrictEqual(payload); expect(response.headers).toMatchObject(headers); expect(response.statusCode).toBe(200); @@ -2012,10 +1980,8 @@ describe("Httpie.safeRequest", () => { pool.intercept(target).reply(statusCode, payload, { headers }); - const response = await request(target.method as any, kUrl + target.path, { mode: "raw" }); - expect(response.data).toStrictEqual(payload); expect(response.headers).toMatchObject(headers); expect(response.statusCode).toBe(200); diff --git a/test/retry.spec.ts b/test/retry.spec.ts index 8f74d56..90f4a06 100644 --- a/test/retry.spec.ts +++ b/test/retry.spec.ts @@ -25,7 +25,7 @@ describe("retry (with default policy)", () => { throw new Error("exceed"); }, { factor: 1 }); } - catch (error) { + catch (error: any) { expect(error.message).toStrictEqual("Exceeded the maximum number of allowed retries!"); } }); @@ -65,7 +65,7 @@ describe("retry (with default policy)", () => { throw new Error("oops"); }, { forever: true, signal: controller.signal }); } - catch (error) { + catch (error: any) { expect(error.message).toStrictEqual("Aborted"); } }); @@ -78,7 +78,7 @@ describe("retry (with http policy)", () => { try { await retry(async() => get("/retry/internalerror"), { factor: 1, retries: 2 }, policies.httpcode()); } - catch (error) { + catch (error: any) { expect(error.message).toStrictEqual("Exceeded the maximum number of allowed retries!"); } }); @@ -89,7 +89,7 @@ describe("retry (with http policy)", () => { try { await retry(async() => get("/retry/notimplemented"), { factor: 1, retries: 2 }, policies.httpcode()); } - catch (error) { + catch (error: any) { expect(error.message).toStrictEqual("Not Implemented"); } }); @@ -102,7 +102,7 @@ describe("retry (with http policy)", () => { await retry(async() => get("/retry/notimplemented"), { factor: 1, retries: 2 }, policy); } - catch (error) { + catch (error: any) { expect(error.message).toStrictEqual("Exceeded the maximum number of allowed retries!"); } }); diff --git a/test/safeRequest.spec.ts b/test/safeRequest.spec.ts index 2dc36d0..a8d6a80 100644 --- a/test/safeRequest.spec.ts +++ b/test/safeRequest.spec.ts @@ -48,7 +48,7 @@ describe("Httpie.safeRequest", () => { expect(result.ok).toBeFalsy(); result.unwrap(); } - catch (error) { + catch (error: any) { expect(isHTTPError(error)).toBeTruthy(); expect(error.statusCode).toBe(statusCode); expect(error.data).toBe(payload.toString()); @@ -98,7 +98,7 @@ describe("Httpie.safeRequest", () => { expect(result.ok).toBeFalsy(); result.unwrap(); } - catch (error) { + catch (error: any) { expect(isHTTPError(error)).toBeTruthy(); expect(error.statusCode).toBe(statusCode); expect(error.data).toBe(payload.toString()); @@ -148,7 +148,7 @@ describe("Httpie.safeRequest", () => { expect(result.ok).toBeFalsy(); result.unwrap(); } - catch (error) { + catch (error: any) { expect(isHTTPError(error)).toBeTruthy(); expect(error.statusCode).toBe(statusCode); expect(error.data).toBe(payload.toString()); @@ -198,7 +198,7 @@ describe("Httpie.safeRequest", () => { expect(result.ok).toBeFalsy(); result.unwrap(); } - catch (error) { + catch (error: any) { expect(isHTTPError(error)).toBeTruthy(); expect(error.statusCode).toBe(statusCode); expect(error.data).toBe(payload.toString()); @@ -504,7 +504,7 @@ describe("Httpie.safeRequest", () => { expect(result.ok).toBeFalsy(); result.unwrap(); } - catch (error) { + catch (error: any) { expect(isHttpieError(error)).toBeTruthy(); expect(error.message).toStrictEqual( "An unexpected error occurred when trying to parse the response body (reason: 'invalid media type')." @@ -534,7 +534,7 @@ describe("Httpie.safeRequest", () => { expect(result.ok).toBeFalsy(); result.unwrap(); } - catch (error) { + catch (error: any) { expect(error.message).toStrictEqual("Unsupported encoding 'unknown'."); expect(error.buffer).toStrictEqual(payload); expect(error.headers).toMatchObject(headers); @@ -733,7 +733,7 @@ describe("Httpie.safeRequest", () => { expect(result.ok).toBeFalsy(); result.unwrap(); } - catch (error) { + catch (error: any) { expect(isHttpieError(error)).toBeTruthy(); expect(error.message).toStrictEqual( "An unexpected error occurred when trying to parse the response body (reason: 'invalid media type')." @@ -763,7 +763,7 @@ describe("Httpie.safeRequest", () => { expect(result.ok).toBeFalsy(); result.unwrap(); } - catch (error) { + catch (error: any) { expect(error.message).toStrictEqual("Unsupported encoding 'unknown'."); expect(error.buffer).toStrictEqual(payload); expect(error.headers).toMatchObject(headers); @@ -962,7 +962,7 @@ describe("Httpie.safeRequest", () => { expect(result.ok).toBeFalsy(); result.unwrap(); } - catch (error) { + catch (error: any) { expect(isHttpieError(error)).toBeTruthy(); expect(error.message).toStrictEqual( "An unexpected error occurred when trying to parse the response body (reason: 'invalid media type')." @@ -992,7 +992,7 @@ describe("Httpie.safeRequest", () => { expect(result.ok).toBeFalsy(); result.unwrap(); } - catch (error) { + catch (error: any) { expect(error.message).toStrictEqual("Unsupported encoding 'unknown'."); expect(error.buffer).toStrictEqual(payload); expect(error.headers).toMatchObject(headers); @@ -1191,7 +1191,7 @@ describe("Httpie.safeRequest", () => { expect(result.ok).toBeFalsy(); result.unwrap(); } - catch (error) { + catch (error: any) { expect(isHttpieError(error)).toBeTruthy(); expect(error.message).toStrictEqual( "An unexpected error occurred when trying to parse the response body (reason: 'invalid media type')." @@ -1221,7 +1221,7 @@ describe("Httpie.safeRequest", () => { expect(result.ok).toBeFalsy(); result.unwrap(); } - catch (error) { + catch (error: any) { expect(error.message).toStrictEqual("Unsupported encoding 'unknown'."); expect(error.buffer).toStrictEqual(payload); expect(error.headers).toMatchObject(headers); @@ -1357,7 +1357,7 @@ describe("Httpie.safeRequest", () => { expect(result.ok).toBeFalsy(); result.unwrap(); } - catch (error) { + catch (error: any) { expect(error.message).toStrictEqual("Unsupported encoding 'unknown'."); expect(error.buffer).toMatchObject(payload); expect(error.headers).toMatchObject(headers); @@ -1385,7 +1385,7 @@ describe("Httpie.safeRequest", () => { expect(result.ok).toBeFalsy(); result.unwrap(); } - catch (error) { + catch (error: any) { expect(error).toBeTruthy(); expect(error.reason).toBeTruthy(); expect(error.message).toStrictEqual( @@ -1521,7 +1521,7 @@ describe("Httpie.safeRequest", () => { expect(result.ok).toBeFalsy(); result.unwrap(); } - catch (error) { + catch (error: any) { expect(error.message).toStrictEqual("Unsupported encoding 'unknown'."); expect(error.buffer).toMatchObject(payload); expect(error.headers).toMatchObject(headers); @@ -1549,7 +1549,7 @@ describe("Httpie.safeRequest", () => { expect(result.ok).toBeFalsy(); result.unwrap(); } - catch (error) { + catch (error: any) { expect(error).toBeTruthy(); expect(error.reason).toBeTruthy(); expect(error.message).toStrictEqual( @@ -1685,7 +1685,7 @@ describe("Httpie.safeRequest", () => { expect(result.ok).toBeFalsy(); result.unwrap(); } - catch (error) { + catch (error: any) { expect(error.message).toStrictEqual("Unsupported encoding 'unknown'."); expect(error.buffer).toMatchObject(payload); expect(error.headers).toMatchObject(headers); @@ -1713,7 +1713,7 @@ describe("Httpie.safeRequest", () => { expect(result.ok).toBeFalsy(); result.unwrap(); } - catch (error) { + catch (error: any) { expect(error).toBeTruthy(); expect(error.reason).toBeTruthy(); expect(error.message).toStrictEqual( @@ -1849,7 +1849,7 @@ describe("Httpie.safeRequest", () => { expect(result.ok).toBeFalsy(); result.unwrap(); } - catch (error) { + catch (error: any) { expect(error.message).toStrictEqual("Unsupported encoding 'unknown'."); expect(error.buffer).toMatchObject(payload); expect(error.headers).toMatchObject(headers); @@ -1877,7 +1877,7 @@ describe("Httpie.safeRequest", () => { expect(result.ok).toBeFalsy(); result.unwrap(); } - catch (error) { + catch (error: any) { expect(error).toBeTruthy(); expect(error.reason).toBeTruthy(); expect(error.message).toStrictEqual( @@ -2010,7 +2010,6 @@ describe("Httpie.safeRequest", () => { pool.intercept(target).reply(statusCode, payload, { headers }); - const result = await safeGet(kUrl + target.path, { mode: "raw" }); const response = result.unwrap(); expect(result.ok).toBeTruthy(); @@ -2098,7 +2097,6 @@ describe("Httpie.safeRequest", () => { pool.intercept(target).reply(statusCode, payload, { headers }); - const result = await safePut(kUrl + target.path, { mode: "raw" }); const response = result.unwrap(); expect(result.ok).toBeTruthy(); @@ -2142,7 +2140,6 @@ describe("Httpie.safeRequest", () => { pool.intercept(target).reply(statusCode, payload, { headers }); - const result = await safeDel(kUrl + target.path, { mode: "raw" }); const response = result.unwrap(); expect(result.ok).toBeTruthy(); diff --git a/test/undiciResponseHandler.spec.ts b/test/undiciResponseHandler.spec.ts index 06e8d3d..651cdfe 100644 --- a/test/undiciResponseHandler.spec.ts +++ b/test/undiciResponseHandler.spec.ts @@ -1,4 +1,3 @@ -/* eslint-disable max-len */ // Import Node.js Dependencies import { randomBytes } from "node:crypto"; @@ -59,9 +58,10 @@ describe("HttpieResponseHandler.getData (mode: 'raw')", () => { try { await handler.getData(); } - catch (error) { + catch (error: any) { expect(error.name).toStrictEqual("ResponseFetchError"); - expect(error.message).toStrictEqual(`An unexpected error occurred while trying to retrieve the response body (reason: '${errMsg}').`); + expect(error.message) + .toStrictEqual(`An unexpected error occurred while trying to retrieve the response body (reason: '${errMsg}').`); expect(error.statusCode).toStrictEqual(mockResponse.statusCode); expect(error.headers).toStrictEqual(mockResponse.headers); } @@ -97,7 +97,7 @@ describe("HttpieResponseHandler.getData (mode: 'decompress')", () => { try { await handler.getData("decompress"); } - catch (error) { + catch (error: any) { expect(error.message).toStrictEqual(`Unsupported encoding '${encoding}'.`); expect(error.buffer).toStrictEqual(buf); expect(error.encodings).toStrictEqual([encoding]); @@ -122,7 +122,7 @@ describe("HttpieResponseHandler.getData (mode: 'decompress')", () => { try { await handler.getData("decompress"); } - catch (error) { + catch (error: any) { expect(error.message).toStrictEqual(`Unsupported encoding '${encoding}'.`); expect(error.buffer).toStrictEqual(buf); expect(error.encodings).toStrictEqual([encoding]); @@ -132,7 +132,8 @@ describe("HttpieResponseHandler.getData (mode: 'decompress')", () => { } }); - it("must use 'gunzip' before to returning an uncompressed buffer when the 'content-encoding' header is set with 'gzip'", async() => { + it(`must use 'gunzip' before to returning an uncompressed buffer + when the 'content-encoding' header is set with 'gzip'`, async() => { const buf = Buffer.from("hello world!"); const mockResponse = { body: { arrayBuffer: () => toArrayBuffer(gzipSync(buf)) }, @@ -144,7 +145,8 @@ describe("HttpieResponseHandler.getData (mode: 'decompress')", () => { expect(data).toStrictEqual(buf); }); - it("must use 'gunzip' before to returning an uncompressed buffer when the 'content-encoding' header is set with 'x-gzip'", async() => { + it(`must use 'gunzip' before to returning an uncompressed buffer + when the 'content-encoding' header is set with 'x-gzip'`, async() => { const buf = Buffer.from("hello world!"); const mockResponse = { body: { arrayBuffer: () => toArrayBuffer(gzipSync(buf)) }, @@ -156,7 +158,8 @@ describe("HttpieResponseHandler.getData (mode: 'decompress')", () => { expect(data).toStrictEqual(buf); }); - it("must use 'brotliDecompress' before to returning an uncompressed buffer when the 'content-encoding' header is set with 'br'", async() => { + it(`must use 'brotliDecompress' before to returning an uncompressed buffer + when the 'content-encoding' header is set with 'br'`, async() => { const buf = Buffer.from("hello world!"); const mockResponse = { body: { arrayBuffer: () => toArrayBuffer(brotliCompressSync(buf)) }, @@ -168,7 +171,8 @@ describe("HttpieResponseHandler.getData (mode: 'decompress')", () => { expect(data).toStrictEqual(buf); }); - it("must use 'inflate' before to returning an uncompressed buffer when the 'content-encoding' header is set with 'deflate'", async() => { + it(`must use 'inflate' before to returning an uncompressed buffer + when the 'content-encoding' header is set with 'deflate'`, async() => { const buf = Buffer.from("hello world!"); const mockResponse = { body: { arrayBuffer: () => toArrayBuffer(deflateSync(buf)) }, @@ -235,7 +239,7 @@ describe("HttpieResponseHandler.getData (mode: 'parse')", () => { try { await handler.getData("parse"); } - catch (error) { + catch (error: any) { expect(error.text).toStrictEqual(payload); expect(error.buffer).toStrictEqual(buf); expect(error.name).toStrictEqual("ResponseParsingError"); diff --git a/test/utils.spec.ts b/test/utils.spec.ts index c57f640..e7f26a0 100644 --- a/test/utils.spec.ts +++ b/test/utils.spec.ts @@ -149,7 +149,6 @@ describe("createAuthorizationHeader", () => { }); }); - describe("isHttpieError", () => { it("it should be true", () => { expect(Utils.isHttpieError(new HttpieOnHttpError({} as any))).toBeTruthy(); diff --git a/tsconfig.json b/tsconfig.json index 7c9f8eb..6b26bef 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,17 +1,9 @@ { - "compilerOptions": { - "declaration": true, - "strictNullChecks": true, - "target": "ES2021", - "outDir": "dist", - "module": "commonjs", - "moduleResolution": "node", - "skipLibCheck": true, - "skipDefaultLibCheck": true, - "esModuleInterop": true, - "sourceMap": true, - "rootDir": "src" - }, - "include": ["src"], - "exclude": ["node_modules", "dist"] - } + "extends": "@openally/config.typescript/cjs", + "compilerOptions": { + "outDir": "dist", + "rootDir": "./src", + }, + "include": ["src"], + "exclude": ["node_modules", "dist"] +}