question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Storybook pulls my tests

See original GitHub issue

I’m attempting to migrate from the default builder to vite. For some reason, storybook shows some error about @testing-library/dom and pretty-format. They should be not there in the first place because those are testing only libraries. I tried to include or exclude them from optimizeDeps without success. I don’t understand why it tries to pull them. Maybe it pulls all the tsconfig files, I don’t know. I have 3 tsconfig files at the root of my project, one for dev, one for tests and one for eslint.

Edit : I talked about this issue here : https://github.com/testing-library/dom-testing-library/issues/985

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
JesusTheHuncommented, Jun 30, 2021

Ok I finally got it working. I was all wrong. Oh boy. I was wrong.

Turns out my main tsconfig.json is used, by default. I still use the plugin so it includes the root for my aliases but that’s all it will do for me. The problem is that in my very tsconfig.json I’m only exluding the usuals :

{
  "include": [
    "src",
    "typings"
  ],
  "exclude": [
    "src/**/*.spec.*",
    "**/node_modules",
    "**/.*/"
  ],
}

Turns out to build my stories I use some utils I created. Those utils were located in a file along with other utils. Those other utils were using and therefore importing @testing-library/react. So I split all my utils into three files : dev-common-utils.tsx for shared utils, stories-utils.tsx for stories-only utils, and finally tests-utils.tsx for jest stuff, including @testing-library. Now, only tests-utils.tsx imports @testing-library. I also notice my setupTests.ts was included in my tsconfig.json and also carries some imports of @testing-library .

So after splitting my utils I updated my tsconfig.json to the following :

{
  "include": [
    "src",
    "typings"
  ],
  "exclude": [
    "src/**/*.spec.*",
    "src/setupTests.ts",
    "src/utils-dev/tests-utils.tsx",
    "**/node_modules",
    "**/.*/"
  ],
}

My .storybook/main.js viteFinal looks very casual now :

async viteFinal(config) {
    config.plugins.push(tsconfigPaths(), svgr()); // tsconfigPaths() is for aliases, nothing to do with our issue
    return config;
  },

I hope I gave enough details so people struggling with the same issue can fix it more quickly than I did 😃

1reaction
JesusTheHuncommented, Jun 29, 2021

Right now what seems the closest to work is :

  async viteFinal(config) {
    config.plugins.push(tsconfigPaths());
    config.optimizeDeps.exclude = ['@testing-library/react', '@babel/runtime', 'format-js']
    return config;
  },
Read more comments on GitHub >

github_iconTop Results From Across the Web

Interaction tests - Storybook - JS.ORG
How does component testing in Storybook work? ... You start by writing a story to set up the component's initial state. Then simulate...
Read more >
This story has tests configured, but no file was found #13885
I have setup storybook 6.1.17 including the jest addon I have managed to get the command line jest command working and test output...
Read more >
How to use Testing Library to test Storybook
You are using Storybook for your components and writing tests for them ... Storybook on GitHub, create an issue, or submit a pull...
Read more >
Using Storybook stories with Testing Library - YouTube
Did you know that you can import your stories from Storybook and run them as tests ? I recently learned about this cool...
Read more >
Visual Regression Testing and React Storybook
import '@storybook/addon-knobs/register';. Next, you can add the Knobs to all your stories globally (you could do it for each story individually ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found