From 67a2d5c1f90cfd35531c6bbc353c9d201562ef0b Mon Sep 17 00:00:00 2001 From: Wil Wilsman Date: Wed, 6 Apr 2022 13:32:46 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Core=20snapshot=20validation=20b?= =?UTF-8?q?ug=20fixes=20(#866)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🐛 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 --- packages/config/src/validate.js | 3 +-- packages/core/src/snapshot.js | 1 + packages/core/test/snapshot-multiple.test.js | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/config/src/validate.js b/packages/config/src/validate.js index 1460ba8d5..1a29683b8 100644 --- a/packages/config/src/validate.js +++ b/packages/config/src/validate.js @@ -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}`)) ); } diff --git a/packages/core/src/snapshot.js b/packages/core/src/snapshot.js index 9bf058f93..15b445764 100644 --- a/packages/core/src/snapshot.js +++ b/packages/core/src/snapshot.js @@ -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) { diff --git a/packages/core/test/snapshot-multiple.test.js b/packages/core/test/snapshot-multiple.test.js index eae935c33..da9f83238 100644 --- a/packages/core/test/snapshot-multiple.test.js +++ b/packages/core/test/snapshot-multiple.test.js @@ -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', () => {