Eva
Eva4mo 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
10 Replies
vɔːʊlkɔː
vɔːʊlkɔː4mo ago
how does your package.json look like?
Eva
EvaOP4mo 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"
}
}
Satchamo
Satchamo4mo ago
@Eva facing the same issue...how did you fix it?
morvud
morvud4mo 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"));
Satchamo
Satchamo4mo ago
In nextjs i get this error: js Property 'glob' does not exist on type 'ImportMeta'.ts(2339)
morvud
morvud4mo 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?
Satchamo
Satchamo4mo ago
No I'm only doing imports in my test files
Satchamo
Satchamo4mo ago
No description
sshader
sshader4mo 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
EvaOP4mo 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!