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

Storyshots: Incorrect typings for method "test" #12361

Closed
nknapp opened this issue Sep 2, 2020 · 3 comments
Closed

Storyshots: Incorrect typings for method "test" #12361

nknapp opened this issue Sep 2, 2020 · 3 comments

Comments

@nknapp
Copy link
Contributor

nknapp commented Sep 2, 2020

Describe the bug
In the file StoryshotsOptions.ts the method test is defined as

(story: any, context: any, renderTree: RenderTree, options?: any) => any;

But in the snapshotsTestTemplate, it is called as

        testMethod({
          story: item,
          context,
          ...testMethodParams,
        }),

where ...testMethodParams is defined in src/api/index.ts as

{
    renderTree,
    renderShallowTree,
    stories2snapsConverter,
  };

To Reproduce
Steps to reproduce the behavior:

Create

  1. Create a new project with storybook (usin sb init to get some default stories)
  2. Add Storyshots
  3. Run the following test
import initStoryshots from "@storybook/addon-storyshots";

describe("test", () => {
  initStoryshots({
    framework: "react",
    suite: "All",
    test: (story, context, renderTree, options): any => {
      console.log({ story, context, renderTree, options });
    }
  });
});

Expected behavior
Based on the typings, I would have expected an output that matches the types, but the output is

{
   story: {id: 'app--default', kind: ...  },
   context: {...}
   renderTree: [Function: getRenderedTree]
   options: ...

The actual output is

 console.log src/inspect.test.ts:8
    { story:
       { story:
          { id: 'app--default',
            kind: 'App',
            name: 'Default',
            story: 'Default',
            hooks: [HooksContext],
            getDecorated: [Function],
            getOriginal: [Function: getOriginal],
            storyFn: [Function: storyFn],
            parameters: [Object],
            args: {},
            argTypes: {},
            initialArgs: {},
            globals: {},
            render: [Function: storyFn],
            fileName: './App.stories.tsx' },
         context:
          { id: 'app--default',
            kind: 'App',
            name: 'Default',
            story: 'Default',
            hooks: [HooksContext],
            getDecorated: [Function],
            getOriginal: [Function: getOriginal],
            storyFn: [Function: storyFn],
            parameters: [Object],
            args: {},
            argTypes: {},
            initialArgs: {},
            globals: {},
            render: [Function: storyFn],
            fileName: './App.stories.tsx',
            framework: 'react' },
         renderTree: [Function: getRenderedTree],
         renderShallowTree: [Function: getRenderedTree],
         stories2snapsConverter:
          Stories2SnapsConverter { getSnapshotExtension: [Function], options: [Object] } },
      context: undefined,
      renderTree: undefined,
      options: undefined }

It seems like the of the test-method should be something like:

 test?: (args: {
    story: any;
    context: any;
    renderTree: RenderTree;
    renderShallowTree: RenderTree;
    stories2SnapsConverter: Stories2SnapsConverter;
  }) => any;

System:
System:
OS: Linux 4.15 Ubuntu 18.04.3 LTS (Bionic Beaver)
CPU: (4) x64 Intel(R) Core(TM) i7-3687U CPU @ 2.10GHz
Binaries:
Node: 10.18.0 - ~/.nvm/versions/node/v10.18.0/bin/node
npm: 6.14.5 - ~/.nvm/versions/node/v10.18.0/bin/npm
Browsers:
Chrome: 79.0.3945.88
Firefox: 80.0
npmPackages:
@storybook/addon-actions: ^6.0.16 => 6.0.16
@storybook/addon-essentials: ^6.0.16 => 6.0.16
@storybook/addon-links: ^6.0.16 => 6.0.16
@storybook/addon-storyshots: ^6.0.20 => 6.0.20
@storybook/node-logger: ^6.0.16 => 6.0.16
@storybook/preset-create-react-app: ^3.1.4 => 3.1.4
@storybook/react: ^6.0.16 => 6.0.16

Additional context
Add any other context about the problem here.

@nknapp nknapp changed the title Incorrect typings for method "test" WIP: Incorrect typings for method "test" Sep 2, 2020
@nknapp nknapp changed the title WIP: Incorrect typings for method "test" Storyshots: Incorrect typings for method "test" Sep 2, 2020
@shilman
Copy link
Member

shilman commented Sep 2, 2020

@nknapp any chance you can submit a fix in a PR?

nknapp added a commit to nknapp/addon-storyshots-selenium that referenced this issue Sep 4, 2020
nknapp added a commit to nknapp/storybook that referenced this issue Sep 5, 2020
@stale
Copy link

stale bot commented Oct 4, 2020

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!

@stale stale bot added the inactive label Oct 4, 2020
@shilman shilman added the P3 label Oct 4, 2020
@stale stale bot removed the inactive label Oct 4, 2020
@shilman shilman closed this as completed in 1e802aa Oct 5, 2020
@shilman
Copy link
Member

shilman commented Oct 5, 2020

ZOMG!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.1.0-alpha.20 containing PR #12389 that references this issue. Upgrade today to try it out!

You can find this prerelease on the @next NPM tag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants