test-gen-js 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +71 -0
- package/LICENSE +22 -0
- package/README.md +538 -0
- package/bin/cli.js +4 -0
- package/dist/analyzer/componentAnalyzer.d.ts +12 -0
- package/dist/analyzer/componentAnalyzer.d.ts.map +1 -0
- package/dist/analyzer/componentAnalyzer.js +223 -0
- package/dist/analyzer/componentAnalyzer.js.map +1 -0
- package/dist/analyzer/fileAnalyzer.d.ts +17 -0
- package/dist/analyzer/fileAnalyzer.d.ts.map +1 -0
- package/dist/analyzer/fileAnalyzer.js +201 -0
- package/dist/analyzer/fileAnalyzer.js.map +1 -0
- package/dist/analyzer/functionAnalyzer.d.ts +12 -0
- package/dist/analyzer/functionAnalyzer.d.ts.map +1 -0
- package/dist/analyzer/functionAnalyzer.js +184 -0
- package/dist/analyzer/functionAnalyzer.js.map +1 -0
- package/dist/analyzer/index.d.ts +7 -0
- package/dist/analyzer/index.d.ts.map +1 -0
- package/dist/analyzer/index.js +14 -0
- package/dist/analyzer/index.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +113 -0
- package/dist/cli.js.map +1 -0
- package/dist/generator/index.d.ts +6 -0
- package/dist/generator/index.d.ts.map +1 -0
- package/dist/generator/index.js +12 -0
- package/dist/generator/index.js.map +1 -0
- package/dist/generator/mockGenerator.d.ts +14 -0
- package/dist/generator/mockGenerator.d.ts.map +1 -0
- package/dist/generator/mockGenerator.js +123 -0
- package/dist/generator/mockGenerator.js.map +1 -0
- package/dist/generator/testGenerator.d.ts +14 -0
- package/dist/generator/testGenerator.d.ts.map +1 -0
- package/dist/generator/testGenerator.js +301 -0
- package/dist/generator/testGenerator.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/parser/astParser.d.ts +15 -0
- package/dist/parser/astParser.d.ts.map +1 -0
- package/dist/parser/astParser.js +100 -0
- package/dist/parser/astParser.js.map +1 -0
- package/dist/parser/index.d.ts +6 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +12 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/typeExtractor.d.ts +14 -0
- package/dist/parser/typeExtractor.d.ts.map +1 -0
- package/dist/parser/typeExtractor.js +165 -0
- package/dist/parser/typeExtractor.js.map +1 -0
- package/dist/templates/component.ejs +67 -0
- package/dist/templates/function.ejs +59 -0
- package/dist/templates/snapshot.ejs +48 -0
- package/dist/types.d.ts +95 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/fileUtils.d.ts +43 -0
- package/dist/utils/fileUtils.d.ts.map +1 -0
- package/dist/utils/fileUtils.js +109 -0
- package/dist/utils/fileUtils.js.map +1 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +22 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/naming.d.ts +37 -0
- package/dist/utils/naming.d.ts.map +1 -0
- package/dist/utils/naming.js +73 -0
- package/dist/utils/naming.js.map +1 -0
- package/package.json +84 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
### Planned
|
|
11
|
+
- Directory scanning (`scan` command)
|
|
12
|
+
- Configuration file support (`.testgenrc.js`)
|
|
13
|
+
- Node.js backend support
|
|
14
|
+
- Custom templates
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## [0.1.0] - 2024-01-07
|
|
19
|
+
|
|
20
|
+
### Added
|
|
21
|
+
- ๐ Initial release
|
|
22
|
+
- CLI interface with `generate` command
|
|
23
|
+
- AST parsing using Babel
|
|
24
|
+
- React component analysis
|
|
25
|
+
- Props extraction
|
|
26
|
+
- Hooks detection (useState, useEffect, etc.)
|
|
27
|
+
- Event handlers detection (onPress, onClick, etc.)
|
|
28
|
+
- React Native component support
|
|
29
|
+
- TypeScript function analysis
|
|
30
|
+
- Parameters extraction
|
|
31
|
+
- Return type detection
|
|
32
|
+
- Async function support
|
|
33
|
+
- EJS template system
|
|
34
|
+
- Component test template
|
|
35
|
+
- Function test template
|
|
36
|
+
- Snapshot test template
|
|
37
|
+
- Auto-detection of testing library
|
|
38
|
+
- `@testing-library/react` for React
|
|
39
|
+
- `@testing-library/react-native` for React Native
|
|
40
|
+
- Mock generation for common libraries
|
|
41
|
+
- React Navigation
|
|
42
|
+
- React Redux
|
|
43
|
+
- AsyncStorage
|
|
44
|
+
- GitHub Actions CI/CD
|
|
45
|
+
- Automated testing
|
|
46
|
+
- Automated npm publishing
|
|
47
|
+
|
|
48
|
+
### Commands
|
|
49
|
+
- `test-gen-js generate <file>` - Generate test file
|
|
50
|
+
- `tgjs g <file>` - Shorthand alias
|
|
51
|
+
|
|
52
|
+
### Options
|
|
53
|
+
- `--output, -o` - Custom output path
|
|
54
|
+
- `--snapshot` - Include snapshot tests
|
|
55
|
+
- `--mock` - Auto-generate mocks (default: true)
|
|
56
|
+
- `--overwrite` - Overwrite existing files
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## [0.0.1] - 2024-01-07
|
|
61
|
+
|
|
62
|
+
### Added
|
|
63
|
+
- Project initialization
|
|
64
|
+
- Basic project structure
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
[Unreleased]: https://github.com/liveforownhappiness/test-gen-js-/compare/v0.1.0...HEAD
|
|
69
|
+
[0.1.0]: https://github.com/liveforownhappiness/test-gen-js-/releases/tag/v0.1.0
|
|
70
|
+
[0.0.1]: https://github.com/liveforownhappiness/test-gen-js-/releases/tag/v0.0.1
|
|
71
|
+
|
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 liveforownhappiness
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,538 @@
|
|
|
1
|
+
# test-gen-js
|
|
2
|
+
|
|
3
|
+
> ๐งช Auto-generate test boilerplate code for JavaScript/TypeScript, React, and React Native projects
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/test-gen-js)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
[](https://github.com/liveforownhappiness/test-gen-js-/actions)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## ๐ฏ ๋ชฉํ (Goal)
|
|
12
|
+
|
|
13
|
+
> **"ํ
์คํธ 0๊ฐ โ ๊ธฐ๋ณธ ํ
์คํธ๋ผ๋ ์๋ ์ํ"**
|
|
14
|
+
|
|
15
|
+
์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ์๋ฒฝํ ํ
์คํธ ์๋ํ๊ฐ ์๋, **ํ
์คํธ ์์ฑ์ ์ง์
์ฅ๋ฒฝ์ ๋ฎ์ถ๋ ๊ฒ**์ ๋ชฉํ๋ก ํฉ๋๋ค.
|
|
16
|
+
|
|
17
|
+
### ์ด ๋๊ตฌ๊ฐ ํด๊ฒฐํ๋ ๋ฌธ์
|
|
18
|
+
|
|
19
|
+
| ๋ฌธ์ | ํด๊ฒฐ |
|
|
20
|
+
|------|------|
|
|
21
|
+
| ๐ซ "ํ
์คํธ ํ์ผ ๋ง๋ค๊ธฐ ๊ท์ฐฎ์์" | โ
๋ณด์ผ๋ฌํ๋ ์ดํธ ์๋ ์์ฑ |
|
|
22
|
+
| ๐ค "์ด๋ป๊ฒ ์์ํด์ผ ํ ์ง ๋ชจ๋ฅด๊ฒ ์ด์" | โ
์คํ ๊ฐ๋ฅํ ์์์ ์ ๊ณต |
|
|
23
|
+
| ๐ฐ "๋ ๋๋ง ๊ธฐ๋ณธ ํ
์คํธ๋ ์์ด์" | โ
์ต์ํ์ ์์ ๋ง ์ ๊ณต |
|
|
24
|
+
| ๐ "ํ
์คํธ ์์ฑ๋ฒ์ ๋ฐฐ์ฐ๊ณ ์ถ์ด์" | โ
ํ์ต ๋๊ตฌ๋ก ํ์ฉ ๊ฐ๋ฅ |
|
|
25
|
+
|
|
26
|
+
### ์ด ๋๊ตฌ์ ํ๊ณ
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
โ ๋น์ฆ๋์ค ๋ก์ง ํ
์คํธ ์๋ ์์ฑ โ ๊ฐ๋ฐ์๊ฐ ์ง์ ์์ฑ ํ์
|
|
30
|
+
โ ์๋ฒฝํ ํ
์คํธ ์ปค๋ฒ๋ฆฌ์ง โ ๋ถ๊ฐ๋ฅ (80% ๋ณด์ผ๋ฌํ๋ ์ดํธ, 20% ์ง์ ์์ฑ)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## ๐ฆ ์ค์น (Installation)
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# ์ ์ญ ์ค์น
|
|
39
|
+
npm install -g test-gen-js
|
|
40
|
+
|
|
41
|
+
# ๋๋ npx๋ก ๋ฐ๋ก ์ฌ์ฉ (์ค์น ์์ด)
|
|
42
|
+
npx test-gen-js generate src/components/Button.tsx
|
|
43
|
+
|
|
44
|
+
# ๋๋ ํ๋ก์ ํธ devDependency๋ก ์ค์น
|
|
45
|
+
npm install -D test-gen-js
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## ๐ ๋น ๋ฅธ ์์ (Quick Start)
|
|
51
|
+
|
|
52
|
+
### 1. React ์ปดํฌ๋ํธ ํ
์คํธ ์์ฑ
|
|
53
|
+
|
|
54
|
+
**์
๋ ฅ: `src/components/Button.tsx`**
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
import React from 'react';
|
|
58
|
+
|
|
59
|
+
interface ButtonProps {
|
|
60
|
+
title: string;
|
|
61
|
+
onPress: () => void;
|
|
62
|
+
disabled?: boolean;
|
|
63
|
+
loading?: boolean;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const Button = ({ title, onPress, disabled = false, loading = false }: ButtonProps) => {
|
|
67
|
+
return (
|
|
68
|
+
<button onClick={onPress} disabled={disabled || loading}>
|
|
69
|
+
{loading ? 'Loading...' : title}
|
|
70
|
+
</button>
|
|
71
|
+
);
|
|
72
|
+
};
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
**๋ช
๋ น์ด ์คํ:**
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
npx test-gen-js generate src/components/Button.tsx
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
**์ถ๋ ฅ: `src/components/Button.test.tsx`**
|
|
82
|
+
|
|
83
|
+
```tsx
|
|
84
|
+
import React from 'react';
|
|
85
|
+
import { render, fireEvent, screen, waitFor } from '@testing-library/react';
|
|
86
|
+
import { Button } from './Button';
|
|
87
|
+
|
|
88
|
+
describe('Button', () => {
|
|
89
|
+
const defaultProps = {
|
|
90
|
+
title: 'Test Title',
|
|
91
|
+
onPress: jest.fn(),
|
|
92
|
+
disabled: false,
|
|
93
|
+
loading: false
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
beforeEach(() => {
|
|
97
|
+
jest.clearAllMocks();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('renders without crashing', () => {
|
|
101
|
+
render(<Button {...defaultProps} />);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('renders with title prop', () => {
|
|
105
|
+
render(<Button {...defaultProps} />);
|
|
106
|
+
// TODO: Add specific assertions for title
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('calls onPress when triggered', () => {
|
|
110
|
+
const handler = jest.fn();
|
|
111
|
+
render(<Button {...defaultProps} onPress={handler} />);
|
|
112
|
+
|
|
113
|
+
// TODO: Trigger the onPress event
|
|
114
|
+
// fireEvent.click(screen.getByRole('button'));
|
|
115
|
+
|
|
116
|
+
// expect(handler).toHaveBeenCalled();
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
### 2. React Native ์ปดํฌ๋ํธ ํ
์คํธ ์์ฑ
|
|
124
|
+
|
|
125
|
+
**์
๋ ฅ: `src/components/Card.tsx`**
|
|
126
|
+
|
|
127
|
+
```tsx
|
|
128
|
+
import React, { useState } from 'react';
|
|
129
|
+
import { View, Text, TouchableOpacity, StyleSheet } from 'react-native';
|
|
130
|
+
|
|
131
|
+
interface CardProps {
|
|
132
|
+
title: string;
|
|
133
|
+
description: string;
|
|
134
|
+
onPress?: () => void;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export const Card = ({ title, description, onPress }: CardProps) => {
|
|
138
|
+
const [expanded, setExpanded] = useState(false);
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<TouchableOpacity onPress={onPress} style={styles.container}>
|
|
142
|
+
<Text style={styles.title}>{title}</Text>
|
|
143
|
+
<Text style={styles.description}>{description}</Text>
|
|
144
|
+
</TouchableOpacity>
|
|
145
|
+
);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const styles = StyleSheet.create({
|
|
149
|
+
container: { padding: 16 },
|
|
150
|
+
title: { fontSize: 18, fontWeight: 'bold' },
|
|
151
|
+
description: { fontSize: 14 },
|
|
152
|
+
});
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
**๋ช
๋ น์ด ์คํ:**
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
npx test-gen-js generate src/components/Card.tsx --snapshot
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
**์ถ๋ ฅ: `src/components/Card.test.tsx`**
|
|
162
|
+
|
|
163
|
+
```tsx
|
|
164
|
+
import React from 'react';
|
|
165
|
+
import { render, fireEvent, screen, waitFor } from '@testing-library/react-native';
|
|
166
|
+
import { Card } from './Card';
|
|
167
|
+
|
|
168
|
+
describe('Card', () => {
|
|
169
|
+
const defaultProps = {
|
|
170
|
+
title: 'Test Title',
|
|
171
|
+
description: 'Test Text',
|
|
172
|
+
onPress: jest.fn()
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
beforeEach(() => {
|
|
176
|
+
jest.clearAllMocks();
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('renders without crashing', () => {
|
|
180
|
+
render(<Card {...defaultProps} />);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('matches snapshot', () => {
|
|
184
|
+
const { toJSON } = render(<Card {...defaultProps} />);
|
|
185
|
+
expect(toJSON()).toMatchSnapshot();
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('calls onPress when triggered', () => {
|
|
189
|
+
const handler = jest.fn();
|
|
190
|
+
render(<Card {...defaultProps} onPress={handler} />);
|
|
191
|
+
|
|
192
|
+
// fireEvent.press(screen.getByTestId('card'));
|
|
193
|
+
// expect(handler).toHaveBeenCalled();
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// Hook: useState
|
|
197
|
+
it('uses useState correctly', () => {
|
|
198
|
+
render(<Card {...defaultProps} />);
|
|
199
|
+
// TODO: Add assertions for useState behavior
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
### 3. ์ผ๋ฐ ํจ์ ํ
์คํธ ์์ฑ
|
|
207
|
+
|
|
208
|
+
**์
๋ ฅ: `src/utils/calculate.ts`**
|
|
209
|
+
|
|
210
|
+
```typescript
|
|
211
|
+
export function calculateDiscount(price: number, discountRate: number): number {
|
|
212
|
+
if (discountRate < 0 || discountRate > 1) {
|
|
213
|
+
throw new Error('Invalid discount rate');
|
|
214
|
+
}
|
|
215
|
+
return price * (1 - discountRate);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export async function fetchUserData(userId: string): Promise<User> {
|
|
219
|
+
const response = await fetch(`/api/users/${userId}`);
|
|
220
|
+
return response.json();
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
**๋ช
๋ น์ด ์คํ:**
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
npx test-gen-js generate src/utils/calculate.ts
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
**์ถ๋ ฅ: `src/utils/calculate.test.ts`**
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
import { calculateDiscount, fetchUserData } from './calculate';
|
|
234
|
+
|
|
235
|
+
describe('calculateDiscount', () => {
|
|
236
|
+
beforeEach(() => {
|
|
237
|
+
jest.clearAllMocks();
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it('should return expected result', () => {
|
|
241
|
+
const result = calculateDiscount(42, 42);
|
|
242
|
+
|
|
243
|
+
// TODO: Add assertions
|
|
244
|
+
expect(result).toBeDefined();
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
describe('price parameter', () => {
|
|
248
|
+
it('should handle valid price', () => {
|
|
249
|
+
// TODO: Test with valid price values
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
describe('discountRate parameter', () => {
|
|
254
|
+
it('should handle valid discountRate', () => {
|
|
255
|
+
// TODO: Test with valid discountRate values
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
describe('fetchUserData', () => {
|
|
261
|
+
beforeEach(() => {
|
|
262
|
+
jest.clearAllMocks();
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it('should resolve successfully', async () => {
|
|
266
|
+
const result = await fetchUserData('test-string');
|
|
267
|
+
|
|
268
|
+
// TODO: Add assertions
|
|
269
|
+
expect(result).toBeDefined();
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it('should handle errors gracefully', async () => {
|
|
273
|
+
// TODO: Mock error scenario
|
|
274
|
+
// jest.spyOn(global, 'fetch').mockRejectedValue(new Error('Network error'));
|
|
275
|
+
// await expect(fetchUserData('123')).rejects.toThrow('Network error');
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
## ๐ CLI ๋ช
๋ น์ด
|
|
283
|
+
|
|
284
|
+
### `generate` (๋ณ์นญ: `g`)
|
|
285
|
+
|
|
286
|
+
๋จ์ผ ํ์ผ์์ ํ
์คํธ ์์ฑ
|
|
287
|
+
|
|
288
|
+
```bash
|
|
289
|
+
# ๊ธฐ๋ณธ ์ฌ์ฉ
|
|
290
|
+
test-gen-js generate <file>
|
|
291
|
+
tgjs g <file>
|
|
292
|
+
|
|
293
|
+
# ์ต์
|
|
294
|
+
--output, -o <path> # ์ถ๋ ฅ ํ์ผ ๊ฒฝ๋ก ์ง์
|
|
295
|
+
--template, -t <type> # ํ
ํ๋ฆฟ ํ์
(component | function | hook)
|
|
296
|
+
--snapshot # ์ค๋
์ท ํ
์คํธ ํฌํจ
|
|
297
|
+
--mock # Mock ์๋ ์์ฑ (๊ธฐ๋ณธ: true)
|
|
298
|
+
--overwrite # ๊ธฐ์กด ํ์ผ ๋ฎ์ด์ฐ๊ธฐ
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
**์์:**
|
|
302
|
+
|
|
303
|
+
```bash
|
|
304
|
+
# ๊ธฐ๋ณธ ์์ฑ
|
|
305
|
+
tgjs g src/components/Header.tsx
|
|
306
|
+
|
|
307
|
+
# ์ค๋
์ท ํ
์คํธ ํฌํจ
|
|
308
|
+
tgjs g src/components/Header.tsx --snapshot
|
|
309
|
+
|
|
310
|
+
# ์ปค์คํ
์ถ๋ ฅ ๊ฒฝ๋ก
|
|
311
|
+
tgjs g src/components/Header.tsx -o __tests__/Header.test.tsx
|
|
312
|
+
|
|
313
|
+
# ๊ธฐ์กด ํ์ผ ๋ฎ์ด์ฐ๊ธฐ
|
|
314
|
+
tgjs g src/components/Header.tsx --overwrite
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### `scan` (๋ณ์นญ: `s`) - v0.2.0 ์์
|
|
318
|
+
|
|
319
|
+
๋๋ ํ ๋ฆฌ ์ ์ฒด ์ค์บ ๋ฐ ์ผ๊ด ์์ฑ
|
|
320
|
+
|
|
321
|
+
```bash
|
|
322
|
+
# ๊ธฐ๋ณธ ์ฌ์ฉ
|
|
323
|
+
test-gen-js scan <directory>
|
|
324
|
+
|
|
325
|
+
# ์ต์
|
|
326
|
+
--dry-run # ๋ฏธ๋ฆฌ๋ณด๊ธฐ (ํ์ผ ์์ฑ ์ ํจ)
|
|
327
|
+
--pattern <glob> # ํ์ผ ํจํด (๊ธฐ๋ณธ: **/*.{ts,tsx,js,jsx})
|
|
328
|
+
--exclude <patterns> # ์ ์ธ ํจํด
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
### `init` - v0.2.0 ์์
|
|
332
|
+
|
|
333
|
+
์ค์ ํ์ผ ์ด๊ธฐํ
|
|
334
|
+
|
|
335
|
+
```bash
|
|
336
|
+
test-gen-js init
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
---
|
|
340
|
+
|
|
341
|
+
## ๐ ์ง์ ๋ฒ์
|
|
342
|
+
|
|
343
|
+
| ํ์
| ์ง์ ์ฌ๋ถ | ํ
์คํธ ํ๋ ์์ํฌ | ๋น๊ณ |
|
|
344
|
+
|------|----------|-----------------|------|
|
|
345
|
+
| JavaScript ํจ์ | โ
| Jest | |
|
|
346
|
+
| TypeScript ํจ์ | โ
| Jest | ํ์
๋ถ์ ์ง์ |
|
|
347
|
+
| React ์ปดํฌ๋ํธ | โ
| Jest + @testing-library/react | |
|
|
348
|
+
| React Native ์ปดํฌ๋ํธ | โ
| Jest + @testing-library/react-native | |
|
|
349
|
+
| Custom Hooks | โ
| Jest + @testing-library/react-hooks | |
|
|
350
|
+
| Node.js ๋ชจ๋ | ๐ v0.2 | Jest | |
|
|
351
|
+
| Express ํธ๋ค๋ฌ | ๐ v0.2 | Jest + supertest | |
|
|
352
|
+
| Vue ์ปดํฌ๋ํธ | ๐ ํ๋ฌ๊ทธ์ธ | Vitest | |
|
|
353
|
+
| Angular ์ปดํฌ๋ํธ | ๐ ํ๋ฌ๊ทธ์ธ | Jasmine | |
|
|
354
|
+
|
|
355
|
+
---
|
|
356
|
+
|
|
357
|
+
## ๐ง ์๋ ์๋ฆฌ
|
|
358
|
+
|
|
359
|
+
### AST (Abstract Syntax Tree) ๋ถ์
|
|
360
|
+
|
|
361
|
+
```
|
|
362
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
363
|
+
โ 1. ์
๋ ฅ: Button.tsx โ
|
|
364
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
|
|
365
|
+
โ export const Button = ({ title, onPress, disabled }) => { โ
|
|
366
|
+
โ const [loading, setLoading] = useState(false); โ
|
|
367
|
+
โ return ( โ
|
|
368
|
+
โ <TouchableOpacity onPress={onPress} disabled={disabled}> โ
|
|
369
|
+
โ <Text>{title}</Text> โ
|
|
370
|
+
โ </TouchableOpacity> โ
|
|
371
|
+
โ ); โ
|
|
372
|
+
โ } โ
|
|
373
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
374
|
+
โ
|
|
375
|
+
โผ Babel Parser
|
|
376
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
377
|
+
โ 2. AST ๋ถ์ ๊ฒฐ๊ณผ โ
|
|
378
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
|
|
379
|
+
โ { โ
|
|
380
|
+
โ name: "Button", โ
|
|
381
|
+
โ type: "arrow", โ
|
|
382
|
+
โ props: [ โ
|
|
383
|
+
โ { name: "title", type: "string", required: true }, โ
|
|
384
|
+
โ { name: "onPress", type: "function", required: true }, โ
|
|
385
|
+
โ { name: "disabled", type: "boolean", required: false } โ
|
|
386
|
+
โ ], โ
|
|
387
|
+
โ hooks: ["useState"], โ
|
|
388
|
+
โ events: ["onPress"], โ
|
|
389
|
+
โ framework: "react-native" โ
|
|
390
|
+
โ } โ
|
|
391
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
392
|
+
โ
|
|
393
|
+
โผ EJS Template
|
|
394
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
395
|
+
โ 3. ์ถ๋ ฅ: Button.test.tsx โ
|
|
396
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
|
|
397
|
+
โ describe('Button', () => { โ
|
|
398
|
+
โ const defaultProps = { title: '...', onPress: jest.fn() }; โ
|
|
399
|
+
โ it('renders without crashing', () => { ... }); โ
|
|
400
|
+
โ it('calls onPress when pressed', () => { ... }); โ
|
|
401
|
+
โ it('uses useState correctly', () => { ... }); โ
|
|
402
|
+
โ }); โ
|
|
403
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
### ์๋ํ ๋ฒ์
|
|
407
|
+
|
|
408
|
+
| ์์ญ | ์๋ํ ์์ค | ์ค๋ช
|
|
|
409
|
+
|------|------------|------|
|
|
410
|
+
| import ๋ฌธ | โ
100% | ํ๋ ์์ํฌ ์๋ ๊ฐ์ง |
|
|
411
|
+
| describe/it ๊ตฌ์กฐ | โ
100% | ์ปดํฌ๋ํธ/ํจ์๋ช
๊ธฐ๋ฐ |
|
|
412
|
+
| defaultProps ์์ฑ | โ
80% | TypeScript ํ์
๋ถ์ |
|
|
413
|
+
| Mock ์ค์ | โ
70% | ์ฃผ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์๋ ๊ฐ์ง |
|
|
414
|
+
| ๋ ๋๋ง ํ
์คํธ | โ
100% | ๊ธฐ๋ณธ ์ ๊ณต |
|
|
415
|
+
| ์ด๋ฒคํธ ํธ๋ค๋ฌ ํ
์คํธ | โ
60% | onPress, onClick ๋ฑ ๊ฐ์ง |
|
|
416
|
+
| Hook ํ
์คํธ | โ
50% | useState, useEffect ๋ฑ ๊ฐ์ง |
|
|
417
|
+
| **๋น์ฆ๋์ค ๋ก์ง ํ
์คํธ** | โ 0% | **๊ฐ๋ฐ์ ์ง์ ์์ฑ ํ์** |
|
|
418
|
+
|
|
419
|
+
---
|
|
420
|
+
|
|
421
|
+
## ๐บ๏ธ ๋ก๋๋งต (Roadmap)
|
|
422
|
+
|
|
423
|
+
### โ
1๋จ๊ณ: MVP (v0.1.x) - ํ์ฌ
|
|
424
|
+
|
|
425
|
+
- [x] ํ๋ก์ ํธ ๊ตฌ์กฐ ์ค์
|
|
426
|
+
- [x] AST ํ์ ๊ตฌํ (Babel ๊ธฐ๋ฐ)
|
|
427
|
+
- [x] CLI ์ธํฐํ์ด์ค (commander)
|
|
428
|
+
- [x] ๊ธฐ๋ณธ ํ
์คํธ ์์ฑ๊ธฐ
|
|
429
|
+
- [x] React ์ปดํฌ๋ํธ
|
|
430
|
+
- [x] React Native ์ปดํฌ๋ํธ
|
|
431
|
+
- [x] JavaScript/TypeScript ํจ์
|
|
432
|
+
- [x] EJS ํ
ํ๋ฆฟ ์์คํ
|
|
433
|
+
- [x] GitHub Actions CI/CD
|
|
434
|
+
- [x] npm ์๋ ํผ๋ธ๋ฆฌ์
|
|
435
|
+
|
|
436
|
+
### ๐ 2๋จ๊ณ: ํ์ฅ (v0.2.x)
|
|
437
|
+
|
|
438
|
+
- [ ] ๋๋ ํ ๋ฆฌ ์ค์บ ๋ฐ ์ผ๊ด ์์ฑ (`scan` ๋ช
๋ น์ด)
|
|
439
|
+
- [ ] ์ค์ ํ์ผ ์ง์ (`.testgenrc.js`)
|
|
440
|
+
- [ ] Node.js ๋ฐฑ์๋ ์ง์
|
|
441
|
+
- [ ] Mock ์๋ ์์ฑ ๊ฐ์
|
|
442
|
+
- [ ] Prettier/ESLint ์ฐ๋
|
|
443
|
+
- [ ] Watch ๋ชจ๋
|
|
444
|
+
- [ ] ์ปค์คํ
ํ
ํ๋ฆฟ ์ง์
|
|
445
|
+
|
|
446
|
+
### ๐ฎ 3๋จ๊ณ: ํ๋ฌ๊ทธ์ธ ์์คํ
(v0.3.x+)
|
|
447
|
+
|
|
448
|
+
- [ ] ํ๋ฌ๊ทธ์ธ ์ํคํ
์ฒ
|
|
449
|
+
- [ ] Vue.js ํ๋ฌ๊ทธ์ธ
|
|
450
|
+
- [ ] Angular ํ๋ฌ๊ทธ์ธ
|
|
451
|
+
- [ ] VS Code ํ์ฅ
|
|
452
|
+
- [ ] AI ํตํฉ (์ ํ์ )
|
|
453
|
+
|
|
454
|
+
---
|
|
455
|
+
|
|
456
|
+
## ๐ ํ๋ก์ ํธ ๊ตฌ์กฐ
|
|
457
|
+
|
|
458
|
+
```
|
|
459
|
+
test-gen-js/
|
|
460
|
+
โโโ bin/
|
|
461
|
+
โ โโโ cli.js # CLI ์ง์
์
|
|
462
|
+
โโโ src/
|
|
463
|
+
โ โโโ index.ts # ๋ฉ์ธ export
|
|
464
|
+
โ โโโ cli.ts # CLI ๋ก์ง (commander)
|
|
465
|
+
โ โโโ types.ts # TypeScript ํ์
์ ์
|
|
466
|
+
โ โโโ analyzer/
|
|
467
|
+
โ โ โโโ index.ts
|
|
468
|
+
โ โ โโโ fileAnalyzer.ts # ํ์ผ ๋ถ์ ๋ฉ์ธ
|
|
469
|
+
โ โ โโโ componentAnalyzer.ts # React ์ปดํฌ๋ํธ ๋ถ์
|
|
470
|
+
โ โ โโโ functionAnalyzer.ts # ํจ์ ๋ถ์
|
|
471
|
+
โ โโโ parser/
|
|
472
|
+
โ โ โโโ index.ts
|
|
473
|
+
โ โ โโโ astParser.ts # Babel AST ํ์ฑ
|
|
474
|
+
โ โ โโโ typeExtractor.ts # TypeScript ํ์
์ถ์ถ
|
|
475
|
+
โ โโโ generator/
|
|
476
|
+
โ โ โโโ index.ts
|
|
477
|
+
โ โ โโโ testGenerator.ts # ํ
์คํธ ์ฝ๋ ์์ฑ
|
|
478
|
+
โ โ โโโ mockGenerator.ts # Mock ์ฝ๋ ์์ฑ
|
|
479
|
+
โ โโโ templates/
|
|
480
|
+
โ โ โโโ component.ejs # ์ปดํฌ๋ํธ ํ
์คํธ ํ
ํ๋ฆฟ
|
|
481
|
+
โ โ โโโ function.ejs # ํจ์ ํ
์คํธ ํ
ํ๋ฆฟ
|
|
482
|
+
โ โ โโโ snapshot.ejs # ์ค๋
์ท ํ
์คํธ ํ
ํ๋ฆฟ
|
|
483
|
+
โ โโโ utils/
|
|
484
|
+
โ โโโ fileUtils.ts # ํ์ผ ์ ํธ๋ฆฌํฐ
|
|
485
|
+
โ โโโ naming.ts # ๋ค์ด๋ฐ ์ ํธ๋ฆฌํฐ
|
|
486
|
+
โโโ .github/
|
|
487
|
+
โ โโโ workflows/
|
|
488
|
+
โ โโโ ci.yml # CI (๋น๋/ํ
์คํธ)
|
|
489
|
+
โ โโโ publish.yml # npm ์๋ ํผ๋ธ๋ฆฌ์
|
|
490
|
+
โโโ package.json
|
|
491
|
+
โโโ tsconfig.json
|
|
492
|
+
โโโ README.md
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
---
|
|
496
|
+
|
|
497
|
+
## ๐ค ๊ธฐ์ฌํ๊ธฐ (Contributing)
|
|
498
|
+
|
|
499
|
+
๊ธฐ์ฌ๋ ์ธ์ ๋ ํ์ํฉ๋๋ค!
|
|
500
|
+
|
|
501
|
+
### ๊ธฐ์ฌ ๋ฐฉ๋ฒ
|
|
502
|
+
|
|
503
|
+
1. ๐ด Fork the repository
|
|
504
|
+
2. ๐ฟ Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
505
|
+
3. ๐พ Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
506
|
+
4. ๐ค Push to the branch (`git push origin feature/amazing-feature`)
|
|
507
|
+
5. ๐ Open a Pull Request
|
|
508
|
+
|
|
509
|
+
### ๊ธฐ์ฌ ์ ํ
|
|
510
|
+
|
|
511
|
+
- ๐ ๋ฒ๊ทธ ๋ฆฌํฌํธ
|
|
512
|
+
- ๐ก ๊ธฐ๋ฅ ์ ์
|
|
513
|
+
- ๐ ๋ฌธ์ ๊ฐ์
|
|
514
|
+
- ๐ง ์ฝ๋ ๊ธฐ์ฌ
|
|
515
|
+
- ๐ ๋ฒ์ญ
|
|
516
|
+
|
|
517
|
+
---
|
|
518
|
+
|
|
519
|
+
## ๐ ๋ผ์ด์ ์ค (License)
|
|
520
|
+
|
|
521
|
+
MIT License - ์์ ๋กญ๊ฒ ์ฌ์ฉ, ์์ , ๋ฐฐํฌํ ์ ์์ต๋๋ค.
|
|
522
|
+
|
|
523
|
+
---
|
|
524
|
+
|
|
525
|
+
## ๐ ๊ฐ์ฌ์ ๊ธ (Acknowledgments)
|
|
526
|
+
|
|
527
|
+
- [Babel](https://babeljs.io/) - JavaScript AST ํ์ฑ
|
|
528
|
+
- [Jest](https://jestjs.io/) - ํ
์คํธ ํ๋ ์์ํฌ
|
|
529
|
+
- [Testing Library](https://testing-library.com/) - ํ
์คํธ ์ ํธ๋ฆฌํฐ
|
|
530
|
+
- [Commander.js](https://github.com/tj/commander.js) - CLI ํ๋ ์์ํฌ
|
|
531
|
+
- [EJS](https://ejs.co/) - ํ
ํ๋ฆฟ ์์ง
|
|
532
|
+
|
|
533
|
+
---
|
|
534
|
+
|
|
535
|
+
## ๐ ๋ฌธ์ (Contact)
|
|
536
|
+
|
|
537
|
+
- GitHub Issues: [https://github.com/liveforownhappiness/test-gen-js-/issues](https://github.com/liveforownhappiness/test-gen-js-/issues)
|
|
538
|
+
- npm: [https://www.npmjs.com/package/test-gen-js](https://www.npmjs.com/package/test-gen-js)
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component Analyzer
|
|
3
|
+
* Extracts information from React/React Native components
|
|
4
|
+
*/
|
|
5
|
+
import type { NodePath } from '@babel/traverse';
|
|
6
|
+
import * as t from '@babel/types';
|
|
7
|
+
import type { ComponentInfo } from '../types';
|
|
8
|
+
/**
|
|
9
|
+
* Analyze a component and extract its information
|
|
10
|
+
*/
|
|
11
|
+
export declare function analyzeComponent(nodePath: NodePath<t.FunctionDeclaration | t.VariableDeclarator>, filePath: string): ComponentInfo | null;
|
|
12
|
+
//# sourceMappingURL=componentAnalyzer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"componentAnalyzer.d.ts","sourceRoot":"","sources":["../../src/analyzer/componentAnalyzer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,OAAO,KAAK,EAAE,aAAa,EAAY,MAAM,UAAU,CAAC;AAExD;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,mBAAmB,GAAG,CAAC,CAAC,kBAAkB,CAAC,EAChE,QAAQ,EAAE,MAAM,GACf,aAAa,GAAG,IAAI,CAgDtB"}
|