vitest: [Windows] vitest exits silently without watching or printing coverage when using canvas

Describe the bug

(It seems the issue described here applies to Windows only. All failing cases listed below pass on Ubuntu via WSL2 in Windows but fail in Windows PowerShell.)

For some runs of vitest,

  • it doesn’t watch. It does print the watch output (i.e. “Waiting for file changes…”, etc.).
  • it doesn’t print a coverage report. It does print the coverage output (i.e. “% Coverage report from c8”).

Reproduction

  1. Clone https://github.com/kleinfreund/vue-accessible-color-picker/tree/a650e7fd451e1ea23eeb2f95ce4d29ec8183b3c2 (sorry, can’t reproduce this in a more minimal case but the repo should be small enough), run npm install.
  2. Set test.singleThread to true in vite.config.js.
  3. Run the following commands:
    • npx vitest
      ❌ doesn’t watch
    • npx vitest .\src\utilities\
      ❌ doesn’t watch
    • npx vitest --coverage
      ❌ doesn’t watch, doesn’t print coverage report
    • npx vitest --coverage .\src\utilities\
      ❌ doesn’t watch, doesn’t print coverage report
    • npx vitest run --coverage
      ❌ doesn’t print coverage report
    • npx vitest run --coverage .\src\utilities\
      ❌ doesn’t print coverage report
    • npx vitest .\src\utilities\color-conversions\
      ✅ watches
    • npx vitest --coverage .\src\utilities\color-conversions\
      ✅ watches, prints coverage report
    • npx vitest run --coverage .\src\utilities\color-conversions\
      ✅ prints coverage report

More context

  • Running tests using wildcards in path segments doesn’t seem to work whatsoever. All the following runs produce the “No test files found, exiting with code 1” error. Path separator doesn’t seem to matter; filter, include, exclude, and watch exclude values seem to all be correct and correctly normalized. I suspect this is some sort of lack of path resolving against the current working directory in Windows environments.
    • npx vitest run --coverage .\src
    • npx vitest run --coverage .\src\**\*.test.js
      ❌ prints “No test files found, exiting with code 1”
    • npx vitest run --coverage .\src\utilities\*.test.js
      ❌ prints “No test files found, exiting with code 1”
    • npx vitest run --coverage .\src\utilities\**\*.test.js
      ❌ prints “No test files found, exiting with code 1”
  • This is not related to Vue. I’ve ported the package to a separate web component and the exact same issue occurs in that project as well.

System Info

System:
    OS: Windows 10 10.0.22621
    CPU: (16) x64 Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
    Memory: 53.80 GB / 63.92 GB
  Binaries:
    Node: 20.5.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - C:\Program Files\nodejs\yarn.CMD
    npm: 9.8.1 - ~\dev\vue-accessible-color-picker\node_modules\.bin\npm.CMD
  npmPackages:
    vite: ^4.4.8 => 4.4.8
    vitest: ^0.34.1 => 0.34.1

Used Package Manager

npm

Validations

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (12 by maintainers)

Most upvoted comments

@mendrik Not sure this is caused by the same underlying issue. I’m not getting any errors when running the commands above. For me, it prints the regular test output and then:

 % Coverage report from c8

After which it simply exits.

(Vitest won’t clear the terminal in the next version)

Vitest 1.0.0 has now --pool=forks which uses multiple node:child_process in parallel. The previous --no-threads was using a single node:child_process.

--pool=forks worked perfectly for me, thank you!

The canvas package is unstable when run in node:worker_threads. And also the old --no-threads options seems to have fixed this so I’ll close this issue with following:

Fixed by https://github.com/vitest-dev/vitest/pull/3925 and https://github.com/vitest-dev/vitest/pull/4172.

Vitest 1.0.0 has now --pool=forks which uses multiple node:child_process in parallel. The previous --no-threads was using a single node:child_process.

If the code you are testing is incompatible with node:worker_threads, switch to --pool=forks. If you run into same error with that pool, feel free to open new issue with minimal reproduction.

I think I figured out why this happens.

One of the files in my project (src/utilities/parse-props-color.js) uses canvas (document.createElement('canvas').getContext('2d')). Removing the tests that import this file fixes the issue. I have the canvas package installed in the project, too.

It’s surprising that the tests don’t crash or throw an error of a sort. How come it just silently exits?