Skip to main content

Testing

Terra uses Vitest for unit tests and Playwright for E2E tests.

Test Stack

ToolPurpose
VitestUnit and integration tests
PlaywrightEnd-to-end browser tests
React Testing LibraryComponent testing

Running Tests

# Unit tests
pnpm test

# Unit tests in watch mode
pnpm test:watch

# E2E tests
pnpm test:e2e

# E2E tests with UI
pnpm test:e2e --ui

# Type check
pnpm build

Test Structure

apps/terra/
├── src/
│   ├── lib/
│   │   └── __tests__/
│   │       └── logic-engine.test.ts
│   └── components/
│       └── __tests__/
│           └── form-renderer.test.tsx
└── e2e/
    ├── form-submission.spec.ts
    └── admin-dashboard.spec.ts

Writing Unit Tests

// src/lib/__tests__/logic-engine.test.ts
import { evaluateLogic } from "../logic-engine";

describe("evaluateLogic", () => {
  it("evaluates simple equality rule", () => {
    const rule = {
      type: "rule",
      fieldId: "status",
      operator: "eq",
      value: "active",
    };

    expect(evaluateLogic(rule, { status: "active" })).toBe(true);
    expect(evaluateLogic(rule, { status: "inactive" })).toBe(false);
  });
});

Writing E2E Tests

// e2e/form-submission.spec.ts
import { test, expect } from "@playwright/test";

test("submits a form", async ({ page }) => {
  await page.goto("/f/test-form");

  await page.fill('[name="full-name"]', "Jane Doe");
  await page.fill('[name="email"]', "jane@example.com");
  await page.click('button[type="submit"]');

  await expect(page.locator("text=Thank you")).toBeVisible();
});