To set up testing for the Prosemirror Sync Convex component with convex-test, you need to ensure that:
- You have the correct schema and modules setup.
- You register the component with
convexTest.
- You handle module resolution issues, especially with pnpm.
1. Schema and Modules Setup
The Prosemirror Sync component does not export its schema directly, which can cause import issues if you try to import it from the package internals. Instead, you should define your own schema for your Convex project and use that in your tests.
Example schema setup:
import { defineSchema, s } from "convex/schema";
export default defineSchema({
documents: s.table({
title: s.string(),
}),
});
2. Registering the Component in Tests
You need to register the component in your test setup using t.registerComponent. There is an example in the convex-test repo for custom components, but for npm-installed components like Prosemirror Sync, you should follow the pattern used in this example.
Key steps:
- Import your schema (not the component's internal schema).
- Use
import.meta.glob to collect your Convex function modules if you have a custom folder structure or are using pnpm.
Example test setup:
import { convexTest } from "convex-test";
import schema from "./schema";
export const modules = import.meta.glob("./**/!(*.*.*)*.*s");
import { modules } from "./test.setup";