From 90dc4d94a3543c72ddc95739a90320abc623059a Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Tue, 10 Sep 2024 08:25:31 -0300 Subject: [PATCH 1/2] fix: fix typings of `skip` modifier --- src/modules/helpers/modifiers.ts | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/modules/helpers/modifiers.ts b/src/modules/helpers/modifiers.ts index 4e0c215e..c62eeb42 100644 --- a/src/modules/helpers/modifiers.ts +++ b/src/modules/helpers/modifiers.ts @@ -7,16 +7,37 @@ export const todo = (message: string, _cb?: () => unknown) => `${indentation.hasDescribe ? ' ' : ''}${format(`● ${message}`).cyan().bold()}` ); +export async function skip( + message: string, + _cb: () => Promise +): Promise; export function skip(message: string, _cb: () => unknown): void; +export async function skip(_cb: () => Promise): Promise; export function skip(_cb: () => unknown): void; -export function skip( - messageOrCb: string | (() => unknown), - _cb?: () => unknown -) { +export async function skip( + messageOrCb: string | (() => unknown) | (() => Promise), + _cb?: (() => unknown) | (() => Promise) +): Promise { const message = (typeof messageOrCb === 'string' && messageOrCb) || 'Skipping'; Write.log( `${indentation.hasDescribe ? ' ' : ''}${format(`◯ ${message}`).info().bold()}` ); + + // Type guard + if (typeof messageOrCb === 'function') { + const isAsync = messageOrCb.constructor.name === 'AsyncFunction'; + + if (isAsync) return await Promise.resolve(); + return; + } + + // Type guard + if (typeof _cb === 'function') { + const isAsync = _cb.constructor.name === 'AsyncFunction'; + + if (isAsync) return await Promise.resolve(); + return; + } } From 48250e027fbfad5bd7a733f6fc177a4b78e96ece Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Tue, 10 Sep 2024 08:31:37 -0300 Subject: [PATCH 2/2] chore(c8): ignore type guard --- src/modules/helpers/modifiers.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/helpers/modifiers.ts b/src/modules/helpers/modifiers.ts index c62eeb42..6a1685f1 100644 --- a/src/modules/helpers/modifiers.ts +++ b/src/modules/helpers/modifiers.ts @@ -25,7 +25,7 @@ export async function skip( `${indentation.hasDescribe ? ' ' : ''}${format(`◯ ${message}`).info().bold()}` ); - // Type guard + /* c8 ignore start */ // Type guard if (typeof messageOrCb === 'function') { const isAsync = messageOrCb.constructor.name === 'AsyncFunction'; @@ -33,11 +33,11 @@ export async function skip( return; } - // Type guard if (typeof _cb === 'function') { const isAsync = _cb.constructor.name === 'AsyncFunction'; if (isAsync) return await Promise.resolve(); return; } + /* c8 ignore stop */ }