get-convex / convex-helpers

A collection of useful code to complement the official packages.
MIT License
94 stars 16 forks source link

Add support for tests against a local backend #80

Closed sshader closed 6 months ago

sshader commented 6 months ago

Adds ConvexTestingHelper to the convex-helpers npm package + a simple example of running tests with a local backend.

ianmacartney commented 6 months ago

makes sense

On Tue, Mar 12, 2024 at 7:22 AM Sarah Shader @.***> wrote:

@.**** commented on this pull request.

In convex/testingFunctions.ts https://github.com/get-convex/convex-helpers/pull/80#discussion_r1521560238 :

+export const testingQuery = customQuery(query, {

  • args: {},
  • input: async (_ctx, _args) => {
  • if (process.env.IS_TEST === undefined) {
  • throw new Error(
  • "Calling a test only function in an unexpected environment"
  • );
  • }
  • return { ctx: {}, args: {} };
  • }, +});

FWIW it'll vary from developer to developer whether they're using customCtx or verify so I kind of like the most explicit thing so there's no potential confusion around what to return.

Like if I was already using a customQuery handling a sessionId argument, I think it would be more obvious how to add this IS_TEST check to make a test only version of my query wrapper than if I used customCtx / verify

— Reply to this email directly, view it on GitHub https://github.com/get-convex/convex-helpers/pull/80#discussion_r1521560238, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACZQW63UC4C6SA35C7LPH3YX4FSNAVCNFSM6AAAAABEQ747N2VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTSMZRGIYTOMZSGA . You are receiving this because your review was requested.Message ID: @.***>