convex-test does not work in yarn workspace
When following the guide on convex.dev, if one is using a yarn workspace with packages hoisted, convex-test will error out and not be able to find the _generated directory.
This was the guide I followed:
- https://docs.convex.dev/functions/testing
This is because of how the library uses
import.meta.glob
with the assumption that the relative path of node_modules is ../../../convex/**/*.*s
relative to where the library is. This is untrue for workspaces where packages are hoisted.
A workaround exists, by ensuring that the "nohoist" option is used in the workspace. It would be good to include in the docs, or update such that convex-test can run as expected even when it is hoisted to the workspace root (e.g. by using the directory of the process perhaps).9 Replies
Have you tried this?
https://docs.convex.dev/functions/testing#custom-convex-folder-name-or-location
Testing | Convex Developer Hub
Automating the testing of your Convex functions is easy.
Are you using yarn workspaces for RN? (this is a setup that we do want to support, so we should document whichever solution is preferable)
oo yeah I actually tried manually doing the
import.meta.glob(...)
step and it also worked (although typescript in the editor was complaining. but the tests passed as well.You need
/// <reference types="vite/client" />
in the file where you call glob
I'm using yarn workspaces in general, to keep the frontend (remix) separate from the backend (convex). I generally default to using a workspace with something like
- /apps/webapp - web frontend
- /services/backend - backend
this allows me to add other apps like RN for example into
- /apps/mobile
in the future.
mm to clarify - I have my interim solution - which is just to ensure that the
convex-test
package does not get hoisted to the root.Gotcha, I'll think about how to mention it in the docs.
I think the expectation is that convex-test should work regardless of where it is installed. right now it is assuming that node_modules is always
../../../convex/_generated/**/*.*s
away.
I think if that assumption is changed (e.g. maybe use the working directory to find where the script is executed from instead) might be a little more precise.
path.join(process.cwd(), convex/**/*.*s)
perhapsThe import string has to be a literal (for Vite to correctly bundle the code). So the linked docs must be used anytime this assumption is not correct.
oh I see..