conradkohC
Convex Community2y ago
12 replies
conradkoh

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

 FAIL  convex/budget.test.ts > create / update budgets
Error: Could not find the "_generated" directory, make sure to run `npx convex dev` or `npx convex codegen`. If your Convex functions aren't defined in a directory called "convex" sibling to your node_modules, provide the second argument to `convexTest`
 ❯ findModulesRoot ../../node_modules/convex-test/dist/index.js:889:11
    887|         "`npx convex dev` or `npx convex codegen`. " +
    888|         (userProvidedModules
    889|             ? "Make sure your `import.meta.glob` includes the files in the " +
       |           ^
    890|                 '"_generated" directory'
    891|             : "If your Convex functions aren't defined in a directory " +
 ❯ moduleCache ../../node_modules/convex-test/dist/index.js:871:20
 ❯ Module.convexTest ../../node_modules/convex-test/dist/index.js:918:18
 ❯ convex/budget.test.ts:9:13


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