Skip to content

Commit 8f46cbd

Browse files
committed
feat: add dependency graph visualization
- Add CLI command 'graph' to generate dependency graphs - Support Mermaid, ASCII, JSON and HTML output formats - Add toMermaid() and toAscii() methods to DependencyGraph - Add generateGraph() and generateHtmlGraph() helper functions - Update documentation with graph visualization guide - Restructure docs to match api-spy format
1 parent d7ee7a3 commit 8f46cbd

11 files changed

Lines changed: 1094 additions & 13 deletions

File tree

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- 🔄 **Auto-ordering** - Tests run in dependency order automatically
2020
-**Cached Results** - Each test runs once, results are cached
2121
- 🎯 **Zero Config** - Works out of the box with Playwright
22+
- 📊 **Dependency Graph** - Visualize test dependencies with Mermaid diagrams
2223

2324
## Installation
2425

@@ -96,6 +97,21 @@ interface Relay {
9697
| Playwright annotations | `test.info().annotations` | ✅ Yes |
9798
| `relay.require()` | `await relay.require('test')` | At runtime |
9899

100+
## Dependency Graph
101+
102+
Visualize your test dependencies:
103+
104+
```bash
105+
# Mermaid diagram
106+
npx playwright-relay graph "tests/**/*.spec.ts"
107+
108+
# ASCII diagram
109+
npx playwright-relay graph "tests/**/*.spec.ts" --format ascii
110+
111+
# Interactive HTML
112+
npx playwright-relay graph "tests/**/*.spec.ts" --format html --output graph.html
113+
```
114+
99115
## Documentation
100116

101117
📖 **[Full Documentation](https://damianovsky.github.io/playwright-relay)**

docs/examples/graph.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# Dependency Graph
2+
3+
Generate visual dependency graphs from your test files.
4+
5+
## CLI Usage
6+
7+
```bash
8+
# Generate Mermaid diagram
9+
npx playwright-relay graph "tests/**/*.spec.ts"
10+
11+
# Generate ASCII diagram
12+
npx playwright-relay graph "tests/**/*.spec.ts" --format ascii
13+
14+
# Generate HTML page with interactive graph
15+
npx playwright-relay graph "tests/**/*.spec.ts" --format html --output graph.html
16+
17+
# Generate JSON
18+
npx playwright-relay graph "tests/**/*.spec.ts" --format json
19+
20+
# Change direction (TB, BT, LR, RL)
21+
npx playwright-relay graph "tests/**/*.spec.ts" --direction LR
22+
```
23+
24+
## Output Formats
25+
26+
### Mermaid (default)
27+
28+
```bash
29+
npx playwright-relay graph "tests/**/*.spec.ts"
30+
```
31+
32+
Output:
33+
```mermaid
34+
flowchart TB
35+
N0["create user"]
36+
N1["update user"]
37+
N2["delete user"]
38+
N0 --> N1
39+
N1 --> N2
40+
```
41+
42+
### ASCII
43+
44+
```bash
45+
npx playwright-relay graph "tests/**/*.spec.ts" --format ascii
46+
```
47+
48+
Output:
49+
```
50+
○ create user
51+
● update user
52+
└─ depends on: create user
53+
● delete user
54+
└─ depends on: update user
55+
```
56+
57+
### HTML
58+
59+
```bash
60+
npx playwright-relay graph "tests/**/*.spec.ts" --format html --output graph.html
61+
```
62+
63+
Generates an HTML page with an interactive Mermaid diagram.
64+
65+
### JSON
66+
67+
```bash
68+
npx playwright-relay graph "tests/**/*.spec.ts" --format json
69+
```
70+
71+
Output:
72+
```json
73+
{
74+
"nodes": [
75+
{ "id": "test.spec.ts > create user", "title": "create user", "file": "test.spec.ts" },
76+
{ "id": "test.spec.ts > update user", "title": "update user", "file": "test.spec.ts" }
77+
],
78+
"edges": [
79+
{ "from": "test.spec.ts > create user", "to": "test.spec.ts > update user" }
80+
]
81+
}
82+
```
83+
84+
## Programmatic Usage
85+
86+
```typescript
87+
import { generateGraph, generateHtmlGraph, buildGraphFromFiles } from 'playwright-relay';
88+
89+
// Generate graph output
90+
const result = generateGraph('tests/**/*.spec.ts', {
91+
format: 'mermaid',
92+
direction: 'TB',
93+
includeOrphans: true,
94+
});
95+
96+
console.log(result.output);
97+
console.log(`Tests: ${result.testCount}, Dependencies: ${result.dependencyCount}`);
98+
99+
// Generate HTML
100+
const html = generateHtmlGraph('tests/**/*.spec.ts', {
101+
direction: 'LR',
102+
});
103+
104+
// Build graph object for custom processing
105+
const graph = buildGraphFromFiles(['tests/auth.spec.ts', 'tests/user.spec.ts']);
106+
console.log(graph.toMermaid());
107+
console.log(graph.toAscii());
108+
```
109+
110+
## Graph Directions
111+
112+
| Direction | Description |
113+
|-----------|-------------|
114+
| `TB` | Top to bottom (default) |
115+
| `BT` | Bottom to top |
116+
| `LR` | Left to right |
117+
| `RL` | Right to left |
118+
119+
## Options
120+
121+
| Option | Type | Default | Description |
122+
|--------|------|---------|-------------|
123+
| `format` | `string` | `'mermaid'` | Output format: `mermaid`, `ascii`, `json`, `html` |
124+
| `direction` | `string` | `'TB'` | Graph direction for Mermaid |
125+
| `includeOrphans` | `boolean` | `true` | Include tests without dependencies |
126+
| `output` | `string` | - | Write to file instead of stdout |

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ nav:
4040
- Examples:
4141
- Basic Patterns: examples/basic.md
4242
- Advanced Patterns: examples/advanced.md
43+
- Dependency Graph: examples/graph.md
4344

4445
markdown_extensions:
4546
- pymdownx.highlight:

0 commit comments

Comments
 (0)