Skip to content
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

🏗 Visual diff updates and fixes #35942

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 8 additions & 9 deletions build-system/tasks/visual-diff/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ const percyCss = [
// 3. Look up the full version at https://en.wikipedia.org/wiki/Google_Chrome_version_history
// 4. Open https://omahaproxy.appspot.com in a browser
// 5. Go to "Tools" -> "Version information"
// 6. Paste the full version in the "Version" field and click "Lookup"
// 6. Paste the full version (add ".0" at the end) in the "Version" field and click "Lookup"
// 7. Copy the value next to "Branch Base Position" and update the line below
const PUPPETEER_CHROMIUM_REVISION = '827102'; // 88.0.4324.0
const PUPPETEER_CHROMIUM_REVISION = '870763'; // 91.0.4472.0

const SNAPSHOT_SINGLE_BUILD_OPTIONS = {
widths: [375],
Expand All @@ -76,15 +76,14 @@ const REMOVE_AMP_SCRIPTS_SNIPPET = fs.readFileSync(
path.resolve(__dirname, 'snippets/remove-amp-scripts.js'),
'utf8'
);
const FREEZE_FORM_VALUE_SNIPPET = fs.readFileSync(
path.resolve(__dirname, 'snippets/freeze-form-values.js'),
'utf8'
);
const FREEZE_CANVAS_IMAGE_SNIPPET = fs.readFileSync(
path.resolve(__dirname, 'snippets/freeze-canvas-image.js'),
'utf8'
);

const REMOVE_NO_SCRIPT_ELEMENT_SNIPPET = fs.readFileSync(
path.resolve(__dirname, 'snippets/remove-no-script.js'),
'utf8'
);
// HTML snippet to create an error page snapshot.
const SNAPSHOT_ERROR_SNIPPET = fs.readFileSync(
path.resolve(__dirname, 'snippets/snapshot-error.html'),
Expand Down Expand Up @@ -641,8 +640,8 @@ async function snapshotWebpages(browser, webpages) {
// prepare it for snapshotting on Percy. See comments inside the
// snippet files for description of each.
await page.evaluate(REMOVE_AMP_SCRIPTS_SNIPPET);
await page.evaluate(FREEZE_FORM_VALUE_SNIPPET);
await page.evaluate(FREEZE_CANVAS_IMAGE_SNIPPET);
await page.evaluate(REMOVE_NO_SCRIPT_ELEMENT_SNIPPET);

// Create a default set of snapshot options for Percy and modify
// them based on the test's configuration.
Expand All @@ -661,7 +660,7 @@ async function snapshotWebpages(browser, webpages) {
.replace(/__PERCY_CSS__/g, percyCss)
);
} else {
snapshotOptions.percyCss = percyCss;
snapshotOptions.percyCSS = percyCss;
}

// Finally, send the snapshot to percy.
Expand Down
52 changes: 0 additions & 52 deletions build-system/tasks/visual-diff/snippets/freeze-form-values.js

This file was deleted.

22 changes: 22 additions & 0 deletions build-system/tasks/visual-diff/snippets/remove-no-script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @fileoverview This file is executed via Puppeteer's page.evaluate on a
* document to remove all <noscript> tags, from the main document and iframes.
* This makes for cleaner diffs and prevents "double-execution" of AMP scripts
* when enableJavaScript=false.
*/

/**
* Removes <noscript> elements from doc and its iframes.
* @param {Document} doc document to operate on recursively.
*/
function removeNoscript(doc) {
doc.querySelectorAll('noscript').forEach((node) => node./*OK*/ remove());

doc.body.querySelectorAll('iframe').forEach((iframe) => {
if (iframe.contentDocument) {
removeNoscript(iframe.contentDocument);
}
});
}

removeNoscript(document);