From 3ae4f9352ee73a21581735883b4049327dce07bf Mon Sep 17 00:00:00 2001 From: Kevin J Hoerr Date: Wed, 11 Dec 2019 09:40:22 -0500 Subject: Add Jest to handle unit and integration testing Wrote a couple of initial unit tests for some of the logic-heavy points in the application, being logger.ts and formats.ts. Evidently colorize() causes an error when transforming on the Format object that's returned. Since that is specific to the Console transport anyways, I just moved it to the transport, since the unit test was only testing the passed label in the returned Formats object. Also the bash template has some issues that I didn't test (oops), so those are fixed now. --- src/formats.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/formats.ts') diff --git a/src/formats.ts b/src/formats.ts index e878399..86d3f6b 100644 --- a/src/formats.ts +++ b/src/formats.ts @@ -24,7 +24,7 @@ export interface GradientStyle { } // color is a gradient from green (>=stage_1) -> yellow (stage_2) -> red. Stage values should come from metadata. -const defaultColorMatches = ( +export const defaultColorMatches = ( coverage: number, style: GradientStyle ): string => { @@ -32,9 +32,12 @@ const defaultColorMatches = ( coverage >= style.stage1 ? 15 : coverage >= style.stage2 - ? (Math.floor(coverage) - style.stage2) * 16 + 15 + ? Math.floor( + ((style.stage1 - coverage) / (style.stage1 - style.stage2)) * 240 + ) + 15 : 240 + Math.floor(coverage / (style.stage2 / 15)); - return gradient.toString(16) + "0"; + const result = gradient.toString(16); + return (result.length === 1 ? "0" : "") + result + "0"; }; const FormatsObj: FormatObj = { -- cgit