| name | senior-qa |
| description | This skill should be used when the user asks to "generate tests", "write unit tests", "analyze test coverage", "scaffold E2E tests", "set up Playwright", "configure Jest", "implement testing patterns", or "improve test quality". Use for React/Next.js testing with Jest, React Testing Library, and Playwright. |
Senior QA Engineer
Test automation, coverage analysis, and quality assurance patterns for React and Next.js applications.
Core rules
- Before adding or revising tests for a substantial phase, first create or update a testing codemap that maps stories to test types, coverage targets, and validation paths.
- Use the testing codemap to separate unit, integration, E2E, and manual verification responsibilities before writing test code.
- Keep the codemap aligned with real implementation boundaries so coverage reports and phase reviews use the same test model.
Repository override for this project
- This repository only automates basic unit tests during the
testing phase.
- Do not add or require automated integration tests or automated E2E tests as a phase gate for this repo.
- Integration testing is handled manually by the user and should be documented as manual verification only.
- Do not add or require automated smoke tests as a phase gate for this repo.
- When examples in this skill mention Playwright, smoke coverage, full E2E setup, or CI-enforced integration coverage, treat them as optional references, not repository requirements.
Table of Contents
Quick Start
python scripts/test_suite_generator.py src/components/ --output __tests__/
python scripts/coverage_analyzer.py coverage/coverage-final.json --threshold 80
python scripts/e2e_test_scaffolder.py src/app/ --output e2e/
Tools Overview
1. Test Suite Generator
Scans React/TypeScript components and generates Jest + React Testing Library test stubs with proper structure.
Input: Source directory containing React components
Output: Test files with describe blocks, render tests, interaction tests
Usage:
python scripts/test_suite_generator.py src/components/ --output __tests__/
python scripts/test_suite_generator.py src/ --output __tests__/ --include-a11y
python scripts/test_suite_generator.py src/ --template custom-template.tsx
Supported Patterns:
- Functional components with hooks
- Components with Context providers
- Components with data fetching
- Form components with validation
2. Coverage Analyzer
Parses Jest/Istanbul coverage reports and identifies gaps, uncovered branches, and provides actionable recommendations.
Input: Coverage report (JSON or LCOV format)
Output: Coverage analysis with recommendations
Usage:
python scripts/coverage_analyzer.py coverage/coverage-final.json
python scripts/coverage_analyzer.py coverage/ --threshold 80 --strict
python scripts/coverage_analyzer.py coverage/ --format html --output report.html
3. E2E Test Scaffolder
Scans Next.js pages/app directory and generates Playwright test files with common interactions.
Input: Next.js pages or app directory
Output: Playwright test files organized by route
Usage:
python scripts/e2e_test_scaffolder.py src/app/ --output e2e/
python scripts/e2e_test_scaffolder.py src/app/ --output e2e/ --include-pom
python scripts/e2e_test_scaffolder.py src/app/ --routes "/login,/dashboard,/checkout"
QA Workflows
Unit Test Generation Workflow
Use when setting up tests for new or existing React components.
Step 1: Scan project for untested components
python scripts/test_suite_generator.py src/components/ --scan-only
Step 2: Generate test stubs
python scripts/test_suite_generator.py src/components/ --output __tests__/
Step 3: Review and customize generated tests
import { render, screen, fireEvent } from '@testing-library/react';
import { Button } from '../src/components/Button';
describe('Button', () => {
it('renders with label', () => {
render(<Button>Click me</Button>);
expect(screen.getByRole('button', { name: /click me/i })).toBeInTheDocument();
});
it('calls onClick when clicked', () => {
const handleClick = jest.fn();
render(<Button onClick={handleClick}>Click</Button>);
fireEvent.click(screen.getByRole('button'));
expect(handleClick).toHaveBeenCalledTimes(1);
});
});
Step 4: Run tests and check coverage
npm test -- --coverage
python scripts/coverage_analyzer.py coverage/coverage-final.json
Coverage Analysis Workflow
Use when improving test coverage or preparing for release.
Step 1: Generate coverage report
npm test -- --coverage --coverageReporters=json
Step 2: Analyze coverage gaps
python scripts/coverage_analyzer.py coverage/coverage-final.json --threshold 80
Step 3: Identify critical paths
python scripts/coverage_analyzer.py coverage/ --critical-paths
Step 4: Generate missing test stubs
python scripts/test_suite_generator.py src/ --uncovered-only --output __tests__/
Step 5: Verify improvement
npm test -- --coverage
python scripts/coverage_analyzer.py coverage/ --compare previous-coverage.json
E2E Test Setup Workflow
Use when setting up Playwright for a Next.js project.
Step 1: Initialize Playwright (if not installed)
npm init playwright@latest
Step 2: Scaffold E2E tests from routes
python scripts/e2e_test_scaffolder.py src/app/ --output e2e/
Step 3: Configure authentication fixtures
import { test as base } from '@playwright/test';
export const test = base.extend({
authenticatedPage: async ({ page }, use) => {
await page.goto('/login');
await page.fill('[name="email"]', 'test@example.com');
await page.fill('[name="password"]', 'password');
await page.click('button[type="submit"]');
await page.waitForURL('/dashboard');
await use(page);
},
});
Step 4: Run E2E tests
npx playwright test
npx playwright show-report
Step 5: Add to CI pipeline
- name: Run E2E tests
run: npx playwright test
- name: Upload report
uses: actions/upload-artifact@v3
with:
name: playwright-report
path: playwright-report/
Reference Documentation
| File | Contains | Use When |
|---|
references/testing_strategies.md | Test pyramid, testing types, coverage targets, CI/CD integration | Designing test strategy |
references/test_automation_patterns.md | Page Object Model, mocking (MSW), fixtures, async patterns | Writing test code |
references/qa_best_practices.md | Testable code, flaky tests, debugging, quality metrics | Improving test quality |
Common Patterns Quick Reference
React Testing Library Queries
screen.getByRole('button', { name: /submit/i })
screen.getByLabelText(/email/i)
screen.getByPlaceholderText(/search/i)
screen.getByTestId('custom-element')
Async Testing
await screen.findByText(/loaded/i);
await waitForElementToBeRemoved(() => screen.queryByText(/loading/i));
await waitFor(() => {
expect(mockFn).toHaveBeenCalled();
});
Mocking with MSW
import { rest } from 'msw';
import { setupServer } from 'msw/node';
const server = setupServer(
rest.get('/api/users', (req, res, ctx) => {
return res(ctx.json([{ id: 1, name: 'John' }]));
})
);
beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());
Playwright Locators
page.getByRole('button', { name: 'Submit' })
page.getByLabel('Email')
page.getByText('Welcome')
page.getByRole('listitem').filter({ hasText: 'Product' })
Coverage Thresholds (jest.config.js)
module.exports = {
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80,
},
},
};
Common Commands
npm test
npm test -- --watch
npm test -- --coverage
npm test -- Button.test.tsx
npx playwright test
npx playwright test --ui
npx playwright test --debug
npx playwright codegen
npm test -- --coverage --coverageReporters=lcov,json
python scripts/coverage_analyzer.py coverage/coverage-final.json