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

Add storyshots watch compatability for jest --watch and wallaby #2936

Closed
axelnormand opened this issue Feb 7, 2018 · 17 comments
Closed

Add storyshots watch compatability for jest --watch and wallaby #2936

axelnormand opened this issue Feb 7, 2018 · 17 comments

Comments

@axelnormand
Copy link

axelnormand commented Feb 7, 2018

Issue details

As per #2259, with storyshots there is one storyshots.test.js file so every time i change a story file, jest --watch or wallaby re-runs all the stories which is a bit slow.

Is there a way to correctly setup multiple jest tests, one per story file so the dependency chain is correct?
Happy to submit a PR but thought someone might have some ideas how I'd approach this?

Many thanks

Here is my storyshots.test.ts file where i'm using react native, typescript and prefer multiple snapshot files generated using enzyme shallow.

import initStoryshots, {
  getSnapshotFileName,
} from '@storybook/addon-storyshots';
import { shallow } from 'enzyme';
import toJson from 'enzyme-to-json';
import path from 'path';

//
// initialise storyshots
// https://github.com/storybooks/storybook/tree/master/addons/storyshots
//

// fix _global import in storyshots code to be jest global including describe method
jest.mock('global', () => global);

initStoryshots({
  framework: 'react-native',
  configPath: path.join(__dirname, 'storybook.config.js'),
  test: ({ story, context }: { story: any; context: any }) => {
    // do multi file snapshots with shallow not mount as nicer to compare for humans
    const snapshotFileName = getSnapshotFileName(context);
    const storyElement = story.render(context);
    const shallowTree = shallow(storyElement);

    if (snapshotFileName) {
      // @ts-ignore toMatchSpecificSnapshot added by storyshots
      expect(toJson(shallowTree)).toMatchSpecificSnapshot(snapshotFileName);
    }
  },
});

and my storyshots.config.js which just loads the stories dynamically generated to storyLoader.js using react-native-storybook-loader (https://github.com/elderfo/react-native-storybook-loader)

import { configure } from '@storybook/react-native';
import { loadStories } from './storyLoader';

//
// Loads the generated stories for Storybook.tsx and storyshots.test.ts
//

configure(() => {
  loadStories();
}, module);
@axelnormand axelnormand changed the title Add watch compatability for jest --watch and wallaby Add storyshots watch compatability for jest --watch and wallaby Feb 7, 2018
@Hypnosphi
Copy link
Member

cc @igor-dv

@igor-dv
Copy link
Member

igor-dv commented Feb 20, 2018

I'll try to take a look at it next week.

@stale
Copy link

stale bot commented Mar 24, 2018

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 Mar 24, 2018
@igor-dv
Copy link
Member

igor-dv commented Mar 25, 2018

As you can imagine I failed to take a look. Hope will get to it soon

@stale stale bot removed the inactive label Mar 25, 2018
@stale
Copy link

stale bot commented Apr 15, 2018

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 Apr 15, 2018
@arntj
Copy link

arntj commented Apr 30, 2018

I have a related problem. If I have setup a precommit hook with jest, and I create a file, say:
thingamabob.tsx
and a corresponding story file:
thingamabob.stories.tsx
then if I change thingamabob.tsx then jest won't detect that the storyshots related to that file should be rerun. This happens even if I create a thingamabob.test.tsx to setup stories in the same directory as thingamabob.tsx.

A fix to this or a hint of how to get around this would be much appreciated.

@stale stale bot removed the inactive label Apr 30, 2018
@igor-dv
Copy link
Member

igor-dv commented Apr 30, 2018

I assume that these all are related also to #3483.

@stale
Copy link

stale bot commented May 21, 2018

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 May 21, 2018
@macrozone
Copy link
Contributor

@igor-dv any idea how to solve this? or a workaround?

@igor-dv
Copy link
Member

igor-dv commented Jun 11, 2018

@thomasbertet added a fix to the jest-specific-snapshot that is published as v1.0.0. I assume it will be adopted here soon

@stale
Copy link

stale bot commented Jul 2, 2018

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 Jul 2, 2018
@joycollector
Copy link

@igor-dv Hi, thanks for your great work. Are there any updates on this?

@stale stale bot removed the inactive label Jul 2, 2018
@igor-dv
Copy link
Member

igor-dv commented Jul 12, 2018

The change was not adopted here yet

@stale
Copy link

stale bot commented Aug 2, 2018

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
Copy link

stale bot commented Aug 26, 2018

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 Aug 26, 2018
@igor-dv
Copy link
Member

igor-dv commented Aug 26, 2018

It was released.

@igor-dv igor-dv closed this as completed Aug 26, 2018
@issue-sh issue-sh bot removed the merged label Aug 26, 2018
@axelnormand
Copy link
Author

for any future people finding this thread, i actually ended up writing a little script to run in the prestorybook target that generates one .test.ts file per .story.tsx file. Watching then works no problem and you can check in that new .test.ts file to git.

I wrote up how i did it here: https://codeburst.io/react-native-storybook-generating-individual-test-files-to-snapshot-bdbda32625ce

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

6 participants