How-to

Test your app

Which test fits which change: backend functions in convex-test, pages over a mock backend, the real app end to end with Playwright, all of it in CI, and a load test before launch.

Test each change at the lowest level that can catch its bug. Most tests run with no deployment and no provider, in milliseconds. A few drive the real app on the providers' test modes.

  • What powers it natively: Vitest, Convex's convex-test, @nuxt/test-utils, Playwright, and the providers' test modes: Resend's test addresses and Polar's sandbox.
  • What the package adds: nuxt-backend/test signs callers in for convex-test, nuxt-backend/test-utils puts a mock backend under your pages, and npx nuxt-backend inbox --json hands an end-to-end test its sign-in code.

Pick the level

You changedTest it withNeedsPage
A query, a mutation or an actionconvex-test, signed in as a person in a workspaceNothingTest backend functions
A page or a componentA mock backend and session in VitestNothingTest pages over a mock backend
An email's wording or languagerenderEmailNothingTest your emails
A flow across pages, sign-in or a purchasePlaywright, on a dev deploymentA Resend key in test mode, a Polar sandbox tokenRun end-to-end tests
Anything, before it mergesAll of the above on every pull requestTwo CI secrets, for end to endCheck every change in CI
The busiest paths, before launchk6, on a deployment made for the testA Convex project for the testLoad-test before launch
Code style in backend/Convex's lint rulesNothingLint backend functions

One Vitest config for both

Function tests run in Convex's edge runtime, and page tests in a Nuxt environment. Give each its own project in one config, so npx vitest run runs both:

vitest.config.ts
import { defineConfig } from 'vitest/config'
import { defineVitestProject } from '@nuxt/test-utils/config'
import { backendTestAliases } from 'nuxt-backend/test-utils'

export default defineConfig({
  test: {
    projects: [
      {
        test: {
          name: 'backend',
          include: ['backend/**/*.test.ts'],
          environment: 'edge-runtime',
        },
      },
      await defineVitestProject({
        resolve: { alias: backendTestAliases() },
        test: {
          name: 'app',
          include: ['test/app/**/*.test.ts'],
          environment: 'nuxt',
          environmentOptions: { nuxt: { domEnvironment: 'happy-dom' } },
        },
      }),
    ],
  },
})

Each page lists what to install for its half. Playwright keeps its own config and runs with npx playwright test.

Why most tests need no provider

A test that calls Polar or Resend is slow, needs a key and can fail for reasons outside your code. So the function and page tests replace the deployment: convex-test runs your functions in memory, and the mock answers your pages. The end-to-end suite is the one place a run crosses a provider, and the providers' test modes keep it from sending real mail or taking real money.

The test helpers are experimental (Stability): they follow the auth and billing flows, which may still move.