From e1f3c487f88d11d7d711ab43ec18d2d7439643f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 23 Dec 2021 16:08:03 +0100 Subject: [PATCH] Avoid logging HTTP request in unit tests --- src/api.ts | 6 +++++- src/main-test.ts | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/api.ts b/src/api.ts index 77e51cf..0a34b21 100644 --- a/src/api.ts +++ b/src/api.ts @@ -9,12 +9,16 @@ const GitHub = Octokit.plugin(restEndpointMethods, requestLog).defaults({ export type API = InstanceType -export default function (token: string, options?: { fetch?: any }): API { +export default function ( + token: string, + options?: { logRequests?: boolean; fetch?: any } +): API { return new GitHub({ request: { fetch: options && options.fetch }, auth: `token ${token}`, log: { info(msg: string) { + if (options?.logRequests === false) return return console.info(msg) }, debug(msg: string) { diff --git a/src/main-test.ts b/src/main-test.ts index 673538f..4396e7d 100644 --- a/src/main-test.ts +++ b/src/main-test.ts @@ -54,7 +54,7 @@ test('prepareEdit()', async (t) => { } throw url } - const apiClient = api('ATOKEN', { fetch: stubbedFetch }) + const apiClient = api('ATOKEN', { fetch: stubbedFetch, logRequests: false }) const opts = await prepareEdit(ctx, apiClient, apiClient) t.is(opts.owner, 'Homebrew')