Testing
Skill PIXARTSeu/Synapse/packages/codegraph/data/skill/testing
Testing knowledge base - Vitest, Playwright, Testing Library, accessibility testing. Use when setting up a test suite, writing unit/E2E tests, implementing visual regression tests, or testing accessibility.From its SKILL.md
npx -y skills add PIXARTSeu/Synapse --skill testingAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
- 8 stars8 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
3.7 KB, 928 tokens by cl100k_base, as published. Nobody here has run it
Testing Knowledge Base
Vitest Setup
npm install -D vitest @testing-library/react @testing-library/jest-dom jsdom
// vitest.config.ts
import { defineConfig } from 'vitest/config';
import react from '@vitejs/plugin-react';
export default defineConfig({
plugins: [react()],
test: {
globals: true,
environment: 'jsdom',
setupFiles: './src/test/setup.ts',
coverage: {
provider: 'v8',
thresholds: { global: { lines: 80 } },
},
},
});
// src/test/setup.ts
import '@testing-library/jest-dom/vitest';
import { cleanup } from '@testing-library/react';
import { afterEach } from 'vitest';
afterEach(() => cleanup());
Unit Tests
// utils.test.ts
import { describe, it, expect } from 'vitest';
import { formatPrice } from './utils';
describe('formatPrice', () => {
it('formats EUR correctly', () => {
expect(formatPrice(1234.56)).toBe('1.234,56 €');
});
it('handles zero', () => {
expect(formatPrice(0)).toBe('0,00 €');
});
});
Component Tests
// Button.test.tsx
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { Button } from './Button';
describe('Button', () => {
it('renders correctly', () => {
render(<Button>Click me</Button>);
expect(screen.getByRole('button')).toHaveTextContent('Click me');
});
it('calls onClick when clicked', async () => {
const onClick = vi.fn();
render(<Button onClick={onClick}>Click</Button>);
await userEvent.click(screen.getByRole('button'));
expect(onClick).toHaveBeenCalledOnce();
});
it('is disabled when loading', () => {
render(<Button isLoading>Submit</Button>);
expect(screen.getByRole('button')).toBeDisabled();
});
});
Playwright E2E
npm install -D @playwright/test
npx playwright install
// playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({
testDir: './e2e',
use: {
baseURL: 'http://localhost:3000',
trace: 'on-first-retry',
},
webServer: {
command: 'npm run dev',
url: 'http://localhost:3000',
},
});
// e2e/contact.spec.ts
import { test, expect } from '@playwright/test';
test('contact form submission', async ({ page }) => {
await page.goto('/contact');
await page.getByLabel(/nome/i).fill('Mario Rossi');
await page.getByLabel(/email/i).fill('[email protected]');
await page.getByLabel(/messaggio/i).fill('Test message');
await page.getByRole('button', { name: /invia/i }).click();
await expect(page.getByText(/inviato/i)).toBeVisible();
});
Visual Testing
// e2e/visual.spec.ts
import { test, expect } from '@playwright/test';
test('homepage visual', async ({ page }) => {
await page.goto('/');
await expect(page).toHaveScreenshot('homepage.png', {
maxDiffPixels: 100,
});
});
Accessibility Testing
// e2e/a11y.spec.ts
import { test, expect } from '@playwright/test';
import AxeBuilder from '@axe-core/playwright';
test('homepage accessibility', async ({ page }) => {
await page.goto('/');
const results = await new AxeBuilder({ page })
.withTags(['wcag2aa'])
.analyze();
expect(results.violations).toEqual([]);
});
Scripts
{
"scripts": {
"test": "vitest",
"test:coverage": "vitest run --coverage",
"test:e2e": "playwright test",
"test:a11y": "playwright test --grep @a11y"
}
}
What ships with it: 3 files
2.4 KB alongside SKILL.md
evals/
- evals.json1.6 KB
- trigger_evals.json668 B
- learnings.md221 B