withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
46.66k stars 2.48k forks source link

SolidJS tests not working with Astro #12256

Open PeterDraex opened 3 weeks ago

PeterDraex commented 3 weeks ago

Astro Info

Astro                    v4.16.6
Node                     v18.20.3
System                   Linux (x64)
Package Manager          unknown
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

The new SolidJS documentation has a tutorial how to setup testing. I followed it and it resulted in this error: FAIL src/components/Counter.test.jsx [ src/components/Counter.test.jsx ] TypeError: Cannot read properties of undefined (reading 'Symbol(Node prepared with document state workarounds)')

After a lot of trial/error, I think it's not working because astro doesn't use the official vite-plugin-solid package for integration. I found a previous mention that this was considered, so I wanted to bring it to attention as it would fix the testing (I think).

What's the expected result?

Passing test

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-pqy8j7-m47wdw?file=src%2Fpages%2Findex.astro

cc @bluwy

ematipico commented 3 weeks ago

A PR would be welcome

bluwy commented 3 weeks ago

Astro uses vite-plugin-solid:

https://github.com/withastro/astro/blob/d6f17044d3873df77cfbc73230cb3194b5a7d82a/packages/integrations/solid/package.json#L37-L39

To properly set this up in Astro, you should be using the getViteConfig API and you should add the Solid integration in your Astro config.

However, after doing those, it still doesn't seem to work. I found that it's because of this line:

https://github.com/withastro/astro/blob/d6f17044d3873df77cfbc73230cb3194b5a7d82a/packages/integrations/solid/src/index.ts#L67

Where ssr: true is causing problems for some reason. Personally I'm not sure why vite-plugin-solid needed the ssr option in the first place (and dev too). But we probably have to workaround this ourselves at the meantime. I think we can not set ssr: true if process.env.VITEST is true to fix this.