import SFPLogger , { Logger , LoggerLevel } from "../../logger/SFPLogger" ; export default class IndividualClassCoverage { public constructor ( private codeCoverage , private logger ) { } public getIndividualClassCoverage ( ) { let individualClassCoverage = [ ] ; individualClassCoverage = this . codeCoverage . map ( ( cls ) => { return { name : cls . name , coveredPercent : cls . coveredPercent } ; } ) ; return individualClassCoverage ; } public validateIndividualClassCoverage ( individualClassCoverage , coverageThreshold ? ) { if ( coverageThreshold < 75 ) { SFPLogger . log ( "Setting minimum coverage percentage to 75%." , LoggerLevel . INFO , this . logger ) ; coverageThreshold = 75 ; } SFPLogger . log ( `Validating individual classes for code coverage greater than ${ coverageThreshold } percent` , LoggerLevel . INFO , this . logger ) ; let classesWithInvalidCoverage = individualClassCoverage . filter ( ( cls ) => { return cls . coveredPercent < coverageThreshold ; } ) ; if ( classesWithInvalidCoverage . length > 0 ) { return { result : false , message : 'There are classes which do not satisfy the individual coverage requirements' , classesCovered : individualClassCoverage , classesWithInvalidCoverage : classesWithInvalidCoverage , } ; } else return { result : true , message : 'All classes in this test run meet the required coverage threshold' , classesCovered : individualClassCoverage } ; } } export type CoverageOptions = { isPackageCoverageToBeValidated : boolean ; isIndividualClassCoverageToBeValidated : boolean ; coverageThreshold : number ; } ; export type ClassCoverage = { name : string ; coveredPercent : number ; } ;