Skip to content

Commit

Permalink
expose cropToViewport chromatic config
Browse files Browse the repository at this point in the history
  • Loading branch information
tevanoff committed Mar 19, 2024
1 parent f149343 commit cf75f80
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/cypress/src/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ afterEach(() => {
...(Cypress.env('prefersReducedMotion') && {
prefersReducedMotion: Cypress.env('prefersReducedMotion'),
}),
...(Cypress.env('cropToViewport') && {
cropToViewport: Cypress.env('cropToViewport'),
}),
},
pageUrl: url,
viewport: {
Expand Down
4 changes: 4 additions & 0 deletions packages/cypress/tests/cypress/e2e/options.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ it('force high-contrast', { env: { forcedColors: 'active' } }, () => {
it('prefers reduced motion', { env: { prefersReducedMotion: 'reduce' } }, () => {
cy.visit('/options/prefers-reduced-motion');
});

it('crops to viewport', { env: { cropToViewport: true } }, () => {
cy.visit('/options/crop-to-viewport');
});
3 changes: 3 additions & 0 deletions packages/playwright/src/makeTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const makeTest = (
prefersReducedMotion: [undefined, { option: true }],
resourceArchiveTimeout: [DEFAULT_GLOBAL_RESOURCE_ARCHIVE_TIMEOUT_MS, { option: true }],
assetDomains: [[], { option: true }],
cropToViewport: [undefined, { option: true }],

save: [
async (
Expand All @@ -51,6 +52,7 @@ export const makeTest = (
prefersReducedMotion,
resourceArchiveTimeout,
assetDomains,
cropToViewport,
},
use,
testInfo
Expand Down Expand Up @@ -92,6 +94,7 @@ export const makeTest = (
...(forcedColors && { forcedColors }),
...(pauseAnimationAtEnd && { pauseAnimationAtEnd }),
...(prefersReducedMotion && { prefersReducedMotion }),
...(cropToViewport && { cropToViewport }),
};

await writeTestResult(
Expand Down
8 changes: 8 additions & 0 deletions packages/playwright/tests/options.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,11 @@ test.describe(() => {
await page.goto('/options/prefers-reduced-motion');
});
});

test.describe(() => {
test.use({ cropToViewport: true });

test('crops to viewport', async ({ page }) => {
await page.goto('/options/crop-to-viewport');
});
});
3 changes: 3 additions & 0 deletions packages/shared/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export interface ChromaticConfig {
// (needed when, for example, CI environment can't access the archives later on)
// ex: www.some-domain.com
assetDomains?: string[];

// Crop snapshots to the viewport size.
cropToViewport?: boolean;
}

export type ChromaticStorybookParameters = Omit<ChromaticConfig, 'disableAutoSnapshot'>;
25 changes: 25 additions & 0 deletions test-server/fixtures/options/crop-to-viewport.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="/css.urls.css" />
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body>
<div class="grid grid-flow-row m-10">
<div><img src="/img"/></div>
<div><img src="/img"/></div>
<div><img src="/img"/></div>
<div><img src="/img"/></div>
<div><img src="/img"/></div>
<div><img src="/img"/></div>
<div><img src="/img"/></div>
<div><img src="/img"/></div>
<div><img src="/img"/></div>

<div><img src="/img/another"/></div>
<div><img src="/img/another"/></div>
<div><img src="/img/another"/></div>
<div><img src="/img/another"/></div>
</div>
</body>
</html>

0 comments on commit cf75f80

Please sign in to comment.