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

Issues/2024 06 28 #104

Merged
merged 6 commits into from
Jul 2, 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
4 changes: 1 addition & 3 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ const config: StorybookConfig = {
builder: {},
},
},
docs: {
autodocs: true,
},
docs: {},
webpackFinal: async (config) => {
config?.module?.rules?.push({
test: /\.scss$/,
Expand Down
3 changes: 3 additions & 0 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const preview: Preview = {
},
layout: "fullscreen",
},

decorators: [
withThemeByClassName({
themes: {
Expand All @@ -39,6 +40,8 @@ const preview: Preview = {
defaultTheme: "light",
}) as any,
],

tags: ["autodocs", "autodocs"]
};

export default preview;
32 changes: 28 additions & 4 deletions .storybook/test-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,49 @@ const { MINIMAL_VIEWPORTS } = require("@storybook/addon-viewport");

const DEFAULT_VP_SIZE = { width: 1280, height: 720 };

/**
* Attempt to solve: https://github.com/testing-library/web-testing-library/issues/3.
* GitHub's suggestions did not work at time of writing.
* @param page
* @param story
* @param attempt
* @param maxAttempts
*/
async function waitForStoryContext(
page: Page,
story: StoryFn,
attempt = 1,
maxAttempts = 20,
) {
try {
return await getStoryContext(page, story);
} catch (e) {
if (attempt > maxAttempts) {
throw e;
}
return waitForStoryContext(page, story, attempt + 1);
}
}

module.exports = {
/**
* This makes sure the test runner respects the viewport.
* @see {@link https://github.com/storybookjs/test-runner/issues/85#issuecomment-1576465128|[Bug] Tests always run in the default viewport}
* @param page
* @param story
*/
async preRender(page: Page, story: StoryFn) {
const context = await getStoryContext(page, story);
async preVisit(page: Page, story: StoryFn) {
const context = await waitForStoryContext(page, story);
const vpName =
context.parameters?.viewport?.defaultViewport ?? "responsive";
const vpParams = MINIMAL_VIEWPORTS[vpName];

if (vpParams) {
const width = parseInt(vpParams.styles.width);
const height = parseInt(vpParams.styles.height);
page.setViewportSize({ width, height });
return await page.setViewportSize({ width, height });
} else {
page.setViewportSize(DEFAULT_VP_SIZE);
return await page.setViewportSize(DEFAULT_VP_SIZE);
}
},
};
Loading