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

@storybook/addon-storyshots supports only main.js #9576

Closed
iiroj opened this issue Jan 21, 2020 · 10 comments
Closed

@storybook/addon-storyshots supports only main.js #9576

iiroj opened this issue Jan 21, 2020 · 10 comments

Comments

@iiroj
Copy link

iiroj commented Jan 21, 2020

Describe the bug

The getMainFile method of the storyshots addon has a hardcoded name for the new configuration style for version 5.3 of main.js. This prevents usage of TypeScript, for example, where the file is main.ts.

You can see the file name here:

const main = path.join(configDir, 'main.js');

It seems the getPreviewFile method correctly supports both JS and TS files.

This results in storyshots failing with storyshots found 0 stories.

If I edit this method to also include TS files, it seems to start working again:

const getMainFile = (configDir: string): string | false => {
  const main = path.join(configDir, 'main.js');
  const mainTS = path.join(configDir, 'main.ts');

  if (isFile(main)) {
    return main;
  }

  if (isFile(mainTS) {
    return mainTS;
  }

  return false;
};
@shilman
Copy link
Member

shilman commented Jan 21, 2020

The file is never main.ts, at least for now.

@shilman shilman closed this as completed Jan 21, 2020
@iiroj
Copy link
Author

iiroj commented Jan 21, 2020

Thanks for the reply, @shilman. I assume it then works by accident? I’ll update my repo.

@shilman
Copy link
Member

shilman commented Jan 21, 2020

Does it really work?! 😱 If so, sorry for the misinformation. Reopening this.

@shilman shilman reopened this Jan 21, 2020
@iiroj
Copy link
Author

iiroj commented Jan 21, 2020

Well, at least start-storybook and build-storybook seem to run fine with a main.ts. I was having trouble only with the @storybook/addon-storyhots not finding any stories.

For now I've gotten along by converting to main.js, but having everything typed would be nice, of course.

Looking at the source, it seems main is required here without a hard-coded extension:

const main = serverRequire(path.resolve(configDir, 'main'));

Let me confirm this to you tomorrow since I managed to fix everything related to the 5.3 migration, but using a main.js. If it really works 100 % with main.ts I'll let you know.

@tobias-kuendig
Copy link

I can confirm this problem. Since the update to 5.3 the following storyshots test file does no longer find any stories:

import initStoryshots from '@storybook/addon-storyshots'

const registerRequireContextHook = require('babel-plugin-require-context-hook/register')

registerRequireContextHook()
initStoryshots({
  framework: 'vue',
  configPath: './config/storybook/'
})

storyshots found 0 stories

I also use a main.ts.

@shilman
Copy link
Member

shilman commented Jan 23, 2020

So main.ts works -- played around with it yesterday -- tho AFAICT support for it is entirely accidental. @mrmckeb and I played around for a few minutes and couldn't figure out WHY it works (that serverRequire is doing something tricky cc @igor-dv ). At any rate, will merge the fix. Thanks @iiroj !!!

@iiroj
Copy link
Author

iiroj commented Feb 3, 2020

Sorry that I never replied to this. Any idea when the fix would be merged?

@shilman
Copy link
Member

shilman commented Feb 3, 2020

Sorry, completely forgot about this. 🙈 Merging now!

@iiroj
Copy link
Author

iiroj commented Feb 5, 2020

Cool, working now!

Although it seems only module.exports works, when using export default causes no configuration to be found.

@iiroj iiroj closed this as completed Feb 5, 2020
@arty-name
Copy link
Contributor

I came here looking for an issue for not working "export default". @iiroj, do you want to open a new issue for that bug?

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

4 participants