#Vitest support

13 messages · Page 1 of 1 (latest)

topaz depot
#

I was hoping to migrate my TypeScript and SolidJS project template from using Jest to Vitest for a nice little speed boost and to reduce my number of dependencies, but I'm encountering some errors. I'm trying to find out what I'm doing wrong, or if Vitest support just isn't fully baked yet.

I've got this on a GitHub branch here: https://github.com/mikefarquhar/typescript-solid-application/tree/vitest_testing
I'm using Node v20 and NPM v10.4.0
My package versions are up-to-date in the lockfile as of the time of writing so I don't believe I'm seeing issues with out-of-date package versions.

The errors I've been seeing are:

  1. "You appear to have multiple instances of Solid. This can lead to unexpected behavior."
    I've seen this pop up in a number of GitHub issues posts, but they look to have been resolved. None of the solutions in said posts are working for me though.

I've made sure that there is only one copy of SolidJS in my project, so I assume something between vite, vitest and vite-plugin-solid is somehow making Solid load twice.

  1. "computations created outside a createRoot or render will never be disposed"
    This shows up once per test unless I add
deps: {
  optimizer: {
    web: {
      exclude: ["solid-js"],
    },
  },
},

This error shows up regardless of whether I'm using any reactive signals or effects. Adding the above to the test config however causes the next problem.

  1. Signals will update values in the browser, but fail to do so within the Vitest environment.
    This is as it sounds. I've effectively followed the basic example from the docs and the count never updates if the config above is set.

Any help or guidance would be appreciated, even if the advice is to just continue using Jest for now.

GitHub

Template for SolidJS applications using TypeScript - GitHub - mikefarquhar/typescript-solid-application at vitest_testing

Solid is a purely reactive library. It was designed from the ground up with a reactive core. It's influenced by reactive principles developed by previous libraries.

brittle zenith
high ruin
#

I needed to add this to the vite config, because I used other packages with solid that start with „@solid“. Hope this helps

test: {
environment: 'jsdom',

globals: true,
testTransformMode: {web: ['/.[jt]sx?$/']},
deps: {
  inline: [/solid-js/, /@solid/],
},

},

vagrant folio
#

With the new version of the vite plugin, you shouldn't need extra configurations anymore.

pseudo gust
#

sometimes I think solids templates and examples are to simply and when added other library it doesnt works as on the example>
I have tried many configurations on example and get all the time
"You appear to have multiple instances of Solid. This can lead to unexpected behavior.
computations created outside a createRoot or render will never be disposed"

some imports on vitest are ___vite_ssr_importxxx. so not sure if some kind of ssr issue, I also dont ahve error when I inlcude <Suspense on my code, it seems like Effects is null

brittle zenith
vagrant folio
#

It doesn't really matter, as solid start uses a minimal vitest.config for testing, since vinxi does not yet support testing.

brittle zenith
vagrant folio
#

I've already opened an issue with vinxi and asked Nikhil about it, but it's not at the top of his list apparently.

topaz depot
topaz depot
pseudo gust
#

I still don't know what to about You appear to have multiple instances of Solid. This can lead to unexpected behavior."

#

also, is supposed to run test on ssr when I am developing on web only? why imports are mentioning __vite_ssr_import_xxx