vitest-dev / vitest

Next generation testing framework powered by Vite.
https://vitest.dev
MIT License
12.85k stars 1.15k forks source link

Vitest not working with uwebsockets.js #5576

Closed chanon closed 5 months ago

chanon commented 5 months ago

Describe the bug

Just calling uwebsocket's App() will terminate the test and Vitest will not show results of any tests.

I have tried looking through the Vitest documentation to see what the problem could be, but did not find anything.

Reproduction

Complete minimal reproduction in github repo: https://github.com/chanon/vitest-uws/

The test code in tests/minimal.test.ts:

import { test } from "vitest"
import { App } from 'uWebSockets.js'

test("test it", async () => {
    try {
        console.log('before App()')
        // try commenting out the App() call
        App()
        console.log('after App()')
    }
    catch (e) {
        console.log(e)
    }
})

Run

pnpm install
pnpm vitest

Result:

image

Comment App() call and run again.

Result:

image

System Info

(Relevant info:)

 System:
    OS: Windows 10 
  Binaries:
    Node: 20.9.0
    pnpm: 9.0.4

Used Package Manager

pnpm

Validations

AriPerkkio commented 5 months ago

Tested this on Github Codespaces and it works fine there. Does vitest --pool=forks make this work better on Windows?

chanon commented 5 months ago

Aha! yes. That works. I somehow missed that in the docs.

AriPerkkio commented 5 months ago

The uWebSockets.js seems to be native node addon. Those have some compatibility issues with Vitest's default pool. In the next major we'll be defaulting to pool: 'forks' so that this kind of issues would not come up: https://github.com/vitest-dev/vitest/pull/5047