Skip to content

Commit aa8566e

Browse files
authored
chore: Disable animations when taking screenshots (#96)
1 parent ad6c1ec commit aa8566e

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

pages/app/app-context.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ interface AppUrlParams {
1313
direction: "ltr" | "rtl";
1414
motionDisabled: boolean;
1515
i18n: boolean;
16+
screenshotMode: boolean;
1617
}
1718

1819
export interface AppContextType<T = unknown> {
@@ -29,6 +30,7 @@ const appContextDefaults: AppContextType = {
2930
direction: "ltr",
3031
motionDisabled: false,
3132
i18n: true,
33+
screenshotMode: false,
3234
},
3335
setUrlParams: () => {},
3436
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
/*
7+
Spinner animations do not follow our general motion configuration, we need to disable them explicitly to get stable
8+
screenshot testing results
9+
*/
10+
.no-animation {
11+
*,
12+
*:before,
13+
*:after {
14+
animation: none !important;
15+
transition: none !important;
16+
}
17+
}

pages/app/screenshot-area.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
import { ReactNode } from "react";
4+
import { ReactNode, useContext } from "react";
5+
import clsx from "clsx";
6+
7+
import AppContext from "./app-context";
8+
9+
import styles from "./screenshot-area.module.css";
510

611
export function ScreenshotArea({ children }: { children: ReactNode }) {
7-
return <div className="screenshot-area">{children}</div>;
12+
const { urlParams } = useContext(AppContext);
13+
return <div className={clsx("screenshot-area", urlParams.screenshotMode && styles["no-animation"])}>{children}</div>;
814
}

test/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function setupTest<P extends BasePageObject & { init?(): Promise<void> }>
1313
test: (page: P) => Promise<void>,
1414
) {
1515
return useBrowser(windowSize, async (browser) => {
16-
await browser.url(url);
16+
await browser.url(`${url}?screenshotMode=true`);
1717
const page = new PageClass(browser);
1818
await page.waitForVisible("main");
1919

0 commit comments

Comments
 (0)