Skip to content

Commit 1907711

Browse files
committed
enhance multi-framework support for test documentation generation
1 parent 6bd1f81 commit 1907711

35 files changed

Lines changed: 1737 additions & 72 deletions

README.md

Lines changed: 80 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,100 @@
11
# Markdown Test Documentation Generator
22

3-
Automatically generate markdown documentation from Jest and Vitest test files, creating a comprehensive test documentation system with GitHub integration.
3+
Automatically generate markdown documentation from Jest, Vitest, and Pytest test files, creating a comprehensive test documentation system with GitHub integration.
44

55
## Features
66

7-
- Extracts test descriptions and metadata from Jest and Vitest test files
7+
- Extracts test descriptions and metadata from Jest, Vitest, and Pytest test files
88
- Supports all Jest/Vitest test functions: `it`, `test`, `describe`, `bench`
9-
- Handles test modifiers: `.skip`, `.only`, `.todo`, `.concurrent`, `.each()`
9+
- Supports all Pytest test functions: `def test_*()`, `class Test*`, parametrized tests
10+
- Handles test modifiers: `.skip`, `.only`, `.todo`, `.concurrent`, `.each()`, `@pytest.mark.*`
1011
- Generates individual markdown files for each test file
1112
- Creates a comprehensive index of all tests
12-
- Supports JSDoc-style annotations in test comments
13+
- Supports JSDoc-style annotations in test comments and Python docstrings
1314
- Categorizes tests and extracts tags
1415
- Formats using Given/When/Then style for behavior-driven tests
1516
- **NEW**: GitHub repository integration with direct links to source code
17+
- **NEW**: Multi-framework support with automatic framework detection
1618

17-
## Vitest Support
19+
## Supported Test Frameworks
1820

19-
Full compatibility with Vitest testing framework, including:
21+
### Jest/Vitest Support
22+
Full compatibility with Jest and Vitest testing frameworks, including:
2023

21-
### Supported Test Functions
24+
#### Supported Test Functions
2225
- `it()` and `test()` - Standard test cases
2326
- `describe()` - Test suites and grouping
2427
- `bench()` - Benchmark/performance tests (Vitest-specific)
2528

26-
### Supported Modifiers
29+
#### Supported Modifiers
2730
- `.skip` - Skip tests during execution
2831
- `.only` - Run only specific tests
2932
- `.todo` - Mark tests as todo/pending
3033
- `.concurrent` - Run tests in parallel
3134
- `.each([...])` - Parameterized tests with data sets
3235

33-
### Example Vitest Test File
36+
### Pytest Support
37+
Full compatibility with Pytest testing framework, including:
38+
39+
#### Supported Test Patterns
40+
- `def test_*()` - Function-based test cases
41+
- `class Test*:` - Class-based test suites
42+
- `@pytest.mark.*` and `@mark.*` - Test markers and decorators
43+
- `@pytest.mark.parametrize` - Parameterized tests
44+
- `@pytest.mark.skip` - Skipped tests
45+
46+
#### Docstring Parsing
47+
- Triple-quoted docstrings (""" or ''')
48+
- Bullet point steps extraction (e.g., `* step description`)
49+
- BDD-style annotations (@given/@when/@then/@and)
50+
- Automatic description and step extraction
51+
52+
### Example Pytest Test File
53+
```python
54+
import pytest
55+
from pytest import mark
56+
57+
@mark.smoke
58+
@mark.test_key('ETCM-6992')
59+
def test_user_login(api, user_credentials):
60+
"""Test user login functionality
61+
62+
* navigate to login page
63+
* enter valid credentials
64+
* click login button
65+
* verify user is redirected to dashboard
66+
"""
67+
api.navigate_to_login()
68+
api.enter_credentials(user_credentials)
69+
api.click_login()
70+
assert api.current_page() == "dashboard"
71+
72+
@pytest.mark.parametrize("input_value,expected", [
73+
(1, 2), (2, 4), (3, 6)
74+
])
75+
def test_multiplication(input_value, expected):
76+
"""Test multiplication function with multiple inputs
77+
78+
@given an input value
79+
@when multiplying by 2
80+
@then result should match expected value
81+
"""
82+
assert input_value * 2 == expected
83+
84+
class TestUserManagement:
85+
@mark.integration
86+
def test_create_user(self, api):
87+
"""Test user creation process
88+
89+
* prepare user data
90+
* send creation request
91+
* verify user exists in database
92+
"""
93+
user_data = {"name": "John", "email": "john@test.com"}
94+
response = api.create_user(user_data)
95+
assert response.status_code == 201
96+
assert api.user_exists(user_data["email"])
97+
```
3498
```typescript
3599
import { describe, it, test, bench, expect } from 'vitest';
36100

@@ -125,6 +189,11 @@ Basic usage:
125189
markdown-docs --source ./src/test --output ./docs/tests
126190
```
127191

192+
With specific test framework:
193+
```bash
194+
markdown-docs --source ./tests --output ./docs/tests --test-framework pytest
195+
```
196+
128197
With GitHub integration:
129198
```bash
130199
markdown-docs --source ./src/test --output ./docs/tests \
@@ -137,6 +206,7 @@ markdown-docs --source ./src/test --output ./docs/tests \
137206

138207
- `--source <path>`: Specify the source directory containing test files (default: `./src/test`)
139208
- `--output <path>`: Specify the output directory for documentation (default: `./doc/tests`)
209+
- `--test-framework <framework>`: Specify test framework - `jest`, `vitest`, `pytest`, or `auto` (default: `auto`)
140210
- `--github-url <url>`: GitHub repository URL (e.g., 'https://github.com/username/repo')
141211
- `--github-branch <branch>`: GitHub branch name (default: 'main')
142212
- `--repository-root <path>`: Repository root directory (default: current working directory)
@@ -160,6 +230,7 @@ import { MarkdownDocsGenerator } from 'markdown-docs-generator';
160230
const generator = new MarkdownDocsGenerator({
161231
sourceDir: './src/test',
162232
outputDir: './docs/tests',
233+
testFramework: 'pytest', // or 'jest', 'vitest', 'auto'
163234
githubUrl: 'https://github.com/username/repo',
164235
githubBranch: 'main',
165236
repositoryRoot: './',

action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: 'markdown-test-docs-action'
2-
description: 'Generate markdown documentation from TypeScript/Jest/Vitest test files'
2+
description: 'Generate markdown documentation from Jest/Vitest/Pytest test files'
33
author: 'Szymon Paluchowski'
44

55
inputs:
@@ -23,6 +23,10 @@ inputs:
2323
description: 'Repository root directory'
2424
required: false
2525
default: ''
26+
test-framework:
27+
description: 'Test framework - jest, vitest, pytest, or auto'
28+
required: false
29+
default: 'auto'
2630
verbose:
2731
description: 'Enable verbose logging'
2832
required: false

dist/file-utils.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { TestFramework } from './types';
12
export declare class FileUtils {
23
private verbose;
34
constructor(verbose?: boolean);
@@ -8,7 +9,11 @@ export declare class FileUtils {
89
/**
910
* Recursively find all test files in a directory
1011
*/
11-
findTestFiles(sourceDir: string): string[];
12+
findTestFiles(sourceDir: string, framework?: TestFramework): string[];
13+
/**
14+
* Check if a file is a test file based on framework
15+
*/
16+
private isTestFile;
1217
/**
1318
* Read file content as string
1419
*/

dist/framework-detector.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { TestFramework } from './types';
2+
export declare class FrameworkDetector {
3+
/**
4+
* Detect test framework based on file extension and content
5+
*/
6+
static detectFramework(filePath: string, content?: string): TestFramework;
7+
/**
8+
* Check if file is a test file based on naming conventions
9+
*/
10+
static isTestFile(filePath: string): boolean;
11+
/**
12+
* Get file extensions for a specific framework
13+
*/
14+
static getFrameworkExtensions(framework: TestFramework): string[];
15+
}

0 commit comments

Comments
 (0)