Agent skill

test-writer

Create and maintain tests for the Raamattu Nyt monorepo using Vitest and React Testing Library. Supports app-specific and package-specific test configurations across the monorepo. Use when: - Writing new tests for hooks, components, or utility functions - Analyzing recent git commits to identify code needing tests - Reviewing existing tests for correctness and coverage - Creating mocks for Supabase, auth, or other dependencies - Debugging test failures or flaky tests Triggers: "write tests", "test this", "add tests", "need tests for", "analyze test coverage", "fix failing tests", "mock this", "review tests", "evolution tests", "migration-safe tests", "idea-machina tests"

Stars 0
Forks 0

Install this agent skill to your Project

npx add-skill https://github.com/Spectaculous-Code/raamattu-nyt/tree/main/.claude/skills/test-writer

SKILL.md

Test Writer

Write and maintain tests for the Raamattu Nyt monorepo.

Monorepo Test Architecture

Determine workspace first. Before writing or running tests, identify which workspace the code belongs to:

Workspace Vitest Config Test Command Path Aliases
apps/raamattu-nyt vite.config.ts (test section) cd apps/raamattu-nyt && npx vitest run @/./src, @shared-auth, @ui, etc.
packages/shared-i18n vitest.config.ts cd packages/shared-i18n && npx vitest run @/integrations/supabase/client → raamattu-nyt client
packages/* (others) None yet Must create vitest.config.ts first Varies per package

Root npm test only runs apps/raamattu-nyt tests.

Running Tests

bash
# ALWAYS cd into the workspace directory first
cd apps/raamattu-nyt && npx vitest run src/hooks/useMyHook.test.ts

# For packages with vitest config
cd packages/shared-i18n && npx vitest run src/myUtil.test.ts

# Run all raamattu-nyt tests with coverage
cd apps/raamattu-nyt && npx vitest run --coverage

NEVER run from monorepo root with a path — include patterns are relative to config location. See references/learnings.md.

Test File Conventions

  • Place tests adjacent to source: useHook.tsuseHook.test.ts
  • Use .test.ts for pure logic, .test.tsx for React components/hooks
  • Name: describe("ComponentName") or describe("hookName")

Standard Test Structure

typescript
import { describe, expect, it, vi, beforeEach } from "vitest";

// Mocks BEFORE imports (hoisted)
vi.mock("@/integrations/supabase/client", () => ({
  supabase: { rpc: vi.fn() }
}));

// Import module under test AFTER mocks
import { myFunction } from "./myModule";

describe("myFunction", () => {
  beforeEach(() => {
    vi.clearAllMocks();
  });

  it("does expected behavior", () => {
    expect(myFunction()).toBe(expected);
  });
});

Hook Testing Pattern

typescript
import { renderHook, waitFor } from "@testing-library/react";

const wrapper = ({ children }) => (
  <AuthProvider>{children}</AuthProvider>
);

it("returns initial state", () => {
  const { result } = renderHook(() => useMyHook(), { wrapper });
  expect(result.current.loading).toBe(true);
});

it("updates on async action", async () => {
  const { result } = renderHook(() => useMyHook(), { wrapper });
  await waitFor(() => {
    expect(result.current.data).toBeDefined();
  });
});

Common Mocks

See references/mocks.md for reusable mock patterns:

  • Supabase client (RPC, auth, schema queries)
  • useAuth hook
  • React Query
  • localStorage

Adding Tests to a New Package

When a package (e.g. packages/shared-recording) needs tests for the first time:

  1. Create vitest.config.ts in the package root:
typescript
/// <reference types="vitest" />
import path from "node:path";
import { defineConfig } from "vitest/config";

export default defineConfig({
  test: {
    globals: true,
    environment: "jsdom",
    include: ["src/**/*.{test,spec}.{ts,tsx}"],
  },
  resolve: {
    alias: {
      // Add aliases matching the package's imports
      "@/integrations/supabase/client": path.resolve(
        __dirname, "../../apps/raamattu-nyt/src/integrations/supabase/client.ts"
      ),
    },
  },
});
  1. Add test script to package's package.json:
json
{ "scripts": { "test": "vitest run" } }
  1. Add test setup if using React Testing Library — create src/test/setup.ts:
typescript
import "@testing-library/jest-dom/vitest";

And add setupFiles: ["./src/test/setup.ts"] to the vitest config.

Workflow

  1. Identify workspace — determine which app/package the code belongs to
  2. Check existing testsGlob pattern: <workspace>/**/*.test.{ts,tsx}
  3. Check vitest config — ensure the workspace has one; create if not
  4. Write tests — happy path, errors, edge cases, loading states
  5. Run from workspace dircd <workspace> && npx vitest run src/path/to/file.test.ts

Test Quality Checklist

  • Tests are independent (no shared state between tests)
  • Mocks are cleared in beforeEach
  • Async operations use waitFor not arbitrary delays
  • Error scenarios are tested
  • Edge cases covered (null, empty, boundary values)
  • Tests run from correct workspace directory

IdeaMachina Evolution Tests

For IdeaMachina evolution features (sparks, cores, direction, force), write migration-safe tests that survive the Zustand→Supabase migration.

See references/idea-machina-migration-safe.md for:

  • Data Port Pattern — abstract the store behind an interface so tests swap Zustand↔Supabase with one import change
  • Test fixturesmakeSpark(), makeCore(), makeDirection() factories
  • Component tests — test rendered UI, not store internals
  • Pure logic tests — stage computation, core health, spark filtering (always migration-proof)
  • What NOT to test — avoid persist config, localStorage keys, store version migrations

Quick rule: If a test imports useProjectEvolutionStore directly, consider whether it can test through rendered UI or the data port instead.

Related Skills

Situation Delegate To
Find code to test code-wizard
Debug test failures systematic-debugging
CI test failures ci-doctor
Lint errors in tests lint-fixer

Expand your agent's capabilities with these related and highly-rated skills.

Spectaculous-Code/raamattu-nyt

docs-updater

Expert assistant for keeping documentation synchronized with code changes in the KR92 Bible Voice project. Use when updating API docs, maintaining architecture diagrams, syncing README, updating CLAUDE.MD, or generating documentation from code.

0 0
Explore
Spectaculous-Code/raamattu-nyt

ai-prompt-manager

Expert assistant for managing AI prompts, features, and configuration in the KR92 Bible Voice AI system. Use when creating AI prompts, configuring AI features, managing prompt versions, setting up AI bindings, or working with AI pricing and models.

0 0
Explore
Spectaculous-Code/raamattu-nyt

performance-auditor

Expert assistant for monitoring and optimizing performance in the KR92 Bible Voice project. Use when analyzing query performance, optimizing database indexes, reviewing React Query caching, monitoring AI call costs, or identifying N+1 queries.

0 0
Explore
Spectaculous-Code/raamattu-nyt

edge-function-generator

Expert assistant for creating and maintaining Supabase Edge Functions for the KR92 Bible Voice project. Use when creating Edge Functions, setting up CORS, integrating shared modules, adding JWT validation, or configuring environment variables.

0 0
Explore
Spectaculous-Code/raamattu-nyt

admin-panel-builder

Expert assistant for creating and maintaining admin panel pages in the KR92 Bible Voice project. Use when creating admin pages, building admin components, integrating with admin navigation, or adding admin features.

0 0
Explore
Spectaculous-Code/raamattu-nyt

lint-fixer

Expert assistant for analyzing and fixing linting and formatting issues in the KR92 Bible Voice project using Biome and TypeScript. Use when fixing lint errors, resolving TypeScript issues, applying code formatting, or reviewing code quality.

0 0
Explore

Didn't find tool you were looking for?

Be as detailed as possible for better results