#Failed to load url with convex-test

1 messages · Page 1 of 1 (latest)

chrome abyss
#

Hello, I'm trying to setup vitest and convex test but everytime I write a query or mutation I get a failed to load url error.

import { convexTest } from 'convex-test'
import { expect, test } from 'vitest'
import { api } from '../../_generated/api'
import schema from '../../schema'

test('creating a user', async () => {
    const t = convexTest(schema)
const mockUser = {
        clerkId: 'user_2fyL',
        username: 'cool username',
        tag: 'coolusername',
        updatedAt: new Date().getTime(),
        accountStanding: 'good'
    } satisfies WithoutSystemFields<Doc<'users'>>

    await t.mutation(api.functions.user.createUser, mockUser)

    const user = await t.run(async ctx => {
        return await ctx.db
            .query('users')
            .withIndex('by_clerkId', q => q.eq('clerkId', mockUser.clerkId))
            .first()
    })

    expect(user).toMatchObject(mockUser)
})
#

weirdly enough if I use the run function it seems to work fine? I just can't pass in my functions to the query or mutation procedures.

wintry sleet
chrome abyss
chrome abyss
#

even after moving my test to the top level of the convex folder it still seems to not work with my functions

#

I am using this within a nextjs project and utilizing vitest workspaces so I can have a different test enviroment for my convex and nextjs. If that could possibly be the issue.

wintry sleet
#

That's probably it, as I haven't tried workspaces.

chrome abyss
#

I see

wintry sleet
#

Yep, I can repro

chrome abyss
#

Ahh are there any recommended ways of testing in a nextjs project without workspaces then?

wintry sleet
#

I think if you just delete the vitest.workspace.ts file everything will work?

#

The only difference is that you can't as easily run only one set of tests or the other?

chrome abyss
#

Hmm interesting well that's fine for now

#

thanks!

wintry sleet
#

I'm looking into fixing this

chrome abyss
#

awesome thank you

lofty marlin
#

I've also run into this error twice, in two different projects

#

In one the test file was located in test/here.test.ts and the Convex functions directory was in test/convex (atypical certainly), in the other the test was in src/convex/dir/otherDir/here.test.ts (so, inside the Convex functions directory)

wintry sleet
#

Thank's @lofty marlin, it's helpful to know! I'm confident I can get this and bunch of the other related issues with convex-test fixed.

lofty marlin
#

Great, thanks @wintry sleet! Let me know if I can provide any more details/do any testing for you

stark ingot
#

Hi @wintry sleet , I'm experiencing some problems with convex-test. Specifically, whenever I run a test that imports import { api } from '@/convex/_generated/api' I get the error shown in the screenshot. Seems to be some error in node_modules/convex-test/dist/index.js, so I'm not sure how I can troubleshoot this.

It works fine if I run a simpler test that does not import api but only imports import schema from '@/convex/schema'

covert quest
stark ingot
#

@covert quest
├─ convex-helpers@npm:0.1.56
├─ convex-test@npm:0.0.33
├─ convex@npm:1.16.3

Could that be the problem, that the newest Convex version is 1.16.6 and test depends on that?

covert quest
#

Yeah you need at least [email protected] . When you installed convex-test it should have printed an error that the peer dependency isn't satisfied

stark ingot
#

I'm sure you understand it better than I do 😂 thanks man. Guess I should pay more attention to dependency warnings in the future!