-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(validation): add validation on plugin options (#2158)
A Stryker plugin is now able to contribute to the validation of StrykerOptions. Export a JSON schema from your plugin with the name `strykerValidationSchema` and it will be added to the validation. Also some housekeeping: 🏡 * StrykerOptions now support additional options as `[k: string]: unknown` instead of `[k: string: any`. This added about 100 compiler errors that I had to fix. * We apparently had some hidden features, like options for the clear text reporter and event recorder reporter. They are now documented in the core schema Example: ``` $ npm run stryker 13:17:48 (24856) INFO ConfigReader Using stryker.conf.js 13:17:49 (24856) ERROR OptionsValidator Config option "mochaOptions['async-only']" has the wrong type. It should be a boolean, but was a string. 13:17:49 (24856) ERROR OptionsValidator Config option "tsconfig" has the wrong type. It should be a object, but was a string. 13:17:49 (24856) ERROR StrykerCli Please correct these configuration errors and try again. ```
- Loading branch information
Showing
112 changed files
with
955 additions
and
428 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
[{*.ts,*.js,*jsx,*tsx,*.json,*.code-workspace}] | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 2 | ||
indent_size = 2 | ||
end_of_line = lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"scripts": { | ||
"pretest": "rimraf stryker.log", | ||
"test": "stryker run --fileLogLevel info stryker-error-in-plugin-options.conf.json || exit 0", | ||
"posttest": "mocha --require \"ts-node/register\" verify/verify.ts" | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
e2e/test/plugin-options-validation/stryker-error-in-plugin-options.conf.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"$schema": "https://raw.githubusercontent.com/stryker-mutator/stryker/master/packages/api/schema/stryker-core.json", | ||
"mochaOptions": { | ||
"spec": "this should have been an array" | ||
}, | ||
"tsconfigFile": 42, | ||
"babel": { | ||
"extensions": "should be an array" | ||
}, | ||
"jasmineConfigFile": { | ||
"should": "be a string" | ||
}, | ||
"karma": { | ||
"projectType": "Project type not supported" | ||
}, | ||
"webpack": { | ||
"configFile": [ | ||
"should be a string" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { expect } from 'chai'; | ||
import { readLogFile } from '../../../helpers'; | ||
|
||
describe('Verify errors', () => { | ||
|
||
it('should report the expected errors', async () => { | ||
const logFile = await readLogFile(); | ||
expect(logFile).includes('Config option "mochaOptions.spec" has the wrong type'); | ||
expect(logFile).includes('Config option "tsconfigFile" has the wrong type'); | ||
expect(logFile).includes('Config option "babel.extensions" has the wrong type'); | ||
expect(logFile).includes('Config option "jasmineConfigFile" has the wrong type'); | ||
expect(logFile).not.includes('Config option "karma.projectType" has the wrong type'); | ||
expect(logFile).includes('Config option "karma.projectType" should be one of the allowed values'); | ||
expect(logFile).includes('Config option "webpack.configFile" has the wrong type'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
packages/babel-transpiler/src/BabelTranspilerWithStrykerOptions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { StrykerOptions } from '@stryker-mutator/api/core'; | ||
|
||
import { BabelTranspilerOptions } from '../src-generated/babel-transpiler-options'; | ||
|
||
export interface BabelTranspilerWithStrykerOptions extends BabelTranspilerOptions, StrykerOptions {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { StrykerBabelConfig } from '../../src-generated/babel-transpiler-options'; | ||
|
||
export function createStrykerBabelConfig(overrides?: Partial<StrykerBabelConfig>): StrykerBabelConfig { | ||
return { | ||
extensions: ['.js', '.jsx', '.es6', '.es', '.mjs'], | ||
optionsFile: '.babelrc', | ||
options: {}, | ||
...overrides, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.