Can't have nested tests / tests in subfolders?
From claude code:
so the issue was we can't have tests in subfolders?
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!
