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 testing not working with Svelte #14471

Closed
etsiaDigital opened this issue Apr 4, 2021 · 2 comments
Closed

Storyshots testing not working with Svelte #14471

etsiaDigital opened this issue Apr 4, 2021 · 2 comments

Comments

@etsiaDigital
Copy link

Using Storyshots auto testing fails

Using and following the Svelte tutorial:
https://storybook.js.org/tutorials/intro-to-storybook/svelte/en/simple-component/

Running Sample.test.js works fine.
Running storybook.test.js (created following tutorial instructions) fails with: "Jest encountered an unexpected token"

Details: .../node_modules/@storybook/svelte/dist/cjs/client/preview/SlotDecorator.svelte:1
    ({"Object.":function(module,exports,require,__dirname,__filename,global,jest){<script>
                                                                                                                                        ^
It appears that the precompile of the svelte file isn't happening.
I tried svelte-jester as an alternative (to jest-transform-svelte) and got these same results.

To Reproduce
Steps to reproduce the behavior:

  1. Follow the Svelte tutorial. https://storybook.js.org/tutorials/intro-to-storybook/svelte/en/simple-component/
  2. After the Snapshot Testing instructions are performed, run "yarn test" as instructed and I get the error.

Expected behavior
I believe this wouldn't happen if the precompile of the .svelte files occurred as expected so Jest was being fed JS as it requires.

@j3rem1e
Copy link
Contributor

j3rem1e commented Apr 4, 2021

We can't ship precompiled js of the svelte files, because they should be compiled against the version on your project.

However, you just had to tell jest to transform files in @storybook/svelte :

transformIgnorePatterns: ['node_modules/(?!(@storybook/svelte)/)'],

@etsiaDigital
Copy link
Author

etsiaDigital commented Apr 4, 2021

This is why I opened an issue. I didn't know how to "tell jest to transform files in @storybook/svelte"
This should be in the default jest config.

Adding the following to package.json in the "jest" section fixed the issue:

"transformIgnorePatterns": ["node_modules/(?!(@storybook/svelte)/)"],

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

No branches or pull requests

2 participants