#Convex Test with Prosemirror Sync

5 messages · Page 1 of 1 (latest)

loud yew
#

I tried to register prosemirror sync component to convex test, but there is some import issue. Give me the guide to setup the correct schema and modules for this component.

Cannot find module '/home/benl/project/dots-connect-refresh/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_highlight._07652a5a6b75829b14e7cc2434853d11/node_modules/@convex-dev/prosemirror-sync/dist/esm/component/schema' imported from /home/benl/project/dots-connect-refresh/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_highlight._07652a5a6b75829b14e7cc2434853d11/node_modules/@convex-dev/prosemirror-sync/dist/esm/client/index.js
brazen vesselBOT
#

Hi @loud yew. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

To set up testing for the Prosemirror Sync Convex component with convex-test, you need to ensure that:

  1. You have the correct schema and modules setup.
  2. You register the component with convexTest.
  3. 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:

// convex/schema.ts
import { defineSchema, s } from "convex/schema";

export default defineSchema({
  // Define your tables here, e.g.:
  documents: s.table({
    title: s.string(),
    // ...other fields
  }),
});

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:

/// <reference types="vite/client" />
import { convexTest } from "convex-test";
import schema from "./schema";
export const modules = import.meta.glob("./**/!(*.*.*)*.*s");

// In your test file
import { modules } from "./test.setup";
#

test("some behavior", async () => {
const t = convexTest(schema, modules);
// Register the component
await t.registerComponent("@convex-dev/prosemirror-sync");
// ... your test logic
});

[See docs for custom folder setup](<https://docs.convex.dev/testing/convex-test#custom-convex-folder-name-or-location>)

### 3. Handling pnpm and Module Resolution

If you are using pnpm, `convex-test` may not automatically find your Convex functions. The workaround is to use `import.meta.glob` as shown above and pass the result as the second argument to `convexTest`. This is necessary because of how pnpm handles node_modules structure, which can break automatic discovery.

**Important:**  
Do **not** try to import the schema from inside the Prosemirror Sync package (e.g., `@convex-dev/prosemirror-sync/dist/esm/component/schema`). This is not supported and will cause the error you saw. Always use your own schema.

### Summary

- Define your own schema for your Convex project.
- Use `import.meta.glob` to collect your modules if needed.
- Register the Prosemirror Sync component in your test setup with `t.registerComponent("@convex-dev/prosemirror-sync")`.
- Do not import the schema from the component package internals.

If you follow these steps, you should be able to test the Prosemirror Sync component with `convex-test` without import errors. If you need a concrete example, refer to the [convex-test repo's component test](<https://github.com/get-convex/convex-test/blob/main/convex/components.test.ts>) and the [memory component test setup](<https://github.com/get-convex/memory/blob/main/example/convex/setup.test.ts#L7-L18>) as referenced by Convex support staff in Discord<<https://discord.com/channels/1019350475847499849/1389221529015025685>.>
#

If you run into issues with pnpm, ensure your import.meta.glob path is correct relative to your test file, as discussed in the Discord thread<https://discord.com/channels/1019350475847499849/1279661189684662292.>

Let me know if you need a more specific code example!

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: