storybookjs / test-runner

🚕 Turn stories into executable tests
https://storybook.js.org/docs/writing-tests/interaction-testing
MIT License
231 stars 72 forks source link

[Bug] "Jest did not exit one second after test run..." warning happens when image is fetched from a remote source #236

Open ImTheC opened 1 year ago

ImTheC commented 1 year ago

Describe the bug

It appears that when I use an image that is fetched from a source, it causes test-storybook to give the following warning:

Jest did not exit one second after the test run has completed.

This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with --detectOpenHandles to troubleshoot this issue.

Steps to reproduce the behavior

  1. Create a brand new Storybook project using Typescript following the documentation.
  2. Add a new story with the following code:
    
    import { Meta } from '@storybook/react';

export default { title: 'Example/Image Test', } as Meta;

export const WithAnImage = () => My CDN placeholder;


3. Run `test-storybook`
4. See error

### Expected behavior

I expected the tests to complete without giving me this warning.

### Screenshots and/or logs

<img width="700" alt="Screen Shot 2022-12-23 at 3 57 33 PM" src="https://user-images.githubusercontent.com/17373817/209408908-8942fe7a-b353-425a-b4c5-c1d62e82c93b.png">

### Environment

 - OS:  macOS Monterey 12.5
 - Node.js version: v19.2.0
 - NPM version: 8.19.3
 - Browser (if applicable): Headless browser: chromium
 - Browser version (if applicable): ??
 - Device (if applicable): N/A

### Additional context

When I use an image that is located in the public directory, I do not see this warning.
lopis commented 1 year ago

Having the same issue occasionally. I used --eject to get the jest config file and pass it detectOpenHandles: true but that didn't do anything, no extra messages were printed and jest just waits forever.

lopis commented 1 year ago

I tried using https://github.com/Raynos/leaked-handles to see if I could debug this further and got the following issue:

tcp handle leaked at one of: 
    at Object.fakeCreateConnection [as createConnection] ([...]/node_modules/leaked-handles/stacks.js:98:21)
    at [...]/node_modules/playwright-core/lib/common/netUtils.js:39:33
    at createSocket ([...]/node_modules/playwright-core/lib/common/netUtils.js:38:10)
    at SocksProxy._handleDirect ([...]/node_modules/playwright-core/lib/common/socksProxy.js:343:55)
tcp stream {
  fd: 67,
  readable: true,
  writable: true,
  address: { address: '192.168.178.20', family: 'IPv4', port: 53972 },
  serverAddr: null
}

This doesn't seem super useful, but i'll continue looking into it...

lopis commented 1 year ago

As a temporary solution, running the test-runner with --eject and setting forceExit: true forces jest to exit.

luisdelgado commented 1 year ago

I'm with the same problem, but not exactly loaded a image.