Eva
Eva13mo ago

`convex-test` could not find the "_generated" directory

Just installed convex-test and wrote a very simple test at the root of my /convex folder. Running it produces an error:
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`
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`
My _generated directory is present and my convex functions are all in /convex at the root of my project. Not sure what might be the issue.
No description
11 Replies
Eva
EvaOP13mo ago
{
"name": "namesake",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"preinstall": "npx only-allow pnpm",
"dev": "npm-run-all --parallel dev:backend dev:frontend ",
"dev:frontend": "vite",
"dev:backend": "convex dev",
"build": "tsc -b && vite build",
"lint": "biome lint",
"lint:fix": "biome lint --write",
"format": "biome format",
"format:fix": "biome format --write",
"check": "biome check",
"check:fix": "biome check --write",
"preview": "vite preview",
"test": "vitest",
"test:once": "vitest run",
"test:debug": "vitest --inspect-brk --no-file-parallelism",
"test:coverage": "vitest run --coverage --coverage.reporter=text"
},
"dependencies": {
"@auth/core": "^0.34.2",
"@convex-dev/auth": "^0.0.61",
"@remixicon/react": "^4.2.0",
"@tanstack/react-router": "^1.51.6",
"convex": "^1.15.0",
"lucide-react": "^0.292.0",
"next-themes": "^0.3.0",
"postcss": "^8.4.31",
"react": "^18.3.1",
"react-aria": "^3.34.3",
"react-aria-components": "latest",
"react-dom": "^18.3.1",
"react-helmet-async": "^2.0.5",
"tailwind-variants": "^0.1.18",
"tailwindcss": "^3.4.0",
"tailwindcss-animate": "^1.0.7"
},
"devDependencies": {
"@babel/preset-react": "^7.24.1",
"@biomejs/biome": "1.8.3",
"@edge-runtime/vm": "^4.0.2",
"@tanstack/router-devtools": "^1.51.6",
"@tanstack/router-plugin": "^1.51.6",
"@types/node": "^22.5.1",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react-swc": "^3.5.0",
"@vitest/coverage-v8": "^2.0.5",
"@vitest/ui": "^2.0.5",
"autoprefixer": "^10.4.16",
"convex-test": "^0.0.28",
"globals": "^15.9.0",
"husky": "^9.1.5",
"npm-run-all": "^4.1.5",
"prop-types": "^15.8.1",
"tailwind-merge": "^2.5.2",
"tailwindcss-react-aria-components": "^1.0.0",
"typescript": "^5.5.3",
"vite": "^5.4.1",
"vitest": "^2.0.5"
},
"resolutions": {
"@types/mime": "3.0.4",
"jackspeak": "2.1.1"
}
}
{
"name": "namesake",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"preinstall": "npx only-allow pnpm",
"dev": "npm-run-all --parallel dev:backend dev:frontend ",
"dev:frontend": "vite",
"dev:backend": "convex dev",
"build": "tsc -b && vite build",
"lint": "biome lint",
"lint:fix": "biome lint --write",
"format": "biome format",
"format:fix": "biome format --write",
"check": "biome check",
"check:fix": "biome check --write",
"preview": "vite preview",
"test": "vitest",
"test:once": "vitest run",
"test:debug": "vitest --inspect-brk --no-file-parallelism",
"test:coverage": "vitest run --coverage --coverage.reporter=text"
},
"dependencies": {
"@auth/core": "^0.34.2",
"@convex-dev/auth": "^0.0.61",
"@remixicon/react": "^4.2.0",
"@tanstack/react-router": "^1.51.6",
"convex": "^1.15.0",
"lucide-react": "^0.292.0",
"next-themes": "^0.3.0",
"postcss": "^8.4.31",
"react": "^18.3.1",
"react-aria": "^3.34.3",
"react-aria-components": "latest",
"react-dom": "^18.3.1",
"react-helmet-async": "^2.0.5",
"tailwind-variants": "^0.1.18",
"tailwindcss": "^3.4.0",
"tailwindcss-animate": "^1.0.7"
},
"devDependencies": {
"@babel/preset-react": "^7.24.1",
"@biomejs/biome": "1.8.3",
"@edge-runtime/vm": "^4.0.2",
"@tanstack/router-devtools": "^1.51.6",
"@tanstack/router-plugin": "^1.51.6",
"@types/node": "^22.5.1",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react-swc": "^3.5.0",
"@vitest/coverage-v8": "^2.0.5",
"@vitest/ui": "^2.0.5",
"autoprefixer": "^10.4.16",
"convex-test": "^0.0.28",
"globals": "^15.9.0",
"husky": "^9.1.5",
"npm-run-all": "^4.1.5",
"prop-types": "^15.8.1",
"tailwind-merge": "^2.5.2",
"tailwindcss-react-aria-components": "^1.0.0",
"typescript": "^5.5.3",
"vite": "^5.4.1",
"vitest": "^2.0.5"
},
"resolutions": {
"@types/mime": "3.0.4",
"jackspeak": "2.1.1"
}
}
Huncho
Huncho12mo ago
@Eva facing the same issue...how did you fix it?
morvud
morvud12mo ago
I had the same issue and fixed it with this
const t = convexTest(schema, import.meta.glob("./**/*.*s"));
const t = convexTest(schema, import.meta.glob("./**/*.*s"));
Huncho
Huncho12mo ago
In nextjs i get this error: js Property 'glob' does not exist on type 'ImportMeta'.ts(2339)
morvud
morvud12mo ago
nextjs shouldn't even be loading the test file, are you exporting anything from the test file that might be used in your nextjs code?
Huncho
Huncho12mo ago
No I'm only doing imports in my test files
Huncho
Huncho12mo ago
No description
sshader
sshader12mo ago
re: Could not find the "_generated" directory -- I think something about pnpm sometimes does not play nicely with convexTest automatically finding your convex functions. The workaround is what morvud described of passing in a import.meta.glob (and I'll update the docs + error message to recommend this for pnpm). To get import.meta.glob to typecheck, I believe you want to add /// <reference types="vite/client" /> to the top of whatever file you're defining your glob in as shown in https://docs.convex.dev/testing/convex-test#custom-convex-folder-name-or-location (or in a pinch, add a // @ts-expect-error comment above the line TypeScript is unhappy about)
convex-test | Convex Developer Hub
The convex-test library provides a mock implementation of the Convex backend
Eva
EvaOP12mo ago
That's correct, the advice in the docs now is what I did. Defining test.setup.ts:
/// <reference types="vite/client" />
export const modules = import.meta.glob("./**/!(*.*.*)*.*s");
/// <reference types="vite/client" />
export const modules = import.meta.glob("./**/!(*.*.*)*.*s");
And then importing modules to use within the arguments of convexTest():
import { convexTest } from "convex-test";
import { expect, test } from "vitest";
import schema from "./schema";
import { modules } from "./test.setup";

test("my test", async () => {
const t = convexTest(schema, modules);
// ... test
});
import { convexTest } from "convex-test";
import { expect, test } from "vitest";
import schema from "./schema";
import { modules } from "./test.setup";

test("my test", async () => {
const t = convexTest(schema, modules);
// ... test
});
Would love if the library could be updated to avoid this for pnpm, definitely feels like extra boilerplate!
burnstony#1975
burnstony#19757mo ago
@sshader getting the same problem still, and its not at all clear from the documentation that this needs to be done, pnpm is not mentioned at https://docs.convex.dev/testing/convex-test
convex-test | Convex Developer Hub
The convex-test library provides a mock implementation of the Convex backend
conradkoh
conradkoh5mo ago
for anyone else who is trying to resolve this (including future me, again) - my workaround had to be tweaked a little. I used this instead:
/// <reference types="vite/client" /> //you need to make sure this is the first line in a file
const modules = import.meta.glob('../../**/!(*.*.*)*.*s'); //you need to check that the relative path here imports to the project root before /** in the path.
/// <reference types="vite/client" /> //you need to make sure this is the first line in a file
const modules = import.meta.glob('../../**/!(*.*.*)*.*s'); //you need to check that the relative path here imports to the project root before /** in the path.
this can be affected if you're using a folder for tests that is not inside of the convex folder, in previous versions this had to be done because you couldn't export functions from a file in the convex folder that was not a proper convex function. if you're willing to let go for pnpm safety to have a quick and dirty fix - you can just set node-linker=hoisted inside of the .npmrc - although kinda defeats the purpose of using pnpm in the first place.

Did you find this page helpful?