guillemusG
Convex Community5mo ago
11 replies
guillemus

false positive "Date.now() isn't currently supported within workflows." when testing workflow

I'm hitting a → Date.now() isn't currently supported within workflows. error, even though there's no call to Date.now() in my code

the test is this:

/// <reference types="vite/client" />


import workflowComponentSchema from '../../node_modules/@convex-dev/workflow/src/component/schema'
export const workflowComponentModules = import.meta.glob(
    '../../node_modules/@convex-dev/workflow/src/component/**/!(*.*.*)*.*s',
)

test('sync', async () => {
    const t = convexTest(schema)
    t.registerComponent('workflow', workflowComponentSchema, workflowComponentModules)

    // .. some setup

    await t.mutation(internal.services.sync.startWorkflow, {
        userId,
        repoId,
    })
})



and start workflow is this:

`

export const startWorkflow = internalMutation({
    args: {
        userId: v.id('users'),
        repoId: v.id('repos'),
    },
    async handler(ctx, args) {
        let savedRepo = await ctx.db.get(args.repoId)
        if (!savedRepo) return err('repo not found')

        let startSync = new Date().toISOString()

        await workflow.start(
            ctx,
            internal.services.sync.backfillRepoWorkflow,
            {
                userId: args.userId,
                repoId: savedRepo._id,
            },
            {
                onComplete: internal.services.sync.finishBackfill,
                context: {
                    repoId: savedRepo._id,
                    backfillStartedAt: startSync,
                } satisfies FinishBackfillArgs['context'],
            },
        )
    },
})


I see that there's a new Date() call, but if I just put an empty string I still have this error.
I'm using bun with vitest, setup as close as possible as documented.
image.png
Was this page helpful?