studio-testing

작성자: supabase

Supabase Studio의 테스트 전략. 테스트를 작성하거나 결정할 때 사용합니다.

npx skills add https://github.com/supabase/supabase --skill studio-testing

Studio Testing Strategy

How to write and structure tests for apps/studio/. The core principle: push logic out of React components into pure utility functions, then test those functions exhaustively. Only use component tests for complex UI interactions. Use E2E tests for features shared between self-hosted and platform.

When to Apply

Reference these guidelines when:

  • Writing new tests for Studio code
  • Deciding which type of test to write (unit, component, E2E)
  • Extracting logic from a component to make it testable
  • Reviewing whether test coverage is sufficient
  • Adding a new feature that needs tests

Rule Categories by Priority

PriorityCategoryImpactPrefix
1Logic ExtractionCRITICALtesting-
2Test CoverageCRITICALtesting-
3Component TestsHIGHtesting-
4E2E TestsHIGHtesting-

Quick Reference

1. Logic Extraction (CRITICAL)

  • testing-extract-logic - Remove logic from components into .utils.ts files as pure functions: args in, return out

2. Test Coverage (CRITICAL)

  • testing-exhaustive-permutations - Test every permutation of utility functions: happy path, malformed input, empty values, edge cases

3. Component Tests (HIGH)

  • testing-component-tests-ui-only - Only write component tests for complex UI interaction logic, not business logic

4. E2E Tests (HIGH)

  • testing-e2e-shared-features - Write E2E tests for features used in both self-hosted and platform; cover clicks AND keyboard shortcuts

Decision Tree: Which Test Type?

Is the logic a pure transformation (parse, format, validate, compute)?
  YES -> Extract to .utils.ts, write unit test with vitest
  NO  -> Does the feature involve complex UI interactions?
           YES -> Is it used in both self-hosted and platform?
                    YES -> Write E2E test in e2e/studio/features/
                    NO  -> Write component test with customRender
           NO  -> Can you extract the logic to make it pure?
                    YES -> Do that, then unit test it
                    NO  -> Write a component test

1. Extract Logic Into Utility Files (CRITICAL)

Remove as much logic from components as possible. Put it in co-located .utils.ts files as pure functions: arguments in, return value out.

File naming:

  • Utility: ComponentName.utils.ts next to the component
  • Test: tests/components/.../ComponentName.utils.test.ts mirroring the source path
// ❌ Logic buried in component — hard to test without rendering
function TaxIdForm({ taxIdValue, taxIdName }: Props) {
  const handleSubmit = () => {
    const taxId = TAX_IDS.find((t) => t.name === taxIdName)
    let sanitized = taxIdValue
    if (taxId?.vatPrefix && !taxIdValue.startsWith(taxId.vatPrefix)) {
      sanitized = taxId.vatPrefix + taxIdValue
    }
    submitToApi(sanitized)
  }
  return <form onSubmit={handleSubmit}>...</form>
}

// ✅ Logic extracted to .utils.ts — trivially testable
// TaxID.utils.ts
export function sanitizeTaxIdValue({ value, name }: { value: string; name: string }): string {
  const taxId = TAX_IDS.find((t) => t.name === name)
  if (taxId?.vatPrefix && !value.startsWith(taxId.vatPrefix)) {
    return taxId.vatPrefix + value
  }
  return value
}

// TaxIdForm.tsx — thin shell
const handleSubmit = () => {
  const sanitized = sanitizeTaxIdValue({ value: taxIdValue, name: taxIdName })
  submitToApi(sanitized)
}

2. Test Every Permutation (CRITICAL)

Once logic is extracted, test exhaustively. Every code path needs a test:

  • Valid inputs (happy path for each branch)
  • Invalid / malformed inputs
  • Empty values, null values, missing fields
  • Edge cases (timestamps with colons, special characters, boundary values)
// ❌ Only happy path
test('parses a filter', () => {
  expect(formatFilterURLParams('id:gte:20')).toStrictEqual({ column: 'id', operator: 'gte', value: '20' })
})

// ✅ Every permutation
test('parses valid filter', () => { ... })
test('handles timestamp with colons in value', () => { ... })
test('rejects malformed filter with missing parts', () => { ... })
test('rejects unrecognized operator', () => { ... })
test('allows empty filter value', () => { ... })

3. Component Tests for Complex UI Only (HIGH)

Only write component tests when there is complex UI interaction logic that cannot be captured by testing utility functions alone.

Valid reasons: conditional rendering from user interaction sequences, popover open/close with keyboard/mouse, multi-step form transitions.

Not valid: testing a calculation or transformation that happens to live in a component — extract to .utils.ts and unit test instead.

// Studio component test conventions
import { fireEvent } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { customRender } from 'tests/lib/custom-render' // always use customRender, not raw render
import { addAPIMock } from 'tests/lib/msw' // API mocking in beforeEach

4. E2E Tests for Shared Features (HIGH)

If a feature exists in both self-hosted and platform, create an E2E test. Cover mouse clicks AND keyboard shortcuts (Tab, Enter, Escape, Arrow keys).

Extract reusable interactions into e2e/studio/utils/*-helpers.ts. Use try/finally for resource cleanup. For E2E execution details, see the studio-e2e-tests skill.

Codebase References

WhatWhere
Util test examplesapps/studio/tests/components/Grid/Grid.utils.test.ts, apps/studio/tests/components/Billing/TaxID.utils.test.ts, apps/studio/tests/components/Editor/SpreadsheetImport.utils.test.ts
Component test examplesapps/studio/tests/features/logs/LogsFilterPopover.test.tsx, apps/studio/tests/components/CopyButton.test.tsx
E2E test examplee2e/studio/features/filter-bar.spec.ts
E2E helpers patterne2e/studio/utils/filter-bar-helpers.ts
Custom renderapps/studio/tests/lib/custom-render.tsx
MSW mock setupapps/studio/tests/lib/msw.ts (addAPIMock)
Test READMEapps/studio/tests/README.md
Vitest configapps/studio/vitest.config.ts
Related skillsstudio-e2e-tests (running E2E), vitest (API reference), vercel-composition-patterns (component architecture)

supabase의 다른 스킬

studio-e2e-tests
supabase
Supabase Studio용 Playwright E2E 테스트를 작성하고 실행합니다. 요청 시 사용하세요.
official
vitest
supabase
Vite 기반의 Jest 호환 API를 갖춘 빠른 단위 테스트 프레임워크입니다. 테스트 작성, 모킹, 커버리지 구성 또는 테스트 작업 시 사용하세요.
official
skill-creator
supabase
모듈형 스킬을 생성하기 위한 종합 가이드로, 전문 지식과 워크플로우를 통해 Claude의 기능을 확장합니다. 스킬은 YAML 프론트매터와 마크다운 지침이 포함된 필수 SKILL.md 파일과, 목적별로 구성되고 컨텍스트를 절약하기 위해 점진적으로 로드되는 선택적 번들 리소스(스크립트, 참조 자료, 에셋)로 구성됩니다. 구체적인 사용 예시를 중심으로 스킬을 설계하고, 결정적 작업을 위한 재사용 가능한 스크립트, 도메인 지식을 위한 참조 파일, 에셋을 식별합니다...
official
supabase
supabase
Supabase와 관련된 모든 작업을 수행할 때 사용합니다. 트리거: Supabase 제품(데이터베이스, 인증, 엣지 함수, 실시간, 스토리지, 벡터, 크론, 큐); 클라이언트…
official
supabase-server
supabase
Supabase를 사용한 서버 측 코드 작성 시 — Edge Functions, Hono 앱, 웹훅 핸들러, 또는 Supabase 인증 및 클라이언트 생성이 필요한 모든 백엔드에서 사용합니다.
official
clickhouse-logs-queries
supabase
Write, review, and migrate Supabase logs queries against the ClickHouse-backed `logs` table (the `logs.all.otel` analytics endpoint). Use this whenever a task…
official
dev-toolbar-review
supabase
PR을 검토할 때 사용하세요. packages/dev-tools/, packages/common/posthog-client.ts 파일을 다루는 경우에 해당합니다.
official
e2e-studio-tests
supabase
Studio 앱에서 e2e 테스트를 실행합니다. e2e 테스트 실행, 스튜디오 테스트 실행, Playwright 테스트 실행, 또는 기능 테스트를 요청받았을 때 사용하세요.
official