New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't test component with Vitest #10
Comments
Yeah I haven't tried this one yet. What it sounds like is the environment is being mismatched. Like you are getting the server version of Solid and expecting the client. Those export conditions look right. @atk if you have any ideas? |
Did you install jsdom alongside vitest? If document is missing, there's no hydrate call. |
Hi guys, thanks for the quick response. Yes, I installed jsdom version 19.0.0. I'm not using any server side rendering, so I actually don't need the hydrate function. I was thinking it has something to do with the import statement in: When I change line 2 to: Then I get a different error message: |
Together with another user (dp on our discord), I found a potential reason: if you install your project with yarn or npm, it seems to fail with that exact reason, but if you use pnpm, for some reason yet unknown, it works. I'm still investigating why this could possibly be the case. In the meantime, you can try pnpm in order to unblock you and I'll come back to this issue once I know more. |
Wow, that's a strange issue. Yes, I'm using Dankeschön. From a fellow German living in Australia. |
I've run into the same issue and cannot use pnpm (I'm behind a corporate proxy on Windows, and can't get it to install) I would appreciate if this could be reopened and further investigated, please |
I am investigating further, but this issue seems to be on the side of vitest, not solid. |
I had the same issue with the ts/vitest template. |
After hours and hours of debugging I finally figured out the issue! It's been reported as vitest-dev/vitest#1588. In the meantime, there is a workaround: /* @file: vite.config.js */
/* snip... */
export default defineConfig({
/* snip... */
test: {
/* snip... */
deps: {
inline: [
/* snip... */
+ /solid-testing-library/,
],
},
},
}); If you do that it will work 100% of the time, regardless of which package management tool you use (npm, yarn, pnpm, etc.) Want to know why?If you only care about fixing the issue then you're done with this comment. If, on the other hand, you're curious as to what actually happened, then read on. Why the error
|
…rary For why this is necessary, see solidjs/solid-testing-library#10.
For why this is necessary, see solidjs/solid-testing-library#10.
Thank you @thislooksfun for providing a fix and documenting the whole process 🙇♂️ . It was very educational for me and helped me better understand how Vite works intensely. |
So basically, it should work if we change the export to |
@atk Not quite. In order for this to work we need
Option 1 is the quick fix proposed above, but it requires manual configuration. Option 2 is out because we can't influence In order to reach the end of
We can control everything up to the final check, but since the file will always be inside of
Option 1 is ruled out because we can't control the protocol. Option 2 is possible, but the only extensions options that I know of are All of this comes together to mean that the only way I can see to get around this without needing to set I think the most reliable way forwards is to have prominent documentation here in |
I have asked in the vitest discord if there's some way to expose the setting in a more direct manner, which would be allowing for a reasonable preset configuration. |
I still get this error and unfortunately I didn't fix it with @thislooksfun's solution |
@Ladvace how if you just remove |
I get the same error |
this is my config:
you are using happy-dom, I'm using jsdom |
Can you try to switch to happy dom and see if that resolves that particular error? |
I did and unfortunately, nothing changed, do I need only download it and add the string "happy-dom" or is there any other config? |
You can check my repo. It's a dependency to add. If the error persists, then it's not about jsdom and look further into the differences in config. |
Make also sure to update vitest and vite to latest version |
yeah I'm giving it a look and I'm checking, I don't if this could related to the fact that I'm using pnpm instead of npm. I'll check, thanks |
After some digging, I found the problem but I didn't really understand why it was not working, basically, I tried the same configurations but in a new plain solid project, and I saw that when you run a test, in the in my case for some reason (I still didn't get why) this folder it's not created, but if I copy this folder manually from the plain works, the test runs correctly. |
I don't see any snapshots on my side though |
Hi,
I'm trying to test my SolidJS library with Vitest. But I'm getting the following error:
I'm using:
vite.config.js
I'm new to testing. Is my configuration correct or is it bug?
I could not find a lot of documentation on testing SolidJS with Vitest.
Thanks.
The text was updated successfully, but these errors were encountered: