Skip to content

Commit 3fb5844

Browse files
authored
Return ComponentApi from the test register function (#301)
This lets convex-test's defineTestApp infer the component's API when the test module is passed directly in its components map.
1 parent eb52a47 commit 3fb5844

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

‎src/test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/// <reference types="vite/client" />
22
import type { TestConvex } from "convex-test";
33
import type { GenericSchema, SchemaDefinition } from "convex/server";
4+
import { componentsGeneric } from "convex/server";
5+
import type { ComponentApi } from "./component/_generated/component.js";
46
import schema from "./component/schema.js";
57
import workpool from "@convex-dev/workpool/test";
68
const modules = import.meta.glob("./component/**/*.ts");
@@ -9,11 +11,14 @@ const modules = import.meta.glob("./component/**/*.ts");
911
* Register the component with the test convex instance.
1012
* @param t - The test convex instance, e.g. from calling `convexTest`.
1113
* @param name - The name of the component, as registered in convex.config.ts.
14+
* @returns a component api to test via ctx.runMutation or for thick client
15+
* usage. Also provides types for convex-test's defineTestApp.
1216
*/
1317
export function register<
1418
Schema extends SchemaDefinition<GenericSchema, boolean>,
1519
>(t: TestConvex<Schema>, name: string = "workflow") {
1620
t.registerComponent(name, schema, modules);
1721
workpool.register(t, `${name}/workpool`);
22+
return componentsGeneric()[name] as unknown as ComponentApi;
1823
}
1924
export default { register, schema, modules };

0 commit comments

Comments
 (0)