diff --git a/src/modules/helpers/modifiers.ts b/src/modules/helpers/modifiers.ts index 4e0c215e..6a1685f1 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()}` ); + + /* c8 ignore start */ // Type guard + if (typeof messageOrCb === 'function') { + const isAsync = messageOrCb.constructor.name === 'AsyncFunction'; + + if (isAsync) return await Promise.resolve(); + return; + } + + if (typeof _cb === 'function') { + const isAsync = _cb.constructor.name === 'AsyncFunction'; + + if (isAsync) return await Promise.resolve(); + return; + } + /* c8 ignore stop */ }