diff --git a/src/adapters/action/dispatcher-http-hook-mastodon.ts b/src/adapters/action/dispatcher-http-hook-mastodon.ts index 72ee9478..67ecd17e 100644 --- a/src/adapters/action/dispatcher-http-hook-mastodon.ts +++ b/src/adapters/action/dispatcher-http-hook-mastodon.ts @@ -58,7 +58,7 @@ async function waitForMediaAttachment( let media: mastodon.v1.MediaAttachment | undefined; const signal = AbortSignal.timeout(timeout); - while (media == undefined) { + while (!media) { if (signal.aborted) { throw new MastoTimeoutError(`Media processing timed out of ${timeout}ms`); } @@ -70,7 +70,7 @@ async function waitForMediaAttachment( `/api/v1/media/${id}`, ); - if (processing.url != undefined) { + if (processing.url) { media = processing; } } catch (error) { diff --git a/src/adapters/action/dispatcher-http.ts b/src/adapters/action/dispatcher-http.ts index e8b9b668..22bf026f 100644 --- a/src/adapters/action/dispatcher-http.ts +++ b/src/adapters/action/dispatcher-http.ts @@ -16,7 +16,7 @@ export class HttpActionDispatcher implements ActionDispatcher { ) {} dispatch(action: HttpAction): T | Promise { - if (this.hook != undefined) { + if (this.hook) { action = this.hook.beforeDispatch(action); } diff --git a/src/adapters/action/paginator-http.ts b/src/adapters/action/paginator-http.ts index 951c4257..c959b3ee 100644 --- a/src/adapters/action/paginator-http.ts +++ b/src/adapters/action/paginator-http.ts @@ -15,7 +15,7 @@ export class PaginatorHttp ) {} async next(): Promise> { - if (this.nextPath == undefined) { + if (!this.nextPath) { return { done: true, value: undefined }; } @@ -98,12 +98,12 @@ export class PaginatorHttp } private getLink(value?: string | null): URL | undefined { - if (value == undefined) { + if (!value) { return; } const parsed = parseLinkHeader(value).get(this.direction); - if (parsed == undefined) { + if (!parsed) { return; } diff --git a/src/adapters/action/proxy.ts b/src/adapters/action/proxy.ts index 4011d696..eba0af3a 100644 --- a/src/adapters/action/proxy.ts +++ b/src/adapters/action/proxy.ts @@ -84,7 +84,7 @@ const apply = const action = context.pop(); /* istanbul ignore next */ - if (action == undefined) { + if (!action) { throw new Error("No action specified"); } diff --git a/src/adapters/config/http-config.ts b/src/adapters/config/http-config.ts index 3a969a4a..a94f1f6c 100644 --- a/src/adapters/config/http-config.ts +++ b/src/adapters/config/http-config.ts @@ -55,7 +55,7 @@ export class HttpConfigImpl implements HttpConfig { if (typeof params === "string") { url.search = params; - } else if (params != undefined) { + } else if (params) { url.search = this.serializer.serialize("querystring", params); } @@ -81,7 +81,7 @@ export class HttpConfigImpl implements HttpConfig { ): AbortSignal { const signals: AbortSignal[] = []; - if (this.props.timeout != undefined) { + if (this.props.timeout) { signals.push(AbortSignal.timeout(this.props.timeout)); } @@ -89,7 +89,7 @@ export class HttpConfigImpl implements HttpConfig { signals.push(this.props.requestInit.signal); } - if (signal != undefined) { + if (signal) { signals.push(signal); } diff --git a/src/adapters/http/http-native-impl.spec.ts b/src/adapters/http/http-native-impl.spec.ts index 52f36c4f..9473adf1 100644 --- a/src/adapters/http/http-native-impl.spec.ts +++ b/src/adapters/http/http-native-impl.spec.ts @@ -9,19 +9,29 @@ import { HttpNativeImpl } from "./http-native-impl"; describe("HttpNativeImpl", () => { it("timeouts", async () => { + const server = node_http.createServer((_, res) => { + res.writeHead(200, { "Content-Type": "application/json" }); + res.end("{}"); + }); + + const port = await getPort(); + server.listen(port); + const serializer = new SerializerNativeImpl(); const http = new HttpNativeImpl( serializer, new HttpConfigImpl( { - url: "https://example.com", - timeout: 0, + url: `http://localhost:${port}`, + timeout: 1, }, serializer, ), ); - await expect(() => http.get("/")).rejects.toThrowError(MastoTimeoutError); + await expect(() => http.get("/")).rejects.toThrow(MastoTimeoutError); + + server.close(); }); it("throws an error if server returned non-JSON", async () => { diff --git a/src/adapters/http/http-native-impl.ts b/src/adapters/http/http-native-impl.ts index 6beb843b..fd0c61ad 100644 --- a/src/adapters/http/http-native-impl.ts +++ b/src/adapters/http/http-native-impl.ts @@ -40,7 +40,7 @@ export class HttpNativeImpl extends BaseHttp implements Http { const text = await response.text(); const encoding = getEncoding(response.headers); - if (encoding == undefined) { + if (!encoding) { throw new MastoUnexpectedError( "The server returned data with an unknown encoding.", ); @@ -89,7 +89,7 @@ export class HttpNativeImpl extends BaseHttp implements Http { private async createError(error: unknown): Promise { if (error instanceof Response) { const encoding = getEncoding(error.headers); - if (encoding == undefined) { + if (!encoding) { throw new MastoUnexpectedError( "The server returned data with an unknown encoding. The server may be down.", ); diff --git a/src/adapters/serializers/flatten.ts b/src/adapters/serializers/flatten.ts index fc176105..b6d31c8a 100644 --- a/src/adapters/serializers/flatten.ts +++ b/src/adapters/serializers/flatten.ts @@ -46,7 +46,7 @@ export const flattenForRailsQueryString = (object: unknown): string => { }); return flatten(object) - .filter(([, v]) => v != undefined) + .filter(([, v]) => !!v) .map(([k, v]) => `${k}=${encodeURIComponent(v as string)}`) .join("&"); }; diff --git a/src/adapters/ws/async-iterable.ts b/src/adapters/ws/async-iterable.ts index ee2ddec7..458ee343 100644 --- a/src/adapters/ws/async-iterable.ts +++ b/src/adapters/ws/async-iterable.ts @@ -8,7 +8,7 @@ export async function* toAsyncIterable( ): AsyncIterableIterator { const handleClose = async (e: WebSocket.CloseEvent) => { /* istanbul ignore next */ - if (events.return == undefined) { + if (!events.return) { throw new MastoUnexpectedError("events.return is undefined"); } await events.return(e); @@ -16,7 +16,7 @@ export async function* toAsyncIterable( const handleError = async (e: WebSocket.ErrorEvent) => { /* istanbul ignore next */ - if (events.return == undefined) { + if (!events.return) { throw new MastoUnexpectedError("events.return is undefined"); } await events.return(e); diff --git a/src/adapters/ws/web-socket-connector.ts b/src/adapters/ws/web-socket-connector.ts index 9a3077fd..97b2a06b 100644 --- a/src/adapters/ws/web-socket-connector.ts +++ b/src/adapters/ws/web-socket-connector.ts @@ -37,7 +37,7 @@ export class WebSocketConnectorImpl implements WebSocketConnector { throw new MastoWebSocketError("WebSocket closed"); } - if (this.ws != undefined) { + if (this.ws) { return Promise.resolve(this.ws); } diff --git a/src/adapters/ws/web-socket-subscription.ts b/src/adapters/ws/web-socket-subscription.ts index 512dc167..e421624f 100644 --- a/src/adapters/ws/web-socket-subscription.ts +++ b/src/adapters/ws/web-socket-subscription.ts @@ -56,7 +56,7 @@ export class WebSocketSubscription implements mastodon.streaming.Subscription { } unsubscribe(): void { - if (this.connection == undefined) { + if (!this.connection) { return; }