forked from canonical/ubuntu.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnapshots.js
More file actions
27 lines (21 loc) · 751 Bytes
/
snapshots.js
File metadata and controls
27 lines (21 loc) · 751 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const fs = require("fs");
const yaml = require("js-yaml");
// Snapshot configuration for Percy visual testing
const baseURL = "http://localhost:8001";
const timeout = 30000;
const acceptCookies = () => {
const banner = document.querySelector(".cookie-policy");
banner?.querySelector("#cookie-policy-button-accept-all")?.click();
};
// Common snapshot config factory
const makeSnapshot = (path) => ({
name: path,
url: `${baseURL}${path === "/" ? "" : path}`,
waitForTimeout: timeout,
execute: { beforeSnapshot: acceptCookies },
});
const data = yaml.load(fs.readFileSync("test-links.yaml", "utf8"));
const routes = data.links.map((link) =>
link.url.replace("https://ubuntu.com/", "/"),
);
module.exports = routes.map(makeSnapshot);