Mermaid Test Runner
This document describes the dedicated test runner for Mermaid diagram functionality in the MIJUG .NET workspace.
Overview
The scripts/test-mermaid-diagrams.js script provides a specialized test runner that focuses exclusively on Mermaid diagram rendering and functionality. It automatically discovers all mermaid-related test files and provides flexible browser testing options.
Features
- Automatic Test Discovery: Finds all mermaid-related test files in the e2e directory
- Multi-Browser Support: Tests with Chromium, Firefox, and WebKit
- Browser Management: Automatic browser installation and verification
- Flexible Options: Headed/headless modes, debug mode, custom worker counts
- Error Handling: Robust error handling with helpful messages
- Cross-Platform: Works on Linux, macOS, and Windows
Usage
Basic Commands
Advanced Options
Command Line Options
| Option | Description | Example |
|---|---|---|
--ensure-browsers |
Install browsers before testing | --ensure-browsers |
--headed |
Run with browser UI visible | --headed |
--debug |
Step-by-step debug mode | --debug |
--project=<name> |
Specify browser (chromium, firefox, webkit) | --project=firefox |
--workers=<num> |
Number of parallel workers (default: 1) | --workers=2 |
--verbose |
Enable verbose output | --verbose |
--help |
Show help message | --help |
Test Files Covered
The script automatically discovers and runs these test files:
-
e2e/mermaid-basic-visual.spec.ts- Tests basic mermaid diagram rendering
- Validates SVG generation and visual elements
-
e2e/mermaid-default-layout.spec.ts- Tests mermaid rendering in default page layout
- Validates sequence diagrams and syntax error handling
-
e2e/mermaid-diagrams-visual.spec.ts- Tests visual diagram sample page
- Validates multiple diagram types and SVG content
-
e2e/mermaid-documentation.spec.ts- Tests documentation pages
- Validates quick start, configuration guide, and examples
Browser Compatibility
| Browser | Support Level | Notes |
|---|---|---|
| Chromium | β Full | Default browser, fastest execution |
| Firefox | β Full | Good compatibility, slightly slower |
| WebKit | β Full | Safari engine, best for macOS testing |
Error Handling
The script provides comprehensive error handling:
- Browser Detection: Automatically detects available browsers
- Fallback Support: Falls back to available browsers if requested browser isnβt available
- Installation Help: Guides users to install missing browsers
- Clear Messages: Provides helpful error messages and suggestions
Integration with CI/CD
The script is designed to work in continuous integration environments:
Performance Considerations
- Single Worker Default: Uses 1 worker by default for stability
- Network Idle: Waits for network idle state before testing
- Timeout Handling: Includes appropriate timeouts for browser operations
- Resource Cleanup: Properly cleans up browser instances
Debugging
For debugging mermaid rendering issues:
Configuration
The script respects the Playwright configuration in playwright.config.ts but allows overrides via command line arguments.
Output Example
Troubleshooting
Common Issues
-
Browser Not Found
# Solution: Install browsers npm run test:mermaid -- --ensure-browsers -
Permission Errors
# Solution: Run with proper permissions or use skipIfNoPermissions node scripts/test-mermaid-diagrams.js --ensure-browsers --skip-if-no-permissions -
Network Timeouts
# Solution: Increase timeout or check network connectivity node scripts/test-mermaid-diagrams.js --workers=1 -
iNotify Watches Limit Exceeded (Linux)
Error:
Listen::Error::INotifyMaxWatchesExceeded: Unable to monitor directories for changes because iNotify max watches exceededSymptoms: Jekyll server fails to start with file watching errors, preventing the test server from running.
Solution: Increase the iNotify watches limit on Linux systems:
# Check current limit cat /proc/sys/fs/inotify/max_user_watches # Increase limit permanently (requires sudo) echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf sudo sysctl -p # Verify the change cat /proc/sys/fs/inotify/max_user_watchesAlternative temporary fix:
# Temporary increase (until reboot) sudo sysctl fs.inotify.max_user_watches=524288Background: This issue occurs when Jekyll tries to watch too many files for changes. The default Linux limit is typically 8,192 watches, but large projects with many files can exceed this limit. Setting it to 524,288 provides ample headroom for most development scenarios.
Future Enhancements
Potential improvements to the script:
- Parallel Browser Testing: Run multiple browsers simultaneously
- Visual Regression Testing: Screenshot comparison for diagram rendering
- Performance Metrics: Measure diagram rendering performance
- Custom Test Patterns: Allow custom glob patterns for test discovery
- Report Generation: Generate detailed HTML reports
- Integration Testing: Test mermaid with different Jekyll configurations
My Info Just Under Glass