Skip to content

Commit

Permalink
Enable experiments before Percy build (#12110)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsimha authored and Barb Paduch committed Dec 6, 2017
1 parent f8a0801 commit c79185d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
4 changes: 3 additions & 1 deletion build-system/tasks/prepend-global/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ function removeConfig(target) {
.then(file => {
let contents = file.toString();
if (numConfigs(contents) == 0) {
util.log('No configs found in', util.colors.cyan(target));
if (!process.env.TRAVIS) {
util.log('No configs found in', util.colors.cyan(target));
}
return Promise.resolve();
}
sanityCheck(contents);
Expand Down
36 changes: 34 additions & 2 deletions build-system/tasks/visual-diff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,16 @@ def generate_snapshots(page, webpages)
forbidden_css = webpage['forbidden_css']
loading_incomplete_css = webpage['loading_incomplete_css']
loading_complete_css = webpage['loading_complete_css']
enable_experiments(page, webpage['experiments'])
page.visit(url)
verify_css_elements(page, url,
forbidden_css, loading_incomplete_css, loading_complete_css)
verify_css_elements(
page,
url,
forbidden_css,
loading_incomplete_css,
loading_complete_css)
Percy::Capybara.snapshot(page, name: name)
clear_experiments(page)
end
end
end
Expand Down Expand Up @@ -336,6 +342,32 @@ def verify_css_elements(
end


# Enables the given AMP experiments.
#
# Args:
# - page: Page object used by Percy for snapshotting.
# - experiments: List of experiments to enable.
def enable_experiments(page, experiments)
if experiments
page.driver.set_cookie(
'AMP_EXP',
experiments.join('%2C'),
{ :path => '/', :domain => 'localhost' })
log('verbose', 'Setting AMP experiments ' + cyan(experiments.join(', ')))
end
end


# Clears all AMP experiment cookies.
#
# Args:
# - page: Page object used by Percy for snapshotting.
def clear_experiments(page)
page.driver.clear_cookies
log('verbose', 'Cleared all AMP experiment cookies')
end


# Enables debugging if requested via command line.
def set_debugging_level
if ARGV.include? '--debug'
Expand Down
6 changes: 6 additions & 0 deletions test/visual-diff/visual-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@
* "loading_complete_css": [
* ".loading-complete-css-class",
* ".another-loading-complete-css-class"
* ],
*
* // Experiments that must be enabled via cookies.
* "experiments": [
* "amp-feature-one",
* "amp-feature-two"
* ]
* },
*/
Expand Down

0 comments on commit c79185d

Please sign in to comment.