-
Notifications
You must be signed in to change notification settings - Fork 874
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
@firebase/rules-unit-testing + vitest throws "Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore" #6905
Comments
Hi @YannicEl, thank you so much for reporting this issue and narrowing it down to a specific vitest version. I am looking into this and will keep you updated. Happy holidays. |
Happy new year, @YannicEl . Seems like the entry point of "firebase/firestore" might be sending user's compiler to a different file than rules-unit-testing. For now, a quick workaround is using "@firebase/firestore" instead. Could you please try that out while we look deeper into the issue? |
@YannicEl did you also try this workaround? |
I did see and try your workaround when troubleshooting but it didn't work.
So now I have a working workaround, but it would still be interesting to find out what the root problem is. I am guessing that for whatever reason the cjs version of Firestore is loaded instead of the mjs version? Thank you very much |
Happy new year to you too! Thanks for the workaround. It works in stackblitz but for some reason it doesn't work in my local project. But that is not that important at the moment because as mentioned in my previous post I have a working workaround now. Thank you very much |
I traced the import paths and I think it might be a bug with Vite that they recently fixed. This next part is maybe TMI and more for my notes:
TLDR: I think Vite is pulling in the wrong file because it's not prioritizing |
@hsubox76 Thank you for your investigation. It seems like this fix is going to be released in vite 4.1. I'll wait until it is released and then report if it fixed the issue. |
i just tested with vitest version 0.30.0 and the issue is fixed. |
Describe your environment
Describe the problem
Issue #6080 seems to be occurring again.
I am using vitest and @firebase/rules-unit-testing to test my firestore securtiy rules. With vitest versions < 0.24.0 everything works great. But since the 0.24.0 release i get the same error as in this issue #6080
Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore.
I am not sure if this is a vitest issue or a firebase issue. But since issue #6080 is resolved i am not sure if this is a regression or if there is somthing wrong with my setup.
Steps to reproduce:
https://stackblitz.com/edit/vitejs-vite-eugcsg?file=index.test.ts
run
npm run dev
and there error will show in the consoleEmulators don't have to be running for this error to occure.
The text was updated successfully, but these errors were encountered: