Skip to content

Commit ea0f3fd

Browse files
committed
Use the convex-test preview from convex/convex-test#212
Also inline batch-worker in vitest, since convex-test now loads its convex.config, and pass a config to the enqueueHandler calls main added to loop.test.ts.
1 parent 49c8c76 commit ea0f3fd

6 files changed

Lines changed: 43 additions & 24 deletions

File tree

‎example/convex/componentInit.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ describe.skipIf(!supportsInit)("init args from convex.config.ts", () => {
2323

2424
test("each pool's init runs with the args its use() passes", async () => {
2525
const t = initConvexTest();
26+
workpool.register(t, "smallPool");
2627
workpool.register(t, "bigPool");
2728
workpool.register(t, "serializedPool");
2829
await t.mutation(api.example.enqueueOneMutation, { data: 1 });

‎package-lock.json‎

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
"chokidar-cli": "3.0.0",
9191
"convex": "https://pkg.pr.new/convex/convex@5d68b26",
9292
"convex-helpers": "0.1.135",
93-
"convex-test": "0.0.71",
93+
"convex-test": "https://pkg.pr.new/convex-test@212",
9494
"eslint": "10.15.0",
9595
"eslint-plugin-react-hooks": "7.1.1",
9696
"eslint-plugin-react-refresh": "0.5.8",

‎src/component/loop.test.ts‎

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
SATURATED_STATUS_COOLDOWN,
1616
STATUS_COOLDOWN,
1717
} from "./loop.js";
18+
import { effectiveConfig } from "./config.js";
1819
import { enqueueHandler } from "./lib.js";
1920
import { createLogger } from "./logging.js";
2021
import { setupTest } from "./setup.test.js";
@@ -100,14 +101,19 @@ describe("loop", () => {
100101
{ runAt, segment }: { runAt?: number; segment?: bigint } = {},
101102
): Promise<Id<"work">> {
102103
return t.run(async (ctx) => {
103-
const workId = await enqueueHandler(ctx, createLogger("WARN"), {
104-
fnType: "action",
105-
fnHandle: "test_handle",
106-
fnName: "test_handle",
107-
fnArgs: {},
108-
runAt: runAt ?? Date.now(),
109-
...overrides,
110-
});
104+
const workId = await enqueueHandler(
105+
ctx,
106+
createLogger("WARN"),
107+
effectiveConfig(null),
108+
{
109+
fnType: "action",
110+
fnHandle: "test_handle",
111+
fnName: "test_handle",
112+
fnArgs: {},
113+
runAt: runAt ?? Date.now(),
114+
...overrides,
115+
},
116+
);
111117
if (segment !== undefined) {
112118
// Pin the ordering value, e.g. to simulate a shared commit stamp.
113119
const work = (await ctx.db.get("work", workId))!;
@@ -1370,13 +1376,18 @@ describe("loop", () => {
13701376
// external fake clock to preserve Date.now() >= snapshotTs.
13711377
const { runAt, workId } = await t.run(async (ctx) => {
13721378
const runAt = Date.now() + 0.5;
1373-
const workId = await enqueueHandler(ctx, createLogger("WARN"), {
1374-
fnType: "action",
1375-
fnHandle: "test_handle",
1376-
fnName: "test_handle",
1377-
fnArgs: {},
1378-
runAt,
1379-
});
1379+
const workId = await enqueueHandler(
1380+
ctx,
1381+
createLogger("WARN"),
1382+
effectiveConfig(null),
1383+
{
1384+
fnType: "action",
1385+
fnHandle: "test_handle",
1386+
fnName: "test_handle",
1387+
fnArgs: {},
1388+
runAt,
1389+
},
1390+
);
13801391
return { runAt, workId };
13811392
});
13821393
const entry = (await observe()).pendingStart.find(

‎src/component/shared.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Infer, Validator, Value, VAny } from "convex/values";
1+
import type { Infer, Validator, Value, VAny, VString } from "convex/values";
22

33
import { v } from "convex/values";
44
import { type Logger, logLevel } from "./logging.js";
@@ -113,6 +113,10 @@ export const vRetryOverride = v.union(v.boolean(), retryBehavior);
113113
* `app.use(workpool, { args })`. Also stored verbatim on the globals document,
114114
* so this is shared between the init's `args` and the schema.
115115
*/
116+
// Matches the client's `WorkId` brand, so an app handler typed with `vWorkId`
117+
// is assignable to the init's `onComplete`.
118+
const vBrandedWorkId = v.string() as VString<string & { __isWorkId: true }>;
119+
116120
export const initArgs = {
117121
maxParallelism: v.optional(v.number()),
118122
logLevel: v.optional(logLevel),
@@ -123,8 +127,8 @@ export const initArgs = {
123127
v.function({
124128
fnType: "mutation",
125129
args: {
126-
workId: v.string(),
127-
context: v.optional(v.any()),
130+
workId: vBrandedWorkId,
131+
context: v.any(),
128132
result: v.any(),
129133
},
130134
returns: v.null(),

‎vitest.config.mts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@ export default defineConfig({
44
test: {
55
environment: "edge-runtime",
66
include: ["src/**/*.test.ts", "example/convex/**/*.test.ts"],
7+
// convex-test imports each component's convex.config to find its init,
8+
// and batch-worker's published config has extensionless relative imports.
9+
server: { deps: { inline: ["@convex-dev/batch-worker"] } },
710
},
811
});

0 commit comments

Comments
 (0)