adamA
Convex Community10mo ago
9 replies
adam

`convex-test` invalid identifier

Given this code:
// messages.test.ts
import { convexTest } from 'convex-test';
import { expect, test } from 'vitest';
import { api } from './_generated/api';
import schema from './schema';

test('insert', async () => {
  const t = convexTest(schema);
  await t.mutation(api.messages.send, { author: 'adam' });
  const messages = await t.query(api.messages.list);
  expect(messages).toMatchObject([{ author: 'adam' }]);
});

It works as expected when the schema looks like this:
// schema.ts
import { defineSchema, defineTable } from 'convex/server';
import { v } from 'convex/values';

export default defineSchema(
  {
    messages: defineTable({
      author: v.string()
    }),
  },
  { schemaValidation: true },
);

However, when a system field such as
_creationTime
is added to the schema,
vitest
throws this error:
Error: Field names must be valid identifiers, got "_creationTime"


// schema.ts
import { defineSchema, defineTable } from 'convex/server';
import { v } from 'convex/values';

export default defineSchema(
  {
    messages: defineTable({
      author: v.string(),
      _creationTime: v.optional(v.number()), // <= !
    }),
  },
  { schemaValidation: true },
);

https://github.com/get-convex/convex-test/blob/83f7e271d41f086b16cfcf8f7efc53efd7491b19/index.ts#L838

Desired behaviour

Can
convex-test
accept a schema with the same policy as
defineSchema({...})
used in
schema.ts
and not a more strict policy that doesn't allow for
_creationTime
?
defineSchema({...})
allows the
_creationTime
field.
Was this page helpful?