Skip to content

Commit

Permalink
馃悰 Check for alternate casing when determining dom snapshot syntax (#883)
Browse files Browse the repository at this point in the history
  • Loading branch information
wwilsman committed Apr 12, 2022
1 parent 76db82d commit 6874205
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
25 changes: 9 additions & 16 deletions packages/core/src/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,25 +128,18 @@ export async function gatherSnapshots(percy, options) {
// properties. Eagerly throws an error when missing a URL for any snapshot, and warns about all
// other invalid options which are also scrubbed from the returned migrated options.
export function validateSnapshotOptions(options) {
let schema;

// decide which schema to validate against
if ('domSnapshot' in options) {
schema = '/snapshot/dom';
} else if ('url' in options) {
schema = '/snapshot';
} else if ('sitemap' in options) {
schema = '/snapshot/sitemap';
} else if ('serve' in options) {
schema = '/snapshot/server';
} else if ('snapshots' in options) {
schema = '/snapshot/list';
} else {
schema = '/snapshot';
}
let schema = (
(['domSnapshot', 'dom-snapshot', 'dom_snapshot']
.some(k => k in options) && '/snapshot/dom') ||
('url' in options && '/snapshot') ||
('sitemap' in options && '/snapshot/sitemap') ||
('serve' in options && '/snapshot/server') ||
('snapshots' in options && '/snapshot/list') ||
('/snapshot'));

let {
// migrate and remove certain properties from validating
// normalize, migrate, and remove certain properties from validating
clientInfo, environmentInfo, snapshots, ...migrated
} = PercyConfig.migrate(options, schema);

Expand Down
8 changes: 6 additions & 2 deletions packages/core/test/snapshot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,17 @@ describe('Snapshot', () => {
domSnapshot: testDOM
}, {
url: 'http://localhost:8000/two',
domSnapshot: testDOM
dom_snapshot: testDOM
}, {
url: 'http://localhost:8000/three',
'dom-snapshot': testDOM
}]);

expect(logger.stderr).toEqual([]);
expect(logger.stdout).toEqual([
'[percy] Snapshot taken: /one',
'[percy] Snapshot taken: /two'
'[percy] Snapshot taken: /two',
'[percy] Snapshot taken: /three'
]);
});

Expand Down

0 comments on commit 6874205

Please sign in to comment.