Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(validation): add validation on plugin options #2158

Merged
merged 16 commits into from
Apr 24, 2020

Conversation

nicojs
Copy link
Member

@nicojs nicojs commented Apr 22, 2020

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.

TODO

  • Add unit tests and integration tests
  • Add an e2e test for some wrong config
  • Remove additional logging from Ajv

@nicojs nicojs marked this pull request as ready for review April 24, 2020 05:19
e2e/helpers.ts Outdated Show resolved Hide resolved
@@ -27,6 +32,10 @@ export class PluginLoader implements PluginResolver {
});
}

public resolveValidationSchemaContributions(): object[] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you use a getter here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I guess we could. Wanted to keep it in line with the other method. Also want to keep it open for us to do a dynamic search in the future.


import { coreTokens } from '../di';

function mergedSchema(mainSchema: any, additionalSchemas: any[]): object {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aren't these objects? (a bit more strict than any)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but I didn't want to bother with trying to explain TypeScript that it has properties and definitions. I know they have them and it is a private API for the time being. Didn't want to waste time on writing code to validate that the schemas are valid json schemas.

@nicojs nicojs merged commit d78fe1e into master Apr 24, 2020
@nicojs nicojs deleted the feat/validate-plugin-options branch April 24, 2020 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants