|
| 1 | +# Layer 4: E2E Markdown Rendering Tests |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +Layer 4 provides end-to-end testing of markdown rendering through the complete Astro pipeline with comprehensive accessibility validation using the Axe library. |
| 6 | + |
| 7 | +## Architecture |
| 8 | + |
| 9 | +```bash |
| 10 | +Markdown Fixtures |
| 11 | + ↓ |
| 12 | +Test Component (Astro) |
| 13 | + ↓ |
| 14 | +Full Markdown Pipeline |
| 15 | + ↓ |
| 16 | +Rendered HTML |
| 17 | + ↓ |
| 18 | +Testing Library + Axe Validation |
| 19 | +``` |
| 20 | + |
| 21 | +## Test Component |
| 22 | + |
| 23 | +Located at `src/components/Test/index.astro`, this component: |
| 24 | + |
| 25 | +- Accepts markdown content as a prop |
| 26 | +- Processes through the production-identical plugin pipeline |
| 27 | +- Returns rendered HTML for testing |
| 28 | + |
| 29 | +## Test Strategy |
| 30 | + |
| 31 | +### Fixtures (`__fixtures__/markdown/`) |
| 32 | + |
| 33 | +Five comprehensive fixtures testing different features: |
| 34 | + |
| 35 | +1. **abbreviations.md** - Tests MDAST abbreviation plugin |
| 36 | +2. **attributes.md** - Tests remark-attr custom classes |
| 37 | +3. **attribution.md** - Tests blockquote attributions with figure/figcaption |
| 38 | +4. **emoji.md** - Tests emoji shortcodes with accessibility |
| 39 | +5. **full-pipeline.md** - Tests all features working together |
| 40 | + |
| 41 | +### Test Coverage (11 tests) |
| 42 | + |
| 43 | +#### Feature Tests (4) |
| 44 | + |
| 45 | +- ✅ Abbreviations with proper HTML and accessibility |
| 46 | +- ✅ Custom attributes on elements |
| 47 | +- ✅ Blockquote attributions with semantic HTML |
| 48 | +- ✅ Emojis with accessibility attributes |
| 49 | + |
| 50 | +#### Integration Tests (3) |
| 51 | + |
| 52 | +- ✅ All features together with proper semantics |
| 53 | +- ✅ Valid semantic HTML structure |
| 54 | +- ✅ Complex markdown with GFM features |
| 55 | + |
| 56 | +#### Accessibility Tests (4) |
| 57 | + |
| 58 | +- ✅ Abbreviations have title attributes |
| 59 | +- ✅ Emojis have proper ARIA attributes |
| 60 | +- ✅ Heading anchor links are accessible |
| 61 | +- ✅ Blockquote attributions use semantic HTML |
| 62 | + |
| 63 | +## Accessibility Validation |
| 64 | + |
| 65 | +Every test includes accessibility validation using `vitest-axe`: |
| 66 | + |
| 67 | +```typescript |
| 68 | +const results = await axe(container) |
| 69 | +expect(results).toHaveNoViolations() |
| 70 | +``` |
| 71 | + |
| 72 | +This ensures: |
| 73 | + |
| 74 | +- WCAG compliance |
| 75 | +- Proper ARIA attributes |
| 76 | +- Semantic HTML structure |
| 77 | +- Screen reader compatibility |
| 78 | + |
| 79 | +## Running Tests |
| 80 | + |
| 81 | +```bash |
| 82 | +# Run Layer 4 E2E tests only |
| 83 | +npx vitest run src/lib/markdown/__tests__/e2e/ |
| 84 | + |
| 85 | +# Run all markdown tests (all 4 layers) |
| 86 | +npx vitest run src/lib/markdown/__tests__/ |
| 87 | + |
| 88 | +# Run with watch mode |
| 89 | +npx vitest watch src/lib/markdown/__tests__/e2e/ |
| 90 | +``` |
| 91 | + |
| 92 | +## Key Features |
| 93 | + |
| 94 | +### No Snapshots |
| 95 | + |
| 96 | +Tests use explicit assertions instead of snapshots for better maintainability and clearer test failures. |
| 97 | + |
| 98 | +### Production Pipeline |
| 99 | + |
| 100 | +Uses the exact same plugin configuration as production to ensure accurate E2E validation. |
| 101 | + |
| 102 | +### Accessibility First |
| 103 | + |
| 104 | +Every test validates accessibility with Axe, ensuring WCAG compliance is maintained. |
| 105 | + |
| 106 | +### Preact Integration |
| 107 | + |
| 108 | +Uses `@testing-library/preact` (not React) to match the project's Preact configuration. |
| 109 | + |
| 110 | +## Test Statistics |
| 111 | + |
| 112 | +- **Total Tests**: 146 across all 4 layers |
| 113 | + - Layer 1 (Isolated): 119 tests |
| 114 | + - Layer 2 (Astro Pipeline): 57 tests |
| 115 | + - Layer 3 (Full Integration): 10 tests |
| 116 | + - Layer 4 (E2E + Accessibility): 11 tests |
| 117 | + |
| 118 | +## Dependencies |
| 119 | + |
| 120 | +- `vitest` - Test runner |
| 121 | +- `@testing-library/preact` - Component rendering |
| 122 | +- `vitest-axe` - Accessibility testing |
| 123 | +- `jsdom` - DOM environment |
| 124 | + |
| 125 | +All dependencies were already present in the project. |
0 commit comments