sfnext-testing
Write tests for Storefront Next using Vitest unit tests, Storybook stories, interaction tests, snapshot tests, and accessibility tests. Use when writing component tests, creating Storybook stories, running test coverage, or setting up test utilities. Covers testing-library patterns, play functions, and coverage thresholds.
What this skill does
# Testing Skill
This skill covers testing patterns in Storefront Next — Vitest for unit tests and Storybook for component stories, interaction tests, and accessibility validation.
## Unit Tests (Vitest)
Test files live alongside source files with `.test.ts` or `.test.tsx` extension:
```typescript
// src/components/product-card/product-card.test.tsx
import { describe, it, expect, vi } from 'vitest';
import { render, screen } from '@testing-library/react';
import { ProductCard } from './product-card';
import { mockProduct } from '@/test-utils/mocks';
describe('ProductCard', () => {
it('renders product name', () => {
render(<ProductCard product={mockProduct} />);
expect(screen.getByText(mockProduct.productName)).toBeInTheDocument();
});
});
```
### Test Utilities
Shared utilities in `src/test-utils/`:
- `config.ts` — Mock configuration objects and ConfigProvider wrappers
- `context-provider-utils.ts` — Context provider helpers for testing
- `context-provider.tsx` — Test context providers
### Running Tests
```bash
pnpm test # Run all tests with coverage
pnpm test:ui # Open interactive Vitest UI
pnpm test:watch # Watch mode (re-run on changes)
```
### Coverage Requirements
Thresholds enforced in `vitest.thresholds.ts`:
| Metric | Minimum |
|--------|---------|
| Lines | 73% |
| Statements | 73% |
| Functions | 72% |
| Branches | 67% |
### Testing Libraries
- `@testing-library/react` — Component rendering and queries
- `@testing-library/jest-dom` — Custom DOM matchers (`toBeInTheDocument`, etc.)
- `@testing-library/user-event` — User interaction simulation
- `@vitest/coverage-v8` — Code coverage
- `@vitest/ui` — Interactive test UI
## Storybook
Every reusable component should have a `.stories.tsx` file.
### Story Structure
```typescript
// src/components/product-card/product-card.stories.tsx
import type { Meta, StoryObj } from '@storybook/react-vite';
import { within, expect } from 'storybook/test';
import { waitForStorybookReady } from '@storybook/test-utils';
import { ProductCard } from './product-card';
import { ConfigProvider } from '@/config/context';
import { mockConfig } from '@/test-utils/config';
import { mockProduct } from '@/test-utils/mocks';
const meta: Meta<typeof ProductCard> = {
title: 'Components/ProductCard',
component: ProductCard,
tags: ['autodocs', 'interaction'],
decorators: [
(Story) => (
<ConfigProvider config={mockConfig}>
<Story />
</ConfigProvider>
),
],
};
export default meta;
type Story = StoryObj<typeof ProductCard>;
export const Default: Story = {
args: {
product: mockProduct,
},
play: async ({ canvasElement }) => {
await waitForStorybookReady(canvasElement);
const canvas = within(canvasElement);
await expect(canvas.getByText(mockProduct.productName)).toBeInTheDocument();
},
};
```
See [Storybook Patterns Reference](references/STORYBOOK-PATTERNS.md) for advanced patterns.
### Storybook Commands
```bash
pnpm storybook # Dev server (port 6006)
pnpm build-storybook # Build static Storybook
pnpm test-storybook:snapshot # Snapshot tests
pnpm test-storybook:snapshot:update # Update snapshots
pnpm test-storybook:interaction # Interaction tests
pnpm test-storybook:a11y # Accessibility tests
pnpm generate:story-tests:coverage # Story coverage report
```
### Story Tags
| Tag | Purpose |
|-----|---------|
| `autodocs` | Enable automatic documentation |
| `interaction` | Include in interaction test runs |
| `skip-a11y` | Exclude from a11y tests (use sparingly) |
## Route Testing
Mock loaders, actions, and React Router context:
```typescript
// src/routes/_app.product.$productId.test.tsx
import { describe, test, expect, vi } from 'vitest';
import { render } from '@testing-library/react';
vi.mock('@/components/product-view', () => ({
default: ({ product }: any) => (
<div data-testid="product-view">
<div data-testid="product-name">{product?.name}</div>
</div>
),
}));
```
## Test Organization
```
src/
├── components/
│ ├── product-card/
│ │ ├── index.tsx # Component
│ │ ├── index.test.tsx # Unit tests
│ │ └── stories/
│ │ └── index.stories.tsx # Stories
├── routes/
│ ├── _app.product.$productId.tsx
│ └── _app.product.$productId.test.tsx
└── test-utils/ # Shared utilities
├── config.ts
└── context-provider-utils.ts
```
## Best Practices
1. **Colocate tests** — Keep test files next to source files
2. **Use test utilities** — Leverage `@/test-utils` for mocks and providers
3. **Mock external dependencies** — Use `vi.mock()` for API clients and context
4. **Test interactions** — Use `@testing-library/user-event` and Storybook play functions
5. **Test accessibility** — Use Storybook a11y addon
6. **Multiple story variants** — Create stories for Default, Loading, Error states
7. **Use viewport toolbar** — Test responsive layouts via Storybook's built-in viewport toolbar
## Related Skills
- `storefront-next:sfnext-components` - Component patterns that need testing
- `storefront-next:sfnext-data-fetching` - Mocking loaders and actions in tests
- `storefront-next:sfnext-page-designer` - Testing Page Designer components
## Reference Documentation
- [Storybook Patterns Reference](references/STORYBOOK-PATTERNS.md) - Advanced story patterns and testing
Related in Design
contribute
IncludedLocal-only OSS contribution command center. Auto-refreshes the user's in-flight PR and issue state on invoke so conversations start with full context — no need to brief Claude on what's in flight. Helps the user find issues to contribute to on GitHub, builds per-repo dossiers of what each upstream expects (CLA, DCO, branch convention, AI policy, draft-first, review bots, issue templates), runs deterministic gates before any external action so AI-assisted contributions don't reach maintainers as slop. State is markdown-only: candidate files at ~/.contribute-system/candidates/, repo dossiers at ~/.contribute-system/research/, append-only event log at ~/.contribute-system/log.jsonl. No database, no cloud calls. Use when the user asks about their PRs / issues / contributions, wants to find new work to take on, claim an issue, build/refresh a repo's dossier, or draft a Design Issue or PR. Trigger with "/contribute", "what's my PR status", "find a contribution", "claim issue X", "draft a Design Issue for Y", "refresh dossier for Z".
architectural-analysis
IncludedUser-triggered deep architectural analysis of a codebase or scoped subtree across eight modes — information architecture, data flow, integration points, UI surfaces, interaction patterns, data model, control flow, and failure modes. This skill should be used when the user asks to "diagram this codebase," "map the architecture," "show the data flow," "give me an ERD," "trace control flow," "find the integration points," "verify the layout pattern," "audit the UX architecture," or any similar request whose primary deliverable is mermaid diagrams plus cited reports under docs/architecture/. Dispatches haiku/sonnet sub-agents in parallel for per-mode exploration, then verifies every citation mechanically before any node lands in a diagram. Not for one-off prose explanations of code (use code-explanation) or for high-level system design from scratch (use system-design).
mcp
IncludedModel Context Protocol (MCP) server development and tool management. Languages: Python, TypeScript. Capabilities: build MCP servers, integrate external APIs, discover/execute MCP tools, manage multi-server configs, design agent-centric tools. Actions: create, build, integrate, discover, execute, configure MCP servers/tools. Keywords: MCP, Model Context Protocol, MCP server, MCP tool, stdio transport, SSE transport, tool discovery, resource provider, prompt template, external API integration, Gemini CLI MCP, Claude MCP, agent tools, tool execution, server config. Use when: building MCP servers, integrating external APIs as MCP tools, discovering available MCP tools, executing MCP capabilities, configuring multi-server setups, designing tools for AI agents.
react-native-skia
IncludedDesign, build, debug, and optimise high-polish animated graphics in React Native or Expo using @shopify/react-native-skia, Reanimated, and Gesture Handler. Use when the user wants canvas-driven UI, shaders, paths, rich text, image filters, sprite fields, Skottie, video frames, snapshots, web CanvasKit setup, or performance tuning for custom motion-heavy elements such as loaders, hero art, cards, charts, progress indicators, particle systems, or gesture-driven surfaces. Also use when the user asks for fluid, glow, glass, blob, parallax, 60fps/120fps, or GPU-friendly animated effects in React Native, even if they do not explicitly say "Skia". Do not use for ordinary form/layout work with standard views.
plaid
IncludedProduct Led AI Development — guides founders from idea to launched product. Six capabilities: Idea (discover a product idea), Validate (pressure-test the idea against fatal flaws, problem reality, competition, and 2-week MVP feasibility), Plan (vision intake + document generation), Design (translate image references into a design.md spec), Launch (go-to-market strategy), and Build (roadmap execution). Use when someone says "PLAID", "plaid idea", "help me find an idea", "product idea", "idea from my business", "idea from my expertise", "plaid validate", "validate my idea", "pressure-test", "is this idea good", "find fatal flaws", "validate the problem", "plan a product", "define my vision", "generate a PRD", "product strategy", "plaid design", "design from image", "translate image to design", "create design.md", "extract design tokens", "plaid launch", "go-to-market", "launch plan", "GTM strategy", "launch playbook", "plaid build", "build the app", "start building", or "execute the roadmap".
nextjs-framer-motion-animations
IncludedAdds production-safe Motion for React or Framer Motion animations to Next.js apps, including reveal, hover and tap micro-interactions, whileInView, stagger, AnimatePresence, layout and layoutId transitions, reorder, scroll-linked UI, and lightweight route-content transitions. Use when the user asks to add, refactor, or debug Motion or Framer Motion in App Router or Pages Router codebases, especially around server/client boundaries, reduced motion, LazyMotion, bundle size, hydration, or route transitions. Avoid for GSAP-style timelines, WebGL or 3D scenes, heavy scroll storytelling, or CSS-only effects unless Motion is explicitly requested.