ShridharS
Convex Community6mo ago
2 replies
Shridhar

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!
Was this page helpful?