Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

sfnext-testing

БесплатноБез исполняемых скриптовНе проверен

Write and run tests for a Storefront Next project: Vitest + React Testing Library unit tests, route loader/action tests (createLoaderArgs, createTestContext)…

SalesforceCommerceCloudот SalesforceCommerceCloud★ 58 звёзд на GitHub

Об этом скилле

Testing Storefront Next

Three layers, all shipped in your project (see docs/README-TESTS.md, docs/README-STORYBOOK.md, AGENTS.md):

Layer Tool Files Command
Unit and route tests Vitest, jsdom, Testing Library, MSW *.test.ts(x) next to source pnpm test
Component stories Storybook: snapshot (Vitest), interaction and a11y (Playwright/Chromium) <component>/stories/*.stories.tsx pnpm storybook:test --type=...
End to end CodeceptJS + Playwright e2e/ pnpm e2e

Prefer the cheapest layer that proves the behavior: pure logic and loaders in Vitest, rendered states and interactions in stories, cross-page shopper flows in e2e.

Commands

pnpm test                         # all unit tests (vitest run); does NOT collect coverage
pnpm test src/components/footer   # one file or directory
pnpm test:watch                   # watch mode
pnpm test --coverage              # coverage report (thresholds enforced)
pnpm test --ui                    # Vitest UI

pnpm storybook                                        # dev server on :6006
pnpm exec playwright install chromium                 # once, for interaction/a11y runs
pnpm storybook:test --type=snapshot                   # add --update to rewrite snapshots
pnpm storybook:test --type=interaction                # play() functions in real Chromium
pnpm storybook:test --type=a11y                       # axe checks
pnpm storybook:test --type=snapshot --stories=footer  # narrow to matching story paths

Add --static (optionally --reuse-build after pnpm storybook:build) to run interaction or a11y against a static build. --coverage with snapshot generates story tests and reports story coverage.

Coverage thresholds live inline in vitest.config.ts (thresholds), and src/components/ui/**, stories, snapshot fixtures and __mocks__ are excluded from coverage. Do not chase 100%.

Unit test

import { render, screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import { AllProvidersWrapper } from '@/test-utils/context-provider';
import MyThing from './index';

describe('MyThing', () => {
    it('renders the label', () => {
        render(<MyThing label="Hello" />, { wrapper: AllProvidersWrapper });
        expect(screen.getByText('Hello')).toBeInTheDocument();
    });
});

vitest.setup.ts already provides jest-dom matchers, i18next (en-GB), window.__APP_CONFIG__, a global mock of @/hooks/use-analytics, and a 10s async-util timeout; do not re-add them. Helpers, wrappers and the analytics caveat: references/UNIT-AND-ROUTE-TESTS.md.

Route loader / action test

import { describe, expect, it, vi } from 'vitest';
import { createLoaderArgs, createTestContext } from '@/lib/test-utils';
import { loader } from './resource.basket-products';

vi.mock('@/lib/api-clients.server', () => ({ createApiClients: vi.fn() }));

it('returns data', async () => {
    const context = createTestContext({ authSession: { userType: 'guest' } });
    const args = createLoaderArgs(new Request('http://localhost/x'), context, {
        params: {},
        pattern: '/' as never,
    });
    const result = await loader(args);
    expect(result).toBeDefined();
});

createActionArgs is the action twin and expectStatus(result, 400) asserts data() statuses. Mock @/lib/api-clients.server (SCAPI) at the module boundary, or use MSW for HTTP-level tests. See storefront-next:sfnext-data-fetching for the loader patterns under test.

Stories

Stories live in a stories/ subfolder next to the component (required; coverage tooling only matches there):

src/components/footer/
├── index.tsx
├── index.test.tsx
└── stories/
    ├── index.stories.tsx
    ├── footer-snapshot.tsx      # snapshot fixture, only where a snapshot test exists
    └── __snapshots__/
import type { Meta, StoryObj } from '@storybook/react-vite';
import { expect, within } from 'storybook/test';
import { waitForStorybookReady } from '@storybook/test-utils';
import { mockProductSearchItem } from '@/components/__mocks__/product-search-hit-data';
import ProductTile from '../index';

const meta: Meta<typeof ProductTile> = {
    title: 'Products/Product Tile', // Domain/Component from the fixed sidebar groups
    component: ProductTile,
    tags: ['autodocs', 'interaction'],
};
export default meta;
type Story = StoryObj<typeof meta>;

export const Default: Story = {
    args: { product: mockProductSearchItem },
    play: async ({ canvasElement }) => {
        await waitForStorybookReady(canvasElement);
        await expect(within(canvasElement).getAllByRole('link')[0]).toBeInTheDocument();
    },
};

Rules of thumb:

  • Every story is already wrapped by a global decorator (memory router + config, site, i18n, auth, basket providers). Do not add your own ConfigProvider. If you truly need one, import it from `@salesforce/
Полный SKILL.md на GitHub

Установить sfnext-testing в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

evals/trigger-evals.jsonreferences/E2E.mdreferences/STORYBOOK-PATTERNS.mdreferences/UNIT-AND-ROUTE-TESTS.md

FAQ

Что делает скилл sfnext-testing?

Write and run tests for a Storefront Next project: Vitest + React Testing Library unit tests, route loader/action tests (createLoaderArgs, createTestContext), Storybook stories with snapshot, interaction (play) and a11y runs, and a pointer to the CodeceptJS/Playwright e2e suite. Use for "write a test for this component/loader", "add a story", pnpm test, pnpm storybook:test --type=snapshot|interaction|a11y, coverage thresholds, routeLoaderData / scapiMock / mockRoutes story parameters, MSW mocking, fixtures in @/components/__mocks__, failing snapshot updates, or pnpm e2e. Do not use for lint, typecheck, format, bundle-size or Lighthouse gates (use `storefront-next:sfnext-quality-gates`), accessibility rules and fixes (use `storefront-next:sfnext-accessibility`), or translations (use `storefront-next:sfnext-i18n`).

Как установить скилл sfnext-testing?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл sfnext-testing запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить sfnext-testing с