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

Fix Percy on CircleCI performance issues #5048

Merged
merged 3 commits into from
Apr 4, 2024
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
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ defaults: &defaults
jobs:
percy:
<<: *defaults
resource_class: large
steps:
- checkout
- run:
Expand Down
42 changes: 33 additions & 9 deletions snapshots.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
const fs = require('fs');
const path = require('path');

const PORT = process.env.PORT || 8101;
const DOCS_URL = `http://localhost:${PORT}/docs/examples/`;

module.exports = async () => {
const {default: GetSiteUrls} = await import('get-site-urls');
let links = await GetSiteUrls(`http://0.0.0.0:${PORT}/`);
let urls = [];
async function getExampleFiles() {
// get all example files from templates folder
let files = await fs.promises.readdir(path.join(process.cwd(), 'templates/docs/examples'), {recursive: true});
mas-who marked this conversation as resolved.
Show resolved Hide resolved

// filter only HTML example files in subfolders that are not partials
files = files.filter((file) => path.dirname(file) !== '.' && file.endsWith('.html') && !path.basename(file).startsWith('_'));

return files;
}

function getExampleUrls(files) {
// add standalone versions of the examples in base and patterns folders
const standaloneFiles = files.filter((file) => file.startsWith('base/') || file.startsWith('patterns/')).map((file) => path.join('standalone', file));

links = links.found
// only snapshot examples, not the whole site
.filter((url) => url.includes('/docs/examples/'))
// remove standalone examples listing from screenshots
.filter((url) => !url.match(/examples\/standalone$/));
files = files.concat(standaloneFiles);

// map the file paths to URLs
return files.map((file) => {
mas-who marked this conversation as resolved.
Show resolved Hide resolved
file = file.replace('.html', '');
return DOCS_URL + file;
});
}

async function getPercyConfigURLs() {
let links = getExampleUrls(await getExampleFiles());
let urls = [];

for (var i = 0; i < links.length; i++) {
const url = links[i];
Expand All @@ -25,4 +45,8 @@ module.exports = async () => {
}

return urls;
}

module.exports = async () => {
return await getPercyConfigURLs();
};