Convex CommunityCCConvex Community
Powered by
ShridharS
Convex Community•7mo 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!
Convex Community banner
Convex CommunityJoin
Join the Convex Discord! Explore Convex, the backend platform that keeps your app in sync.
15,138Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Recent Announcements
james

Hi @everyone with everything going on today I forgot to post on discord about our EU launch! We have a region in Dublin now! You can start using it immediately, even for folks on the free plan. https://news.convex.dev/we-finally-got-our-eu-visa/ Stay tuned for more regions but also stay tuned for more infra improvements where we improve latency for teams no matter where their servers are located. Just at the tip of the iceberg re all the optimizations we have lined up.

james · 4d ago

Wayne

Hi @everyone happy Monday. Components Authoring [Challenge](https://www.convex.dev/components/challenge) updates! Meet the second batch of community-approved components **Firecrawl Scrape **- Scrape any URL and get clean markdown, HTML, screenshots, or structured JSON - with durable caching and reactive queries. https://www.convex.dev/components/firecrawl-scrape Built by: Gitmaxd **Durable Agents **- A Convex component for building durable AI agents with an async tool loop. https://www.convex.dev/components/durable-agents Built by: Siegfried **Convex Debouncer** - A server-side debouncing component for debouncing expensive operations like LLM calls, metrics computation, or any heavy processing that should only run after a period of inactivity. https://www.convex.dev/components/debouncer Built by: Ilya **DatabaseChat **- A Convex component for adding natural language database queries to your app. https://www.convex.dev/components/database-chat Built by: Nick **Transloadit** - A Convex component for creating Transloadit Assemblies, handling resumable uploads with status, and persisting status/results in Convex. https://www.convex.dev/components/transloadit Built by: Kvz **Loops** - A Convex component for integrating with Loops.so email marketing platform. https://www.convex.dev/components/loops Built by: Bobby The [challenge](https://www.convex.dev/components/challenge) is now ongoing, so keep building, and we'll keep rewarding. Thanks, everyone!

Wayne · 3w ago

Liz C

Hi everyone! Have you ever wanted to get your hands on some convex swag? Well you're in luck! We just launched our Convex swag store. Check it out here ---> https://store.convex.dev/

Liz C · 3w ago

Similar Threads

tests don't catch return validation errors?
amppAampp / support-community
3d ago
E2E tests
Xyz3RXXyz3R / support-community
3mo ago
API tests
CillaCCilla / support-community
3y ago
finishAllScheduledFunctions breaking tests
BendeBBende / support-community
5mo ago