Skip unused addons and font loads in Loki screenshot runs (#83068)

This commit is contained in:
Fraser
2026-10-06 14:23:32 +13:00
committed by GitHub
parent e2369cc1d4
commit 145357fbb1
7 changed files with 28 additions and 23 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 73 KiB

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 73 KiB

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 72 KiB

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 72 KiB

After

Width:  |  Height:  |  Size: 74 KiB

View File

@@ -61,6 +61,15 @@ const config: StorybookConfig = {
build: {
test: {
disableTreeShaking: false,
// Setting this replaces the addons --test disables by default,
// so the first three repeat Storybook's defaults.
disabledAddons: [
"@storybook/addon-docs",
"@storybook/addon-essentials/docs",
"@storybook/addon-coverage",
"@storybook/addon-a11y",
"@storybook/addon-interactions",
],
},
},
typescript: {

View File

@@ -49,16 +49,17 @@ if (
document.head.appendChild(fontFaceStyle);
}
// Force every registered font to load before the story renders. This ensures we
// use same fonts for tests every time, instead of using generic fallback
// family like `sans-serif` which might resolve to different specific fonts (depending
// on what available on current machine) which might have different metrics, in turn
// producing inconsistent behavior in code relying on measuring text (e.g., column
// autosize in table visualization). Awaiting all loads here makes measurements
// deterministic across platforms.
const PRELOADED_FONT_FAMILIES = ["Lato", "JetBrains Mono"];
// Load the app's text and monospace fonts before the story renders,
// so code that measures text, like the table's column autosize, gets the same metrics on every machine.
const fontsReady = async () => {
const loads: Promise<unknown>[] = [];
document.fonts.forEach((face) => loads.push(face.load()));
document.fonts.forEach((face) => {
if (PRELOADED_FONT_FAMILIES.includes(face.family)) {
loads.push(face.load());
}
});
await Promise.all(loads);
};

View File

@@ -20,6 +20,7 @@ import {
} from "metabase/dashboard/context/mock-context";
import { MetabaseReduxProvider } from "metabase/redux";
import { stableStringify } from "metabase/utils/objects";
import { checkNotNull } from "metabase/utils/types";
import { BarChart } from "metabase/visualizations/visualizations/BarChart";
import { Table } from "metabase/visualizations/visualizations/Table/Table";
import TABLE_RAW_SERIES from "metabase/visualizations/visualizations/Table/stories-data/orders-with-people.json";
@@ -398,25 +399,19 @@ const createDefaultArgs = ({
};
function getLastPopover() {
// Unjustified type cast. FIXME
const lastPopover = Array.from(
document.documentElement.querySelectorAll(
'[data-element-id="mantine-popover"]',
),
).at(-1) as HTMLElement;
return within(lastPopover);
return within(getLastPopoverElement());
}
function getLastPopoverElement() {
// Unjustified type cast. FIXME
const lastPopover = Array.from(
document.documentElement.querySelectorAll(
'[data-element-id="mantine-popover"]',
),
).at(-1) as HTMLElement;
const popovers = document.documentElement.querySelectorAll<HTMLElement>(
'[data-element-id="mantine-popover"]',
);
// Mantine renders an input's options dropdown as a hidden popover when there are no options.
const lastPopover = Array.from(popovers)
.filter((popover) => popover.checkVisibility())
.at(-1);
return lastPopover;
return checkNotNull(lastPopover);
}
export const LightThemeText = {