Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
itsjwala committed Sep 11, 2023
1 parent b898956 commit 1792bac
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export function createPercyServer(percy, port) {
success: await percy.flush(req.body).then(() => true)
}))
.route('post', '/percy/automateScreenshot', async (req, res) => {
req = percyAutomateRequestHandler(req, percy.build);
req = percyAutomateRequestHandler(req, percy);
res.json(200, {
success: await (percy.upload(await new WebdriverUtils(req.body).automateScreenshot())).then(() => true)
});
Expand Down
47 changes: 47 additions & 0 deletions packages/core/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,53 @@ export const configSchema = {
},
scope: {
type: 'string'
},
freezeAnimation: {
type: 'boolean',
default: false,
onlyAutomate: true
},
ignoreRegions: {
type: 'object',
additionalProperties: false,
onlyAutomate: true,
properties: {
ignoreRegionSelectors: {
type: 'array',
default: [],
items: {
type: 'string'
}
},
ignoreRegionXpaths: {
type: 'array',
default: [],
items: {
type: 'string'
}
}
}
},
considerRegions: {
type: 'object',
additionalProperties: false,
onlyAutomate: true,
properties: {
considerRegionSelectors: {
type: 'array',
default: [],
items: {
type: 'string'
}
},
considerRegionXPaths: {
type: 'array',
default: [],
items: {
type: 'string'
}
}
}
}
}
},
Expand Down
26 changes: 21 additions & 5 deletions packages/core/src/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import EventEmitter from 'events';
import { sha256hash } from '@percy/client/utils';
import { camelcase, merge } from '@percy/config/utils';

export {
request,
Expand All @@ -24,17 +25,32 @@ export function normalizeURL(url) {
}

// Returns the body for automateScreenshot in structure
export function percyAutomateRequestHandler(req, buildInfo) {
export function percyAutomateRequestHandler(req, percy) {
if (req.body.client_info) {
req.body.clientInfo = req.body.client_info;
}
if (req.body.environment_info) {
req.body.environmentInfo = req.body.environment_info;
}
if (!req.body.options) {
req.body.options = {};
}
req.body.buildInfo = buildInfo;

// combines array and overrides global config with per-screenshot config
let camelCasedOptions = {};
Object.entries(req.body.options || {}).forEach(([key, value]) => {
camelCasedOptions[camelcase(key)] = value;
});

req.body.options = merge([{
percyCSS: percy.config.snapshot.percyCSS,
freezeAnimation: percy.config.snapshot.freezeAnimation,
ignoreRegionSelectors: percy.config.snapshot.ignoreRegions.ignoreRegionSelectors,
ignoreRegionXpaths: percy.config.snapshot.ignoreRegions.ignoreRegionXpaths,
considerRegionSelectors: percy.config.snapshot.considerRegions.considerRegionSelectors,
considerRegionXPaths: percy.config.snapshot.considerRegions.considerRegionXPaths
},
camelCasedOptions
]);

req.body.buildInfo = percy.build;
return req;
}

Expand Down
8 changes: 1 addition & 7 deletions packages/webdriver-utils/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import ProviderResolver from './providers/providerResolver.js';
import utils from '@percy/sdk-utils';
import { camelcase } from '@percy/config/utils';

export default class WebdriverUtils {
log = utils.logger('webdriver-utils:main');
Expand All @@ -21,12 +20,7 @@ export default class WebdriverUtils {
this.capabilities = capabilities;
this.sessionCapabilites = sessionCapabilites;
this.snapshotName = snapshotName;
const camelCasedOptions = {};
Object.keys(options).forEach((key) => {
let newKey = camelcase(key);
camelCasedOptions[newKey] = options[key];
});
this.options = camelCasedOptions;
this.options = options;
this.clientInfo = clientInfo;
this.environmentInfo = environmentInfo;
this.buildInfo = buildInfo;
Expand Down

0 comments on commit 1792bac

Please sign in to comment.