-
Notifications
You must be signed in to change notification settings - Fork 18
fix: merge .percy.yml config options with snapshot options for serializeDOM #310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
f9ed826
65470c8
fef3e61
ede01f6
449acb4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -374,6 +374,25 @@ public JSONObject snapshot(String name, Map<String, Object> options) { | |
|
|
||
| Object domSnapshot = null; | ||
|
|
||
| // Merge .percy.yml config options with snapshot options (snapshot options take priority) | ||
| Map<String, Object> mergedOptions = new HashMap<>(); | ||
| if (cliConfig != null && cliConfig.has("snapshot") && !cliConfig.isNull("snapshot")) { | ||
| JSONObject snapshotConfig = cliConfig.getJSONObject("snapshot"); | ||
| for (String key : snapshotConfig.keySet()) { | ||
| mergedOptions.put(key, snapshotConfig.get(key)); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Medium] Config values land in mergedOptions as raw org.json types
Suggestion: Seed from fully-unwrapped Java types, e.g. Reviewer: stack:code-reviewer |
||
| } | ||
| } | ||
| if (options != null) { | ||
| // Only overlay non-null per-call options so a null value (set by the | ||
| // positional snapshot() overloads for unset params) does not clobber a | ||
| // real value coming from .percy.yml config. | ||
| for (Map.Entry<String, Object> entry : options.entrySet()) { | ||
| if (entry.getValue() != null) { | ||
| mergedOptions.put(entry.getKey(), entry.getValue()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| try { | ||
| JavascriptExecutor jse = (JavascriptExecutor) driver; | ||
| jse.executeScript(fetchPercyDOM()); | ||
|
|
@@ -383,10 +402,10 @@ public JSONObject snapshot(String name, Map<String, Object> options) { | |
| } catch(Exception e) { | ||
| log("Cookie collection failed " + e.getMessage(), "debug"); | ||
| } | ||
| if (isCaptureResponsiveDOM(options)) { | ||
| domSnapshot = captureResponsiveDom(driver, cookies, options); | ||
| if (isCaptureResponsiveDOM(mergedOptions)) { | ||
| domSnapshot = captureResponsiveDom(driver, cookies, mergedOptions); | ||
| } else { | ||
| domSnapshot = getSerializedDOM(jse, cookies, options); | ||
| domSnapshot = getSerializedDOM(jse, cookies, mergedOptions); | ||
| } | ||
| } catch (WebDriverException e) { | ||
| // For some reason, the execution in the browser failed. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Low] Config-supplied
widthsbecomes aJSONArray, not aListsnapshotConfig.get(key)returns org.json native types. Awidthsarray from.percy.ymlis copied intomergedOptionsas aJSONArray; Java-side consumers that branch oninstanceof Listwould silently ignore it (the serialize/POSTnew JSONObject(options)path is unaffected).Suggestion: convert
JSONArrayvalues toListwhen copying, or add a test confirming config-supplied widths flow through.Reviewer: stack:code-review