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

Group Percy snapshots by test case name #5299

Merged
merged 3 commits into from
Sep 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions snapshots.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,19 @@ async function getPercyConfigURLs() {
let urls = [];

for (let link of links) {
const path = new URL(link).pathname.replace(/\/?$/, '/');

for (const theme of SNAPSHOT_COLOR_THEMES) {
const url = `${link}?${COLOR_THEME_QUERY_PARAM_NAME}=${theme}`;
const url = new URL(`${link}?${COLOR_THEME_QUERY_PARAM_NAME}=${theme}`);
const path = url.pathname.replace(/\/?$/, '/');

const name = `${path.slice(0, path.length - 1)}?${COLOR_THEME_QUERY_PARAM_NAME}=${theme}`;
const widths = await getWidthsForExample(path, theme);

// Default theme captured responsively, other themes captured at the largest width
urls.push({
url,
url: url.href,
name,
widths,
testCase: url.pathname.replace(/standalone\//g, ''),
});
}
}
Expand Down
14 changes: 14 additions & 0 deletions tests/snapshots.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,17 @@ test('Returns snapshots with only the expected set of color themes', async () =>
}, new Set());
expect(JSON.stringify(encounteredThemes)).toBe(JSON.stringify(new Set(SNAPSHOT_COLOR_THEMES)));
});

test('Returns snapshots with unique combination of test case and name', async () => {
const snapshots = await snapshotsTest();
const encounteredTestCaseAndName = new Map();
const failedSnapshots = [];
snapshots.forEach((snapshot) => {
const key = `${snapshot.testCase}-${snapshot.name}`;
if (encounteredTestCaseAndName.has(key)) {
failedSnapshots.push(snapshot);
}
encounteredTestCaseAndName.set(key, snapshot.url);
});
expect(failedSnapshots).toHaveLength(0);
});
Loading