Scaffolds comprehensive testing setup for Next.js applications including Vitest unit tests, React Testing Library component tests, and Playwright E2E flows with accessibility testing via axe-core. This skill should be used when setting up test infrastructure, generating test files, creating test utilities, adding accessibility checks, or configuring testing frameworks for Next.js projects. Trigger terms include setup testing, scaffold tests, vitest, RTL, playwright, e2e tests, component tests, unit tests, accessibility testing, a11y tests, axe-core, test configuration.
Scaffolds complete testing infrastructure for Next.js applications with Vitest, React Testing Library, and Playwright including accessibility testing. Use this when setting up test infrastructure, generating test files, or configuring testing frameworks for Next.js projects.
/plugin marketplace add hopeoverture/worldbuilding-app-skills/plugin install testing-next-stack@worldbuilding-app-skillsThis skill inherits all available tools. When active, it can use any tool Claude has access to.
assets/examples/component-test.tsxassets/examples/e2e-test.tsassets/examples/unit-test.tsassets/playwright.config.tsassets/test-setup.tsassets/vitest.config.tsreferences/a11y-testing.mdscripts/generate_test_deps.pyScaffold complete testing infrastructure for Next.js applications with modern testing tools.
To create a comprehensive testing setup for Next.js applications, use this skill to generate:
Use this skill when:
To understand the project layout, examine:
Generate package.json additions using scripts/generate_test_deps.py:
python scripts/generate_test_deps.py --nextjs-version <version> --typescript
Install required packages:
vitest - Fast unit test runner@testing-library/react - Component testing utilities@testing-library/jest-dom - Custom matchers@testing-library/user-event - User interaction simulation@playwright/test - E2E testing framework@axe-core/playwright - Accessibility testing@vitejs/plugin-react - Vite React pluginjsdom - DOM implementation for VitestCreate configuration files using templates from assets/:
Vitest Configuration (vitest.config.ts):
assets/vitest.config.tsPlaywright Configuration (playwright.config.ts):
assets/playwright.config.tsTest Setup (test/setup.ts):
assets/test-setup.tsGenerate utility functions in test/utils/:
Render Utilities (test/utils/render.tsx):
Mock Factories (test/utils/factories.ts):
Test Helpers (test/utils/helpers.ts):
Create example test files demonstrating patterns:
Unit Test Example (test/unit/example.test.ts):
assets/examples/unit-test.tsComponent Test Example (test/component/example.test.tsx):
assets/examples/component-test.tsxE2E Test Example (test/e2e/example.spec.ts):
assets/examples/e2e-test.tsAdd test scripts to package.json:
{
"scripts": {
"test": "vitest",
"test:ui": "vitest --ui",
"test:coverage": "vitest --coverage",
"test:e2e": "playwright test",
"test:e2e:ui": "playwright test --ui",
"test:e2e:debug": "playwright test --debug"
}
}
To test utility functions and business logic:
import { describe, it, expect } from 'vitest'
import { validateEntityRelationship } from '@/lib/validation'
describe('validateEntityRelationship', () => {
it('validates valid relationship', () => {
const result = validateEntityRelationship({
sourceId: '1',
targetId: '2',
type: 'BELONGS_TO'
})
expect(result.isValid).toBe(true)
})
it('rejects self-referential relationship', () => {
const result = validateEntityRelationship({
sourceId: '1',
targetId: '1',
type: 'BELONGS_TO'
})
expect(result.isValid).toBe(false)
})
})
To test React components:
import { render, screen } from '@/test/utils/render'
import { userEvent } from '@testing-library/user-event'
import { axe } from '@axe-core/playwright'
import EntityCard from '@/components/EntityCard'
describe('EntityCard', () => {
it('renders entity information', () => {
render(<EntityCard entity={mockEntity} />)
expect(screen.getByText(mockEntity.name)).toBeInTheDocument()
})
it('handles edit action', async () => {
const onEdit = vi.fn()
render(<EntityCard entity={mockEntity} onEdit={onEdit} />)
await userEvent.click(screen.getByRole('button', { name: /edit/i }))
expect(onEdit).toHaveBeenCalledWith(mockEntity.id)
})
it('has no accessibility violations', async () => {
const { container } = render(<EntityCard entity={mockEntity} />)
const results = await axe(container)
expect(results.violations).toHaveLength(0)
})
})
To test complete user flows:
import { test, expect } from '@playwright/test'
import { injectAxe, checkA11y } from '@axe-core/playwright'
test('user creates new entity', async ({ page }) => {
await page.goto('/entities')
// Inject axe for accessibility testing
await injectAxe(page)
// Navigate to create form
await page.getByRole('button', { name: /create entity/i }).click()
// Fill form
await page.getByLabel(/name/i).fill('New Character')
await page.getByLabel(/type/i).selectOption('character')
await page.getByLabel(/description/i).fill('A mysterious traveler')
// Submit
await page.getByRole('button', { name: /save/i }).click()
// Verify success
await expect(page.getByText('New Character')).toBeVisible()
// Check accessibility
await checkA11y(page)
})
To add accessibility assertions in component tests:
import { render } from '@/test/utils/render'
import { axe, toHaveNoViolations } from 'jest-axe'
expect.extend(toHaveNoViolations)
it('meets accessibility standards', async () => {
const { container } = render(<MyComponent />)
const results = await axe(container)
expect(results).toHaveNoViolations()
})
To scan entire pages for accessibility issues:
import { test } from '@playwright/test'
import { injectAxe, checkA11y, getViolations } from '@axe-core/playwright'
test('homepage accessibility', async ({ page }) => {
await page.goto('/')
await injectAxe(page)
// Check entire page
await checkA11y(page)
// Or check specific element
await checkA11y(page, '#main-content')
// Or get violations for custom reporting
const violations = await getViolations(page)
expect(violations).toHaveLength(0)
})
To generate code coverage reports, configure Vitest coverage in vitest.config.ts:
export default defineConfig({
test: {
coverage: {
provider: 'v8',
reporter: ['text', 'json', 'html'],
exclude: [
'node_modules/',
'test/',
'**/*.config.{ts,js}',
'**/*.d.ts'
],
thresholds: {
lines: 80,
functions: 80,
branches: 80,
statements: 80
}
}
}
})
Consult the following resources for detailed information:
references/vitest-setup.md - Vitest configuration detailsreferences/rtl-patterns.md - React Testing Library best practicesreferences/playwright-setup.md - Playwright configuration guidereferences/a11y-testing.md - Accessibility testing guidelinesassets/vitest.config.ts - Vitest configuration templateassets/playwright.config.ts - Playwright configuration templateassets/test-setup.ts - Test setup templateassets/examples/ - Example test filesAfter scaffolding the testing infrastructure:
npm install to install dependenciesnpm test to verify Vitest setupnpm run test:e2e to verify Playwright setup