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

Provide a method to retrieve parameters in the API hooks #97

Closed
shilman opened this issue Apr 23, 2022 · 3 comments
Closed

Provide a method to retrieve parameters in the API hooks #97

shilman opened this issue Apr 23, 2022 · 3 comments
Labels
feature request New feature or request linear

Comments

@shilman
Copy link
Member

shilman commented Apr 23, 2022

Currently there is no stylized way to retrieve story parameters in API hooks.

This would be useful for reusing:

  • viewports configurations
  • a11y parameters
  • etc.

This could be provided automatically by the test-runner as part of the context argument.

  async preRender(page, context) {
    const { parameters } = context;
  },

Or maybe on=demand:

  async preRender(page, context) {
    const parameters = await getParameters(page, context);
    // OR
    const parameters = await context.getParameters(page);
  },

The benefit of on-demand is that the user would only "pay" the performance cost of retrieving parameters when they are actually used.

@lacolaco
Copy link

lacolaco commented May 20, 2022

I strongly want parameters for viewports configurations and skipping screenshots for some stories!

@jakubriedl
Copy link

This is super important for accessibility testing, but in principle for any configuration of tests.

in the meantime I workaround this by saving story props to window in decorator and reading it back in the test

preview.tsx

export const decorators: DecoratorFn[]= [
  (Story, props) => {
    window.STORY_PROPS = props
    return <Story {...props} />
  },
]

test-runner.ts

export const postRender: TestHook = async (page, context) => {
  const { parameters }: any = await page.evaluate("window.STORY_PROPS")
  // ...
}

@yannbf
Copy link
Member

yannbf commented Jun 24, 2022

Hey peeps! This was released in v0.2.0, please check the details here. Thanks for using this library!

@yannbf yannbf closed this as completed Jun 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request linear
Projects
None yet
Development

No branches or pull requests

4 participants