-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(stryker): #438 Extensive config validation #549
Changes from 4 commits
d445a44
54326e6
549ff08
804ccd4
cb7eab2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,15 @@ export default class ConfigValidator { | |
validate() { | ||
this.validateTestFramework(); | ||
this.validateThresholds(); | ||
this.validateLogLevel(); | ||
this.validateTimeout(); | ||
this.validateIsNumber('port', this.strykerConfig.port); | ||
this.validateIsNumber('maxConcurrentTestRunners', this.strykerConfig.maxConcurrentTestRunners); | ||
this.validateIsString('mutator', this.strykerConfig.mutator); | ||
this.validateIsStringArray('plugins', this.strykerConfig.plugins); | ||
this.validateIsStringArray('reporter', this.strykerConfig.reporter); | ||
this.validateIsStringArray('transpilers', this.strykerConfig.transpilers); | ||
this.validateCoverageAnalysis(); | ||
this.downgradeCoverageAnalysisIfNeeded(); | ||
this.crashIfNeeded(); | ||
} | ||
|
@@ -48,6 +57,27 @@ export default class ConfigValidator { | |
} | ||
} | ||
|
||
private validateLogLevel() { | ||
const logLevel = this.strykerConfig.logLevel; | ||
const VALID_LOG_LEVEL_VALUES = ['fatal', 'error', 'warn', 'info', 'debug', 'trace', 'all', 'off']; | ||
if (VALID_LOG_LEVEL_VALUES.indexOf(logLevel) < 0) { | ||
this.invalidate('\`logLevel\` is invalid, expected one of \`fatal\`, \`error\`, \`warn\`, \`info\`, \`debug\`, \`trace\`, \`all\` and \`off\`'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is actually done in |
||
} | ||
} | ||
|
||
private validateTimeout() { | ||
this.validateIsNumber('timeoutMs', this.strykerConfig.timeoutMs); | ||
this.validateIsNumber('timeoutFactor', this.strykerConfig.timeoutFactor); | ||
} | ||
|
||
private validateCoverageAnalysis() { | ||
const VALID_COVERAGE_ANALYSIS_VALUES = ['perTest', 'all', 'off']; | ||
const coverageAnalysis = this.strykerConfig.coverageAnalysis; | ||
if (VALID_COVERAGE_ANALYSIS_VALUES.indexOf(coverageAnalysis) < 0) { | ||
this.invalidate(`Value "${coverageAnalysis}" is invalid for \`coverageAnalysis\`. Expected one of the folowing: ${VALID_COVERAGE_ANALYSIS_VALUES.map(v => `"${v}"`).join(', ')}`); | ||
} | ||
} | ||
|
||
private downgradeCoverageAnalysisIfNeeded() { | ||
if (this.strykerConfig.transpilers.length && this.strykerConfig.coverageAnalysis !== 'off') { | ||
this.log.info('Disabled coverage analysis for this run (off). Coverage analysis using transpilers is not supported yet.'); | ||
|
@@ -61,6 +91,30 @@ export default class ConfigValidator { | |
} | ||
} | ||
|
||
private validateIsNumber(fieldName: keyof Config, value: any) { | ||
if (typeof value !== 'number') { | ||
this.invalidate(`${fieldName} is invalid, expected a number`); | ||
} | ||
} | ||
|
||
private validateIsString(fieldName: keyof Config, value: any) { | ||
if (typeof value !== 'string') { | ||
this.invalidate(`${fieldName} is invalid, expected a string`); | ||
} | ||
} | ||
|
||
private validateIsStringArray(fieldName: keyof Config, value: any) { | ||
if (!Array.isArray(value)) { | ||
this.invalidate(`${fieldName} is invalid, expected an array`); | ||
} else { | ||
value.forEach(v => { | ||
if (typeof v !== 'string') { | ||
this.invalidate(`${fieldName} is invalid, expected an array of strings`); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
private invalidate(message: string) { | ||
this.log.fatal(message); | ||
this.isValid = false; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love this, very much readable!