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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate config using JSON schema #2123

Merged
merged 20 commits into from
Apr 19, 2020
Merged

Conversation

nicojs
Copy link
Member

@nicojs nicojs commented Mar 27, 2020

This merge request is far too big! (sorry 🙄)

A number of improvements:

  • Api: Deprecate Config in favor of StrykerOptions
    • Made Config an interface now, for the time being, to be removed in next major version
  • Api: Export the StrykerOptions JSON schema from the API
  • Core: Validate StrykerOptions using JSON schema
  • Util: Refactor: replace filterEmpty in favor of notEmpty
  • Core: Feature: hide stacktrace on validation error
  • Util: Refactor: move noopLogger to utils (used in 3 places now)
  • Util: Remove old ES5 work around in StrykerError so instanceof StrykerError works.
  • Core: Use AJV for fill in the default options.

Please don't squash merge (rebase and merge is fine), so the changelog will contain all these things.

@nicojs nicojs force-pushed the feat/validate-config-using-json-schema branch from 70e95bf to 2fcf055 Compare April 4, 2020 18:23
@nicojs
Copy link
Member Author

nicojs commented Apr 6, 2020

@nicojs nicojs force-pushed the feat/validate-config-using-json-schema branch from 2fcf055 to 627d2f7 Compare April 6, 2020 05:32
@nicojs
Copy link
Member Author

nicojs commented Apr 6, 2020

I just rebased on master, please rebase and merge instead of squash merge, if you're ready.

@nicojs
Copy link
Member Author

nicojs commented Apr 6, 2020

@simondel I've found this package and tested it out:

https://github.com/atlassian/better-ajv-errors

It actually works great. Although it won't filter the errors, so it would only be a replacement for describeError. It also comes with a small overhead: https://bundlephobia.com/[email protected].

Some examples:

image
image
image

Also, it will not represent the actual code of your Stryker options are written in plain JS format rather than your JSON format.

@nicojs
Copy link
Member Author

nicojs commented Apr 7, 2020

I think I'm falling in love with better-ajv-errors 😍

@nicojs
Copy link
Member Author

nicojs commented Apr 10, 2020

I've opened an issue to move all the ajv error filtering logic to better-ajv-errors, let's see what they think about it:

atlassian/better-ajv-errors#76

nicojs added 18 commits April 19, 2020 08:27
* Deprecate `Config`, use `StrykerOptions` instead (no `set` method)
* Deprecate `ConfigEditor`, use `OptionsEditor` instead
Use the declarative nature of JSON schema to make implementation more DRY and maintainable.

* Use [ajv](https://github.com/epoberezkin/ajv) to validate StrykerOptions against the schema
* Use ajv to fill in the default values
Introduce the `ConfigError`. If that is thrown, no stacktrace will be shown
Remove es5 workarounds around `Error`, so `err instanceof StrykerError`
works
@nicojs nicojs force-pushed the feat/validate-config-using-json-schema branch from 627d2f7 to ea6a895 Compare April 19, 2020 06:29
@nicojs nicojs merged commit eb0e60d into master Apr 19, 2020
@nicojs nicojs deleted the feat/validate-config-using-json-schema branch April 19, 2020 06:50
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.

2 participants