Test your app
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/testsigns callers in forconvex-test,nuxt-backend/test-utilsputs a mock backend under your pages, andnpx nuxt-backend inbox --jsonhands an end-to-end test its sign-in code.
Pick the level
| You changed | Test it with | Needs | Page |
|---|---|---|---|
| A query, a mutation or an action | convex-test, signed in as a person in a workspace | Nothing | Test backend functions |
| A page or a component | A mock backend and session in Vitest | Nothing | Test pages over a mock backend |
| An email's wording or language | renderEmail | Nothing | Test your emails |
| A flow across pages, sign-in or a purchase | Playwright, on a dev deployment | A Resend key in test mode, a Polar sandbox token | Run end-to-end tests |
| Anything, before it merges | All of the above on every pull request | Two CI secrets, for end to end | Check every change in CI |
| The busiest paths, before launch | k6, on a deployment made for the test | A Convex project for the test | Load-test before launch |
Code style in backend/ | Convex's lint rules | Nothing | Lint 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:
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.
Related
- Test backend functions:
convex-testwith the package's components. - Test pages over a mock backend: every state a page can be in.
- Run end-to-end tests: Playwright, codes from the dev inbox, the test card.
- Develop on real sandboxes: the providers' test modes the end-to-end suite uses.
Analyze bundles
Measure the backend's Convex bundle and the Nuxt app's bundles with one command, see how much of each the package brings, act on its insights, and hold both to a budget in CI.
Pages
Render your pages and the packaged components over a mock backend and session in Vitest: signed in, signed out, loading and failed, with no deployment and no network.