Skip to content

Commit

Permalink
🐛 Core snapshot validation bug fixes (#866)
Browse files Browse the repository at this point in the history
* 🐛 Remove method of validation error suppression

Before schemas could be properly inherited, this check would ensure that errors bubbled from the
correct schema. Now with full inheritance, errors can bubble from related schemas as well.

* 🐛 Do not pre-scrub empty snapshot lists

When pre-scrubbed, empty lists get removed and cause validation warnings due to the missing
property. By adding back an empty array when needed, the incorrect validate warning no longer occurs
  • Loading branch information
wwilsman authored Apr 6, 2022
1 parent db5b67f commit 67a2d5c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 1 addition & 2 deletions packages/config/src/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ function shouldHideError(key, path, error) {
let { parentSchema, keyword, schemaPath } = error;

return !(parentSchema.error || parentSchema.errors?.[keyword]) && (
HIDE_NESTED_KEYWORDS.some(k => schemaPath.includes(`/${k}`)) ||
getSchema(key, path)[path.length] !== parentSchema
HIDE_NESTED_KEYWORDS.some(k => schemaPath.includes(`/${k}`))
);
}

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export function validateSnapshotOptions(options) {

// add back snapshots before validating and scrubbing; function snapshots are validated later
if (snapshots) migrated.snapshots = typeof snapshots === 'function' ? [] : snapshots;
else if (!isSnapshot && options.snapshots) migrated.snapshots = [];
let errors = PercyConfig.validate(migrated, schema);

if (errors) {
Expand Down
9 changes: 9 additions & 0 deletions packages/core/test/snapshot-multiple.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,15 @@ describe('Snapshot multiple', () => {
'Missing required URL for snapshot'
);
});

it('rejects when missing snapshots', async () => {
await expectAsync(
percy.snapshot({ baseUrl, snapshots: () => [] })
).toBeRejectedWithError('No snapshots found');

expect(logger.stdout).toEqual([]);
expect(logger.stderr).toEqual([]);
});
});

describe('sitemap syntax', () => {
Expand Down

0 comments on commit 67a2d5c

Please sign in to comment.