Conversation
The underlying merge util was refactored to accept an array of objects instead of only two objects. The options argument was replaced with a map callback argument. The function will be called for each property within each object recursively with the path, previous value, and next value of the property. A path-value pair can be returned to override the default merge behavior. Some options previously handled by the old merge function were replaced by the new map callback in the appropriate places. The validate util was also refactored, though to a much less degree. Default schema $id's now start with a forward slash to help disguish them from local schema references. The function will also now only return an array of errors on failure and undefined on success. The associated addSchema util was also updated to accept schema's without automatically adding them to the global Percy config schema. This allows the validate util to be used with other registered schemas and not just the global Percy config schema.
Heavily based on the required keyword, destructured from internal helpers, and negated since we want to disallow properties rather than require them.
This was referenced Jul 15, 2021
samarsault
pushed a commit
that referenced
this pull request
Mar 3, 2023
Bumps [cypress](https://github.com/cypress-io/cypress) from 8.3.0 to 8.3.1. - [Release notes](https://github.com/cypress-io/cypress/releases) - [Changelog](https://github.com/cypress-io/cypress/blob/develop/.releaserc.base.js) - [Commits](cypress-io/cypress@v8.3.0...v8.3.1) --- updated-dependencies: - dependency-name: cypress dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
While adding better validations for config options and per-snapshot validations, data must be validated against schemas other than the global config schema. To facilitate this, the validate util was refactored slightly. The merge util is also used within the core snapshot options config function to merge and validate provided options with config options and defaults while also handling deprecated options. Due to the merge util's limitation of only merging two objects at a time while mutating the first object, it had to be used several times in a row in order to merge all of the snapshot options together into a new object. Furthermore, it's options argument was limited in it's abilities and the merge function itself was centered around config normalization, so wasn't generic enough to use outside of said normalization function.
Approach
The
validateutils were refactored so default schema$ids now start with a forward slash (/) to help distinguish them from local schema references. The function will also now only return an array of errors on failure andundefinedon success. The associatedaddSchemautil was updated to accept schemas without automatically adding them to the global Percy config schema (via an explicit$id). This allows the validate util to be used with other registered schemas and not just the global Percy config schema.The
mergeutil was refactored to accept an array of objects instead of only two objects. It also always returns a deep clone rather than mutating the first argument. The limitedoptionsargument was replaced with amapcallback argument. The callback will be called for each property within each object, recursively, with the path, previous value, and next value of the property. A path-value pair can be returned to override the default merge behavior. Some options previously handled by the old merge function were replaced by the new map callback in the appropriate places.Other features were also added while refactoring that were found to be useful for better validations:
minimumandmaximumkeywords will be clamped rather than scrubbed.instanceofkeyword to allow functions or regular expressions.disallowedkeyword, based on the built-inrequiredkeyword (but negated).e.g.
['foo', <5 empty items>, 'xyzzy'] => ['foo', 'xyzzy']before:
snapshots.widths.0: must be <= 2000after:
snapshots.widths[0]: must be <= 2000