deno icon indicating copy to clipboard operation
deno copied to clipboard

Vitest report an error with assertType<string>

Open foobar-maker opened this issue 2 months ago • 3 comments

Version: Deno 2.5.6

I run Deno test with Vitest library and want to test assertType<string>

Is it due to Deno or Vitest ?

assertType("aaa") => works assertType(uuid()) => error

PoC in zip deno-vitest.zip

./add/index.test.ts (uncaught error)
error: (in promise) Error: Vitest failed to find the current suite. This is a bug in Vitest. Please, open an issue with reproduction.
    at assert 
    at getCurrentSuite 
    at Object.<anonymous> 
    at chain 
This error was not caught from a test and caused the test runner to fail on the referenced module.
It most likely originated from a dangling promise, event/timeout handler or top-level code.

foobar-maker avatar Nov 15 '25 17:11 foobar-maker

Can you please provide a repro as a repository instead of zip archive?

bartlomieju avatar Nov 18 '25 13:11 bartlomieju

here the project https://github.com/foobar-maker/deno-vitest

foobar-maker avatar Nov 18 '25 13:11 foobar-maker

Looks like vitest calls tsc under the hood which bypasses the instance that ships with Deno:

https://github.com/vitest-dev/vitest/blob/67a39f5e3973f44bb62dd071b44106fe4e3beb13/packages/vitest/src/typecheck/typechecker.ts#L262-L310

marvinhagemeister avatar Nov 18 '25 13:11 marvinhagemeister

@marvinhagemeister how is that a bug then?

bartlomieju avatar Dec 04 '25 13:12 bartlomieju

Upon closer inspection it turns out that this particular error doesn't seem to be related to the type checking capabilities in vitest. It fails without these too. I've filed an upstream issue https://github.com/vitest-dev/vitest/issues/9170

marvinhagemeister avatar Dec 04 '25 13:12 marvinhagemeister

Well, we missed a crucial detail: The test task doesn't run vitest, it runs deno test. And then vitest rightfully complains that all the test suite detection is missing, simply because vitest wasn't run.

The fix:

  "tasks": {
-   "test": "deno test --allow-env",
+  "test": "vitest"
  },

marvinhagemeister avatar Dec 04 '25 14:12 marvinhagemeister