|
| 1 | +# CPK-E2E |
| 2 | + |
| 3 | +E2E render testing tool for [cpk-ui](https://github.com/crossplatformkorea/cpk-ui) React Native components. |
| 4 | + |
| 5 | +## Project Structure |
| 6 | + |
| 7 | +``` |
| 8 | +cpk-e2e/ |
| 9 | +├── scripts/ |
| 10 | +│ ├── discover-components.ts # Parse cpk-ui source to find all components |
| 11 | +│ ├── check-coverage.ts # Verify all components have story coverage |
| 12 | +│ └── run-e2e.ts # Full E2E pipeline orchestrator |
| 13 | +├── tests/ |
| 14 | +│ └── components.spec.ts # Playwright tests that crawl all stories |
| 15 | +├── screenshots/ # Auto-generated screenshots (gitignored) |
| 16 | +├── playwright.config.ts |
| 17 | +└── package.json |
| 18 | +``` |
| 19 | + |
| 20 | +## How It Works |
| 21 | + |
| 22 | +1. **Discover**: Parses `cpk-ui/src/index.tsx` to find all exported components |
| 23 | +2. **Build**: Builds cpk-ui's Storybook as static web app |
| 24 | +3. **Coverage**: Checks which components have stories (and which don't) |
| 25 | +4. **Test**: Playwright opens each story in a headless browser and checks: |
| 26 | + - No console errors |
| 27 | + - No React error boundaries |
| 28 | + - No uncaught exceptions |
| 29 | + - Component actually renders (not empty) |
| 30 | +5. **Screenshot**: Saves a screenshot of each story for visual regression |
| 31 | + |
| 32 | +## Prerequisites |
| 33 | + |
| 34 | +- cpk-ui must be cloned at `../cpk-ui` (sibling directory) |
| 35 | +- Storybook must be buildable in cpk-ui (`bun run build-storybook`) |
| 36 | + |
| 37 | +## Commands |
| 38 | + |
| 39 | +```bash |
| 40 | +bun install # Install dependencies |
| 41 | +bun run discover # List all cpk-ui components |
| 42 | +bun run check-coverage # Check story coverage |
| 43 | +bun run test # Run Playwright tests (auto-starts server) |
| 44 | +bun run test:headed # Run with visible browser |
| 45 | +bun run test:ui # Interactive Playwright UI |
| 46 | +bun run e2e # Full pipeline (discover + build + test) |
| 47 | +bun run e2e -- --skip-build # Skip Storybook rebuild |
| 48 | +bun run report # View HTML test report |
| 49 | +``` |
| 50 | + |
| 51 | +## Adding New Tests |
| 52 | + |
| 53 | +### Testing a specific component |
| 54 | + |
| 55 | +Add a new test file in `tests/`: |
| 56 | + |
| 57 | +```ts |
| 58 | +// tests/button.spec.ts |
| 59 | +import {test, expect} from '@playwright/test'; |
| 60 | + |
| 61 | +test('Button renders all variants', async ({page}) => { |
| 62 | + // Story ID format: category-componentname--storyname |
| 63 | + await page.goto('/iframe.html?id=ui-button--primary&viewMode=story'); |
| 64 | + await expect(page.locator('button')).toBeVisible(); |
| 65 | +}); |
| 66 | +``` |
| 67 | + |
| 68 | +### Testing interactions |
| 69 | + |
| 70 | +```ts |
| 71 | +test('Button click triggers action', async ({page}) => { |
| 72 | + await page.goto('/iframe.html?id=ui-button--primary&viewMode=story'); |
| 73 | + await page.click('button'); |
| 74 | + // Check for state changes, navigation, etc. |
| 75 | +}); |
| 76 | +``` |
| 77 | + |
| 78 | +## Architecture Decisions |
| 79 | + |
| 80 | +- **Storybook as render target**: Components are already configured with proper props in stories. No need to guess default props. |
| 81 | +- **Playwright over Detox/Maestro**: Tests run on web (react-native-web) which catches most render errors. No simulator needed. |
| 82 | +- **Separate repo**: Keeps E2E concerns isolated from the component library. Can test multiple versions/branches. |
| 83 | +- **Screenshot-based**: Every story gets a screenshot saved. Future: add visual regression comparison. |
| 84 | + |
| 85 | +## Future Roadmap |
| 86 | + |
| 87 | +- [ ] Visual regression with screenshot comparison (baseline vs current) |
| 88 | +- [ ] Accessibility audits (axe-core integration) |
| 89 | +- [ ] Performance metrics (render time per component) |
| 90 | +- [ ] Mobile viewport testing |
| 91 | +- [ ] Dark mode testing |
| 92 | +- [ ] CI integration with cpk-ui (trigger on PR) |
| 93 | +- [ ] Test interaction stories (click, input, gesture) |
| 94 | +- [ ] Cross-browser testing (Firefox, Safari) |
0 commit comments