Shridhar
Shridhar4w ago

Can't have nested tests / tests in subfolders?

I'm trying to co-locate my tests, and my functions are in various folders. Is it possible to do so? I was running into errors, but it worked when putting them in the root convex/ directory. However, I cannot have the co-location niceness anymore From claude code:
so the issue was we can't have tests in subfolders?
⏺ Yes, exactly! That was the main issue. The convex-test library has a limitation where it expects test files to be in the root of the convex/ directory, not in subdirectories. When we had the tests at: - convex/auth/users.test.ts - convex/auth/access.test.ts And they were importing from ../_generated/api, convex-test couldn't properly resolve the module paths and gave us the "Could not find the _generated directory" error. By moving them to: - convex/users.test.ts - convex/access.test.ts And changing the imports to ./_generated/api (matching the documentation examples), everything worked. This is a quirk of how convex-test uses Vite's import.meta.glob under the hood to dynamically load the Convex modules. It seems to expect a specific directory structure where test files are siblings to the _generated directory. So the key takeaways are: 1. Keep test files in the root of the convex/ directory 2. Use relative imports from the test file's perspective (./_generated/api, not ../_generated/api) 3. Test utilities can live outside the convex directory (we put them in test-utils/) This limitation isn't clearly documented, which made it tricky to debug. But now that we know, it's easy to work around - just keep all test files at the convex root level!
2 Replies
Convex Bot
Convex Bot4w ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
Shridhar
ShridharOP4w ago
convex-test | Convex Developer Hub
Mock Convex backend for fast automated testing of functions

Did you find this page helpful?