From 7e316b8e811990f1362233479dc18f213ab2ba5b Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 25 Jul 2022 20:59:09 -0400 Subject: [PATCH] make sure to check funcs in context calls too - `get-options-overrides`'s coverage func % decreased bc funcs passed to `context.debug` weren't being called - took me a bit to notice too since we have no coverage checks - and then another bit to realize _why_ it decreased --- __tests__/fixtures/context.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/__tests__/fixtures/context.ts b/__tests__/fixtures/context.ts index cd1501d5..239114c3 100644 --- a/__tests__/fixtures/context.ts +++ b/__tests__/fixtures/context.ts @@ -3,11 +3,19 @@ import { PluginContext } from "rollup"; import { IContext } from "../../src/context"; +// if given a function, make sure to call it (for code coverage etc) +function returnText (message: string | (() => string)) { + if (typeof message === "string") + return message; + + return message(); +} + export function makeContext(): PluginContext & IContext { return { - error: jest.fn(), - warn: jest.fn(), - info: jest.fn(), - debug: jest.fn(), + error: jest.fn(returnText), + warn: jest.fn(returnText), + info: jest.fn(returnText), + debug: jest.fn(returnText), } as unknown as PluginContext & IContext; };