Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/test.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { describe, expect, it, vi } from "vitest";
import type { TestConvex } from "convex-test";
import type { GenericSchema, SchemaDefinition } from "convex/server";
import r2Test from "./test.js";

type TestInstance = TestConvex<SchemaDefinition<GenericSchema, boolean>>;

function registeredNames(name?: string) {
const registerComponent = vi.fn();
const t = { registerComponent } as unknown as TestInstance;
if (name === undefined) {
r2Test.register(t);
} else {
r2Test.register(t, name);
}
return registerComponent.mock.calls.map((call) => call[0] as string);
}

describe("register", () => {
it("registers action-retrier as a child of the r2 component", () => {
const names = registeredNames();

expect(names).toContain("r2");
expect(names).toContain("r2/actionRetrier");
expect(names).not.toContain("actionRetrier");
});

it("nests action-retrier under a custom component name", () => {
const names = registeredNames("storage");

expect(names).toContain("storage");
expect(names).toContain("storage/actionRetrier");
expect(names).not.toContain("actionRetrier");
});
});
6 changes: 4 additions & 2 deletions src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ export function register(
t: TestConvex<SchemaDefinition<GenericSchema, boolean>>,
name: string = "r2",
) {
actionRetrier.register(t);
return t.registerComponent(name, schema, modules) as unknown as ComponentApi;
const component = t.registerComponent(name, schema, modules);
// The component installs action-retrier as a child, so it lives at "<name>/actionRetrier".
actionRetrier.register(t, `${name}/actionRetrier`);
return component as unknown as ComponentApi;
}
export default { register, schema, modules };