diff --git a/src/annotations/createCoverageAnnotations.ts b/src/annotations/createCoverageAnnotations.ts index 6ca8806..bd7bd28 100644 --- a/src/annotations/createCoverageAnnotations.ts +++ b/src/annotations/createCoverageAnnotations.ts @@ -1,10 +1,10 @@ import { relative } from 'path'; +import { Annotation } from './Annotation'; import { CoverageAnnotationType } from '../typings/CoverageAnnotationType'; import { JsonReport, Location } from '../typings/JsonReport'; import { i18n } from '../utils/i18n'; import { isValidNumber } from '../utils/isValidNumber'; -import { Annotation } from './Annotation'; const getLocation = ( start: Location = { line: 0 }, @@ -32,7 +32,11 @@ export const createCoverageAnnotations = ( const annotations: Partial[] = []; if (annotationFilters.length === 0) { - annotationFilters = [CoverageAnnotationType.Branch, CoverageAnnotationType.Function, CoverageAnnotationType.Statement]; + annotationFilters = [ + CoverageAnnotationType.Branch, + CoverageAnnotationType.Function, + CoverageAnnotationType.Statement, + ]; } Object.entries(jsonReport.coverageMap).forEach( @@ -60,9 +64,8 @@ export const createCoverageAnnotations = ( } ); } - - if (annotationFilters.includes(CoverageAnnotationType.Branch)) { + if (annotationFilters.includes(CoverageAnnotationType.Branch)) { Object.entries(normalizedFileCoverage.branchMap).forEach( ([branchIndex, branchCoverage]) => { if (branchCoverage.locations) { @@ -80,7 +83,9 @@ export const createCoverageAnnotations = ( ), path: normalizedFilename, annotation_level: 'warning', - title: i18n('notCoveredBranchTitle'), + title: i18n( + 'notCoveredBranchTitle' + ), message: i18n( 'notCoveredBranchMessage' ), @@ -93,7 +98,7 @@ export const createCoverageAnnotations = ( ); } - if (annotationFilters.includes(CoverageAnnotationType.Function)) { + if (annotationFilters.includes(CoverageAnnotationType.Function)) { Object.entries(normalizedFileCoverage.fnMap).forEach( ([functionIndex, functionCoverage]) => { if (normalizedFileCoverage.f[+functionIndex] === 0) { @@ -111,7 +116,6 @@ export const createCoverageAnnotations = ( } ); } - } ); diff --git a/src/run.ts b/src/run.ts index c58a926..cac9323 100644 --- a/src/run.ts +++ b/src/run.ts @@ -18,7 +18,7 @@ import { } from './stages/switchBranch'; import { JsonReport } from './typings/JsonReport'; import { getOptions } from './typings/Options'; -import { DataCollector, createDataCollector } from './utils/DataCollector'; +import { createDataCollector, DataCollector } from './utils/DataCollector'; import { getNormalThreshold } from './utils/getNormalThreshold'; import { getPrPatch } from './utils/getPrPatch'; import { i18n } from './utils/i18n'; @@ -246,7 +246,10 @@ export const run = async ( skip(); } - let coverageAnnotations = createCoverageAnnotations(headCoverage!, options.annotationFilters || []); + let coverageAnnotations = createCoverageAnnotations( + headCoverage!, + options.annotationFilters || [] + ); if (coverageAnnotations.length === 0) { skip(); diff --git a/src/typings/CoverageAnnotationType.ts b/src/typings/CoverageAnnotationType.ts index b6306e7..8c08b3c 100644 --- a/src/typings/CoverageAnnotationType.ts +++ b/src/typings/CoverageAnnotationType.ts @@ -2,4 +2,4 @@ export enum CoverageAnnotationType { Statement = 'statement', Branch = 'branch', Function = 'function', -} \ No newline at end of file +} diff --git a/src/typings/Options.ts b/src/typings/Options.ts index 123824d..6852ef0 100644 --- a/src/typings/Options.ts +++ b/src/typings/Options.ts @@ -2,8 +2,8 @@ import { getInput } from '@actions/core'; import { context, getOctokit } from '@actions/github'; import * as yup from 'yup'; -import { icons } from '../format/strings.json'; import { CoverageAnnotationType } from './CoverageAnnotationType'; +import { icons } from '../format/strings.json'; export type IconType = keyof typeof icons; @@ -91,7 +91,9 @@ const optionSchema = yup.object().shape({ .required() .transform((_, originalValue: string) => originalValue.split(', ')) .of(yup.string().required().oneOf(validOutputTypeOptions)), - annotationFilters: yup.string().transform((value: string) => value.split(',')) + annotationFilters: yup + .string() + .transform((value: string) => value.split(',')), }); export const shouldInstallDeps = (skipStep: SkipStepType): Boolean => diff --git a/tests/annotations/createCoverageAnnotations.test.ts b/tests/annotations/createCoverageAnnotations.test.ts index 066807e..35a0c48 100644 --- a/tests/annotations/createCoverageAnnotations.test.ts +++ b/tests/annotations/createCoverageAnnotations.test.ts @@ -16,18 +16,33 @@ describe('createCoverageAnnotations', () => { (_, second) => second ); - expect(createCoverageAnnotations(jsonReport, [CoverageAnnotationType.Branch, CoverageAnnotationType.Function, CoverageAnnotationType.Statement])).toMatchSnapshot(); + expect( + createCoverageAnnotations(jsonReport, [ + CoverageAnnotationType.Branch, + CoverageAnnotationType.Function, + CoverageAnnotationType.Statement, + ]) + ).toMatchSnapshot(); expect( - createCoverageAnnotations((jsonReport2 as unknown) as JsonReport, [CoverageAnnotationType.Branch, CoverageAnnotationType.Function, CoverageAnnotationType.Statement]) + createCoverageAnnotations((jsonReport2 as unknown) as JsonReport, [ + CoverageAnnotationType.Branch, + CoverageAnnotationType.Function, + CoverageAnnotationType.Statement, + ]) ).toMatchSnapshot(); expect( - createCoverageAnnotations((jsonReport3 as unknown) as JsonReport, []) + createCoverageAnnotations( + (jsonReport3 as unknown) as JsonReport, + [] + ) ).toMatchSnapshot(); expect( - createCoverageAnnotations((jsonReport4 as unknown) as JsonReport, [CoverageAnnotationType.Function]) + createCoverageAnnotations((jsonReport4 as unknown) as JsonReport, [ + CoverageAnnotationType.Function, + ]) ).toMatchSnapshot(); (relative as jest.Mock).mockClear();