Skip to content
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
14 changes: 7 additions & 7 deletions .github/workflows/pr-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,12 @@ jobs:

// Page status table
const pages = ['home', 'screenshots', 'documentation', 'downloads', 'support'];
const getIcon = (name) => {
const img = report.images.find(i => i.name === name);
return !img ? '➖' : img.status === 'changed' ? '🔄' : '✅';
};
const pageRows = pages.map(p => {
const desktopImg = report.images.find(i => i.name === `${p}-desktop.png`);
const mobileImg = report.images.find(i => i.name === `${p}-mobile.png`);
const desktopIcon = !desktopImg ? '➖' : desktopImg.status === 'changed' ? '🔄' : '✅';
const mobileIcon = !mobileImg ? '➖' : mobileImg.status === 'changed' ? '🔄' : '✅';
return `| ${p} | ${desktopIcon} | ${mobileIcon} |`;
return `| ${p} | ${getIcon(`${p}-dark-desktop.png`)} | ${getIcon(`${p}-dark-mobile.png`)} | ${getIcon(`${p}-light-desktop.png`)} | ${getIcon(`${p}-light-mobile.png`)} |`;
}).join('\n');

const mergeStatus = jobStatus === 'success' && e2eStatus === 'success'
Expand All @@ -318,8 +318,8 @@ jobs:
``,
visualSection,
`### 📸 Page Status`,
`| Page | 🖥️ Desktop | 📱 Mobile |`,
`|------|-----------|----------|`,
`| Page | 🌙 Dark Desktop | 🌙 Dark Mobile | ☀️ Light Desktop | ☀️ Light Mobile |`,
`|------|----------------|----------------|-----------------|-----------------|`,
pageRows,
``,
mergeStatus,
Expand Down
33 changes: 20 additions & 13 deletions e2e/screenshots.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from '@playwright/test';
import { expectScreenshot, printWarningSummary } from './visual';
import { expectScreenshot, setTheme, printWarningSummary } from './visual';

const pages = [
{ path: '/', name: 'home' },
Expand All @@ -10,26 +10,33 @@ const pages = [
];

const MOBILE_VIEWPORT = { width: 375, height: 812 };
const themes = ['dark', 'light'] as const;

test.describe('desktop screenshots', () => {
for (const { path, name } of pages) {
test(`${name} page renders correctly`, async ({ page }) => {
await page.goto(path, { waitUntil: 'networkidle' });
await expect(page).toHaveTitle(/DiffractWD/);
await expectScreenshot(page, `${name}-desktop.png`);
});
for (const theme of themes) {
for (const { path, name } of pages) {
test(`${name} page renders correctly (${theme}, desktop)`, async ({ page }) => {
await page.goto(path, { waitUntil: 'networkidle' });
await setTheme(page, theme);
await expect(page).toHaveTitle(/DiffractWD/);
await expectScreenshot(page, `${name}-${theme}-desktop.png`);
});
}
}
});

test.describe('mobile screenshots', () => {
test.use({ viewport: MOBILE_VIEWPORT });

for (const { path, name } of pages) {
test(`${name} page renders correctly on mobile`, async ({ page }) => {
await page.goto(path, { waitUntil: 'networkidle' });
await expect(page).toHaveTitle(/DiffractWD/);
await expectScreenshot(page, `${name}-mobile.png`);
});
for (const theme of themes) {
for (const { path, name } of pages) {
test(`${name} page renders correctly (${theme}, mobile)`, async ({ page }) => {
await page.goto(path, { waitUntil: 'networkidle' });
await setTheme(page, theme);
await expect(page).toHaveTitle(/DiffractWD/);
await expectScreenshot(page, `${name}-${theme}-mobile.png`);
});
}
}
});

Expand Down
Binary file added e2e/screenshots/documentation-dark-desktop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added e2e/screenshots/documentation-dark-mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed e2e/screenshots/documentation-desktop.png
Binary file not shown.
Binary file added e2e/screenshots/documentation-light-desktop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added e2e/screenshots/documentation-light-mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed e2e/screenshots/documentation-mobile.png
Binary file not shown.
Binary file added e2e/screenshots/downloads-dark-desktop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added e2e/screenshots/downloads-dark-mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed e2e/screenshots/downloads-desktop.png
Binary file not shown.
Binary file added e2e/screenshots/downloads-light-desktop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added e2e/screenshots/downloads-light-mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed e2e/screenshots/downloads-mobile.png
Binary file not shown.
Binary file added e2e/screenshots/home-dark-desktop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added e2e/screenshots/home-dark-mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed e2e/screenshots/home-desktop.png
Binary file not shown.
Binary file added e2e/screenshots/home-light-desktop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added e2e/screenshots/home-light-mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed e2e/screenshots/home-mobile.png
Binary file not shown.
Binary file added e2e/screenshots/screenshots-dark-desktop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added e2e/screenshots/screenshots-dark-mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed e2e/screenshots/screenshots-desktop.png
Binary file not shown.
Binary file added e2e/screenshots/screenshots-light-desktop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added e2e/screenshots/screenshots-light-mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed e2e/screenshots/screenshots-mobile.png
Binary file not shown.
Binary file added e2e/screenshots/support-dark-desktop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added e2e/screenshots/support-dark-mobile.png
Binary file removed e2e/screenshots/support-desktop.png
Diff not rendered.
Binary file added e2e/screenshots/support-light-desktop.png
Binary file added e2e/screenshots/support-light-mobile.png
Binary file removed e2e/screenshots/support-mobile.png
Diff not rendered.
13 changes: 13 additions & 0 deletions e2e/visual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ export function getVisualMode(): VisualMode {
return 'warning';
}

export async function setTheme(page: Page, theme: 'dark' | 'light'): Promise<void> {
await page.evaluate((t) => {
localStorage.setItem('theme', t);
if (t === 'dark') {
document.documentElement.classList.add('dark');
} else {
document.documentElement.classList.remove('dark');
}
}, theme);
// Allow styles to settle after theme change
await page.waitForTimeout(300);
}

export async function waitForVisualStability(page: Page, timeout = 500): Promise<void> {
await page.waitForLoadState('networkidle');
await page.evaluate(() => document.fonts.ready);
Expand Down