test-gen-js 0.1.2 โ 0.2.0
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 +26 -2
- package/README.md +216 -143
- package/dist/cli.js +10 -7
- package/dist/cli.js.map +1 -1
- package/dist/commands/index.d.ts +5 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +9 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/init.d.ts +14 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +232 -0
- package/dist/commands/init.js.map +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,9 +9,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
### Planned
|
|
11
11
|
- Directory scanning (`scan` command)
|
|
12
|
-
- Configuration file support (`.testgenrc.js`)
|
|
13
12
|
- Node.js backend support
|
|
14
13
|
- Custom templates
|
|
14
|
+
- Watch mode
|
|
15
|
+
- Prettier/ESLint integration
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## [0.2.0] - 2024-01-07
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
- ๐ `init` command - Initialize test-gen-js configuration
|
|
23
|
+
- Creates `.testgenrc.js` configuration file
|
|
24
|
+
- Sets up Git hooks with husky and lint-staged
|
|
25
|
+
- Pre-commit hook runs tests automatically before each commit
|
|
26
|
+
- Configuration file support (`.testgenrc.js`)
|
|
27
|
+
|
|
28
|
+
### Commands
|
|
29
|
+
- `test-gen-js init` - Initialize configuration and Git hooks
|
|
30
|
+
- `--no-hooks` - Skip Git hooks setup
|
|
31
|
+
- `--force` - Overwrite existing configuration
|
|
32
|
+
|
|
33
|
+
### How Pre-commit Testing Works
|
|
34
|
+
1. Run `npx test-gen-js init` in your project
|
|
35
|
+
2. Husky and lint-staged are automatically installed
|
|
36
|
+
3. When you run `git commit`, tests run for staged files
|
|
37
|
+
4. If tests pass, commit proceeds; if tests fail, commit is blocked
|
|
15
38
|
|
|
16
39
|
---
|
|
17
40
|
|
|
@@ -65,7 +88,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
65
88
|
|
|
66
89
|
---
|
|
67
90
|
|
|
68
|
-
[Unreleased]: https://github.com/liveforownhappiness/test-gen-js/compare/v0.
|
|
91
|
+
[Unreleased]: https://github.com/liveforownhappiness/test-gen-js/compare/v0.2.0...HEAD
|
|
92
|
+
[0.2.0]: https://github.com/liveforownhappiness/test-gen-js/compare/v0.1.0...v0.2.0
|
|
69
93
|
[0.1.0]: https://github.com/liveforownhappiness/test-gen-js/releases/tag/v0.1.0
|
|
70
94
|
[0.0.1]: https://github.com/liveforownhappiness/test-gen-js/releases/tag/v0.0.1
|
|
71
95
|
|
package/README.md
CHANGED
|
@@ -8,50 +8,88 @@
|
|
|
8
8
|
|
|
9
9
|
---
|
|
10
10
|
|
|
11
|
-
## ๐ฏ
|
|
11
|
+
## ๐ฏ Goal
|
|
12
12
|
|
|
13
|
-
> **"
|
|
13
|
+
> **"From zero tests to having basic tests"**
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
This library is not about perfect test automation, but about **lowering the barrier to writing tests**.
|
|
16
16
|
|
|
17
|
-
###
|
|
17
|
+
### Problems This Tool Solves
|
|
18
18
|
|
|
19
|
-
|
|
|
20
|
-
|
|
21
|
-
| ๐ซ "
|
|
22
|
-
| ๐ค "
|
|
23
|
-
| ๐ฐ "
|
|
24
|
-
| ๐ "
|
|
19
|
+
| Problem | Solution |
|
|
20
|
+
|---------|----------|
|
|
21
|
+
| ๐ซ "Creating test files is tedious" | โ
Auto-generate boilerplate |
|
|
22
|
+
| ๐ค "I don't know how to start" | โ
Provide a working starting point |
|
|
23
|
+
| ๐ฐ "I don't even have basic render tests" | โ
Provide minimal safety net |
|
|
24
|
+
| ๐ "I want to learn how to write tests" | โ
Use as a learning tool |
|
|
25
25
|
|
|
26
|
-
###
|
|
26
|
+
### Limitations
|
|
27
27
|
|
|
28
28
|
```
|
|
29
|
-
โ
|
|
30
|
-
โ
|
|
29
|
+
โ Auto-generate business logic tests โ Developers must write these
|
|
30
|
+
โ Perfect test coverage โ Not possible (80% boilerplate, 20% manual)
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
---
|
|
34
34
|
|
|
35
|
-
## ๐ฆ
|
|
35
|
+
## ๐ฆ Installation
|
|
36
36
|
|
|
37
37
|
```bash
|
|
38
|
-
#
|
|
38
|
+
# Global installation
|
|
39
39
|
npm install -g test-gen-js
|
|
40
40
|
|
|
41
|
-
#
|
|
41
|
+
# Or use with npx (no installation required)
|
|
42
42
|
npx test-gen-js generate src/components/Button.tsx
|
|
43
43
|
|
|
44
|
-
#
|
|
44
|
+
# Or install as devDependency
|
|
45
45
|
npm install -D test-gen-js
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
---
|
|
49
49
|
|
|
50
|
-
##
|
|
50
|
+
## ๐ ๏ธ Setup with Git Hooks (Recommended)
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
Set up automatic testing before each commit:
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
```bash
|
|
55
|
+
# 1. Install as dev dependency
|
|
56
|
+
npm install -D test-gen-js
|
|
57
|
+
|
|
58
|
+
# 2. Initialize (creates config + sets up Git hooks)
|
|
59
|
+
npx test-gen-js init
|
|
60
|
+
|
|
61
|
+
# 3. Generate tests for your components
|
|
62
|
+
npx test-gen-js generate src/components/Button.tsx
|
|
63
|
+
|
|
64
|
+
# 4. Now when you commit, tests run automatically!
|
|
65
|
+
git add .
|
|
66
|
+
git commit -m "feat: add Button component"
|
|
67
|
+
# ๐งช Running tests before commit...
|
|
68
|
+
# โ
Tests passed!
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### What `init` Does
|
|
72
|
+
|
|
73
|
+
| Item | Description |
|
|
74
|
+
|------|-------------|
|
|
75
|
+
| `.testgenrc.js` | Creates configuration file |
|
|
76
|
+
| `husky` | Installs Git hooks manager |
|
|
77
|
+
| `lint-staged` | Runs tests on staged files only |
|
|
78
|
+
| `pre-commit` | Tests run before each commit |
|
|
79
|
+
|
|
80
|
+
### Pre-commit Behavior
|
|
81
|
+
|
|
82
|
+
- โ
Tests pass โ Commit proceeds
|
|
83
|
+
- โ Tests fail โ Commit is **blocked**
|
|
84
|
+
- โญ๏ธ Skip with `git commit --no-verify` (not recommended)
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## ๐ Quick Start
|
|
89
|
+
|
|
90
|
+
### 1. Generate React Component Tests
|
|
91
|
+
|
|
92
|
+
**Input: `src/components/Button.tsx`**
|
|
55
93
|
|
|
56
94
|
```tsx
|
|
57
95
|
import React from 'react';
|
|
@@ -72,13 +110,13 @@ export const Button = ({ title, onPress, disabled = false, loading = false }: Bu
|
|
|
72
110
|
};
|
|
73
111
|
```
|
|
74
112
|
|
|
75
|
-
|
|
113
|
+
**Run command:**
|
|
76
114
|
|
|
77
115
|
```bash
|
|
78
116
|
npx test-gen-js generate src/components/Button.tsx
|
|
79
117
|
```
|
|
80
118
|
|
|
81
|
-
|
|
119
|
+
**Output: `src/components/Button.test.tsx`**
|
|
82
120
|
|
|
83
121
|
```tsx
|
|
84
122
|
import React from 'react';
|
|
@@ -120,9 +158,9 @@ describe('Button', () => {
|
|
|
120
158
|
|
|
121
159
|
---
|
|
122
160
|
|
|
123
|
-
### 2. React Native
|
|
161
|
+
### 2. Generate React Native Component Tests
|
|
124
162
|
|
|
125
|
-
|
|
163
|
+
**Input: `src/components/Card.tsx`**
|
|
126
164
|
|
|
127
165
|
```tsx
|
|
128
166
|
import React, { useState } from 'react';
|
|
@@ -152,13 +190,13 @@ const styles = StyleSheet.create({
|
|
|
152
190
|
});
|
|
153
191
|
```
|
|
154
192
|
|
|
155
|
-
|
|
193
|
+
**Run command:**
|
|
156
194
|
|
|
157
195
|
```bash
|
|
158
196
|
npx test-gen-js generate src/components/Card.tsx --snapshot
|
|
159
197
|
```
|
|
160
198
|
|
|
161
|
-
|
|
199
|
+
**Output: `src/components/Card.test.tsx`**
|
|
162
200
|
|
|
163
201
|
```tsx
|
|
164
202
|
import React from 'react';
|
|
@@ -203,9 +241,9 @@ describe('Card', () => {
|
|
|
203
241
|
|
|
204
242
|
---
|
|
205
243
|
|
|
206
|
-
### 3.
|
|
244
|
+
### 3. Generate Function Tests
|
|
207
245
|
|
|
208
|
-
|
|
246
|
+
**Input: `src/utils/calculate.ts`**
|
|
209
247
|
|
|
210
248
|
```typescript
|
|
211
249
|
export function calculateDiscount(price: number, discountRate: number): number {
|
|
@@ -221,13 +259,13 @@ export async function fetchUserData(userId: string): Promise<User> {
|
|
|
221
259
|
}
|
|
222
260
|
```
|
|
223
261
|
|
|
224
|
-
|
|
262
|
+
**Run command:**
|
|
225
263
|
|
|
226
264
|
```bash
|
|
227
265
|
npx test-gen-js generate src/utils/calculate.ts
|
|
228
266
|
```
|
|
229
267
|
|
|
230
|
-
|
|
268
|
+
**Output: `src/utils/calculate.test.ts`**
|
|
231
269
|
|
|
232
270
|
```typescript
|
|
233
271
|
import { calculateDiscount, fetchUserData } from './calculate';
|
|
@@ -279,88 +317,122 @@ describe('fetchUserData', () => {
|
|
|
279
317
|
|
|
280
318
|
---
|
|
281
319
|
|
|
282
|
-
## ๐ CLI
|
|
320
|
+
## ๐ CLI Commands
|
|
283
321
|
|
|
284
|
-
### `generate` (
|
|
322
|
+
### `generate` (alias: `g`)
|
|
285
323
|
|
|
286
|
-
|
|
324
|
+
Generate tests for a single file
|
|
287
325
|
|
|
288
326
|
```bash
|
|
289
|
-
#
|
|
327
|
+
# Basic usage
|
|
290
328
|
test-gen-js generate <file>
|
|
291
329
|
tgjs g <file>
|
|
292
330
|
|
|
293
|
-
#
|
|
294
|
-
--output, -o <path> #
|
|
295
|
-
--template, -t <type> #
|
|
296
|
-
--snapshot #
|
|
297
|
-
--mock #
|
|
298
|
-
--overwrite #
|
|
331
|
+
# Options
|
|
332
|
+
--output, -o <path> # Specify output file path
|
|
333
|
+
--template, -t <type> # Template type (component | function | hook)
|
|
334
|
+
--snapshot # Include snapshot tests
|
|
335
|
+
--mock # Auto-generate mocks (default: true)
|
|
336
|
+
--overwrite # Overwrite existing file
|
|
299
337
|
```
|
|
300
338
|
|
|
301
|
-
|
|
339
|
+
**Examples:**
|
|
302
340
|
|
|
303
341
|
```bash
|
|
304
|
-
#
|
|
342
|
+
# Basic generation
|
|
305
343
|
tgjs g src/components/Header.tsx
|
|
306
344
|
|
|
307
|
-
#
|
|
345
|
+
# Include snapshot tests
|
|
308
346
|
tgjs g src/components/Header.tsx --snapshot
|
|
309
347
|
|
|
310
|
-
#
|
|
348
|
+
# Custom output path
|
|
311
349
|
tgjs g src/components/Header.tsx -o __tests__/Header.test.tsx
|
|
312
350
|
|
|
313
|
-
#
|
|
351
|
+
# Overwrite existing file
|
|
314
352
|
tgjs g src/components/Header.tsx --overwrite
|
|
315
353
|
```
|
|
316
354
|
|
|
317
|
-
### `scan` (
|
|
355
|
+
### `scan` (alias: `s`) - Coming in v0.2.0
|
|
318
356
|
|
|
319
|
-
|
|
357
|
+
Scan directory and generate tests for all files
|
|
320
358
|
|
|
321
359
|
```bash
|
|
322
|
-
#
|
|
360
|
+
# Basic usage
|
|
323
361
|
test-gen-js scan <directory>
|
|
324
362
|
|
|
325
|
-
#
|
|
326
|
-
--dry-run #
|
|
327
|
-
--pattern <glob> #
|
|
328
|
-
--exclude <patterns> #
|
|
363
|
+
# Options
|
|
364
|
+
--dry-run # Preview without creating files
|
|
365
|
+
--pattern <glob> # File pattern (default: **/*.{ts,tsx,js,jsx})
|
|
366
|
+
--exclude <patterns> # Patterns to exclude
|
|
329
367
|
```
|
|
330
368
|
|
|
331
|
-
### `init`
|
|
369
|
+
### `init`
|
|
332
370
|
|
|
333
|
-
|
|
371
|
+
Initialize test-gen-js configuration and set up Git hooks for pre-commit testing.
|
|
334
372
|
|
|
335
373
|
```bash
|
|
374
|
+
# Basic usage - creates config and sets up Git hooks
|
|
336
375
|
test-gen-js init
|
|
376
|
+
|
|
377
|
+
# Options
|
|
378
|
+
--no-hooks # Skip Git hooks setup
|
|
379
|
+
--force # Overwrite existing configuration
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
**What it does:**
|
|
383
|
+
|
|
384
|
+
1. Creates `.testgenrc.js` configuration file
|
|
385
|
+
2. Installs `husky` and `lint-staged` (if not present)
|
|
386
|
+
3. Sets up pre-commit hook to run tests before each commit
|
|
387
|
+
|
|
388
|
+
**Example:**
|
|
389
|
+
|
|
390
|
+
```bash
|
|
391
|
+
# Install test-gen-js as dev dependency
|
|
392
|
+
npm install -D test-gen-js
|
|
393
|
+
|
|
394
|
+
# Initialize (sets up Git hooks)
|
|
395
|
+
npx test-gen-js init
|
|
396
|
+
|
|
397
|
+
# Now when you commit, tests will run automatically!
|
|
398
|
+
git add .
|
|
399
|
+
git commit -m "feat: add new component"
|
|
400
|
+
# ๐งช Running tests before commit...
|
|
401
|
+
# โ
Tests passed, commit successful!
|
|
337
402
|
```
|
|
338
403
|
|
|
404
|
+
**Pre-commit behavior:**
|
|
405
|
+
|
|
406
|
+
- Tests run only for **staged files** (files you're committing)
|
|
407
|
+
- If tests fail, commit is **blocked**
|
|
408
|
+
- If tests pass, commit proceeds normally
|
|
409
|
+
- Use `git commit --no-verify` to skip tests (not recommended)
|
|
410
|
+
|
|
339
411
|
---
|
|
340
412
|
|
|
341
|
-
## ๐
|
|
413
|
+
## ๐ Supported Types
|
|
342
414
|
|
|
343
|
-
|
|
|
344
|
-
|
|
345
|
-
| JavaScript
|
|
346
|
-
| TypeScript
|
|
347
|
-
| React
|
|
348
|
-
| React Native
|
|
415
|
+
| Type | Support | Test Framework | Notes |
|
|
416
|
+
|------|---------|----------------|-------|
|
|
417
|
+
| JavaScript functions | โ
| Jest | |
|
|
418
|
+
| TypeScript functions | โ
| Jest | Type analysis supported |
|
|
419
|
+
| React components | โ
| Jest + @testing-library/react | |
|
|
420
|
+
| React Native components | โ
| Jest + @testing-library/react-native | |
|
|
349
421
|
| Custom Hooks | โ
| Jest + @testing-library/react-hooks | |
|
|
350
|
-
| Node.js
|
|
351
|
-
| Express
|
|
352
|
-
| Vue
|
|
353
|
-
| Angular
|
|
422
|
+
| Node.js modules | ๐ v0.2 | Jest | |
|
|
423
|
+
| Express handlers | ๐ v0.2 | Jest + supertest | |
|
|
424
|
+
| Vue components | ๐ Plugin | Vitest | |
|
|
425
|
+
| Angular components | ๐ Plugin | Jasmine | |
|
|
354
426
|
|
|
355
427
|
---
|
|
356
428
|
|
|
357
|
-
## ๐ง
|
|
429
|
+
## ๐ง How It Works
|
|
358
430
|
|
|
359
|
-
### AST (Abstract Syntax Tree)
|
|
431
|
+
### AST (Abstract Syntax Tree) Analysis
|
|
360
432
|
|
|
361
433
|
```
|
|
362
434
|
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
363
|
-
โ 1.
|
|
435
|
+
โ 1. Input: Button.tsx โ
|
|
364
436
|
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
|
|
365
437
|
โ export const Button = ({ title, onPress, disabled }) => { โ
|
|
366
438
|
โ const [loading, setLoading] = useState(false); โ
|
|
@@ -374,7 +446,7 @@ test-gen-js init
|
|
|
374
446
|
โ
|
|
375
447
|
โผ Babel Parser
|
|
376
448
|
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
377
|
-
โ 2. AST
|
|
449
|
+
โ 2. AST Analysis Result โ
|
|
378
450
|
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
|
|
379
451
|
โ { โ
|
|
380
452
|
โ name: "Button", โ
|
|
@@ -392,7 +464,7 @@ test-gen-js init
|
|
|
392
464
|
โ
|
|
393
465
|
โผ EJS Template
|
|
394
466
|
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
395
|
-
โ 3.
|
|
467
|
+
โ 3. Output: Button.test.tsx โ
|
|
396
468
|
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
|
|
397
469
|
โ describe('Button', () => { โ
|
|
398
470
|
โ const defaultProps = { title: '...', onPress: jest.fn() }; โ
|
|
@@ -403,90 +475,91 @@ test-gen-js init
|
|
|
403
475
|
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
404
476
|
```
|
|
405
477
|
|
|
406
|
-
###
|
|
478
|
+
### Automation Coverage
|
|
407
479
|
|
|
408
|
-
|
|
|
409
|
-
|
|
410
|
-
|
|
|
411
|
-
| describe/it
|
|
412
|
-
| defaultProps
|
|
413
|
-
| Mock
|
|
414
|
-
|
|
|
415
|
-
|
|
|
416
|
-
| Hook
|
|
417
|
-
|
|
|
480
|
+
| Area | Automation Level | Description |
|
|
481
|
+
|------|------------------|-------------|
|
|
482
|
+
| Import statements | โ
100% | Auto-detect framework |
|
|
483
|
+
| describe/it structure | โ
100% | Based on component/function name |
|
|
484
|
+
| defaultProps generation | โ
80% | TypeScript type analysis |
|
|
485
|
+
| Mock setup | โ
70% | Auto-detect major libraries |
|
|
486
|
+
| Render tests | โ
100% | Always provided |
|
|
487
|
+
| Event handler tests | โ
60% | Detect onPress, onClick, etc. |
|
|
488
|
+
| Hook tests | โ
50% | Detect useState, useEffect, etc. |
|
|
489
|
+
| **Business logic tests** | โ 0% | **Developer must write** |
|
|
418
490
|
|
|
419
491
|
---
|
|
420
492
|
|
|
421
|
-
## ๐บ๏ธ
|
|
493
|
+
## ๐บ๏ธ Roadmap
|
|
422
494
|
|
|
423
|
-
### โ
1
|
|
495
|
+
### โ
Phase 1: MVP (v0.1.x) - Current
|
|
424
496
|
|
|
425
|
-
- [x]
|
|
426
|
-
- [x] AST
|
|
427
|
-
- [x] CLI
|
|
428
|
-
- [x]
|
|
429
|
-
- [x] React
|
|
430
|
-
- [x] React Native
|
|
431
|
-
- [x] JavaScript/TypeScript
|
|
432
|
-
- [x] EJS
|
|
497
|
+
- [x] Project structure setup
|
|
498
|
+
- [x] AST parser implementation (Babel-based)
|
|
499
|
+
- [x] CLI interface (commander)
|
|
500
|
+
- [x] Basic test generator
|
|
501
|
+
- [x] React components
|
|
502
|
+
- [x] React Native components
|
|
503
|
+
- [x] JavaScript/TypeScript functions
|
|
504
|
+
- [x] EJS template system
|
|
433
505
|
- [x] GitHub Actions CI/CD
|
|
434
|
-
- [x] npm
|
|
506
|
+
- [x] Automated npm publishing
|
|
435
507
|
|
|
436
|
-
### ๐ 2
|
|
508
|
+
### ๐ Phase 2: Extended Features (v0.2.x)
|
|
437
509
|
|
|
438
|
-
- [ ]
|
|
439
|
-
- [
|
|
440
|
-
- [
|
|
441
|
-
- [ ]
|
|
442
|
-
- [ ]
|
|
443
|
-
- [ ]
|
|
444
|
-
- [ ]
|
|
510
|
+
- [ ] Directory scanning and batch generation (`scan` command)
|
|
511
|
+
- [x] Configuration file support (`.testgenrc.js`)
|
|
512
|
+
- [x] Git hooks for pre-commit testing (`init` command)
|
|
513
|
+
- [ ] Node.js backend support
|
|
514
|
+
- [ ] Improved mock generation
|
|
515
|
+
- [ ] Prettier/ESLint integration
|
|
516
|
+
- [ ] Watch mode
|
|
517
|
+
- [ ] Custom template support
|
|
445
518
|
|
|
446
|
-
### ๐ฎ 3
|
|
519
|
+
### ๐ฎ Phase 3: Plugin System (v0.3.x+)
|
|
447
520
|
|
|
448
|
-
- [ ]
|
|
449
|
-
- [ ] Vue.js
|
|
450
|
-
- [ ] Angular
|
|
451
|
-
- [ ] VS Code
|
|
452
|
-
- [ ] AI
|
|
521
|
+
- [ ] Plugin architecture
|
|
522
|
+
- [ ] Vue.js plugin
|
|
523
|
+
- [ ] Angular plugin
|
|
524
|
+
- [ ] VS Code extension
|
|
525
|
+
- [ ] AI integration (optional)
|
|
453
526
|
|
|
454
527
|
---
|
|
455
528
|
|
|
456
|
-
## ๐
|
|
529
|
+
## ๐ Project Structure
|
|
457
530
|
|
|
458
531
|
```
|
|
459
532
|
test-gen-js/
|
|
460
533
|
โโโ bin/
|
|
461
|
-
โ โโโ cli.js # CLI
|
|
534
|
+
โ โโโ cli.js # CLI entry point
|
|
462
535
|
โโโ src/
|
|
463
|
-
โ โโโ index.ts #
|
|
464
|
-
โ โโโ cli.ts # CLI
|
|
465
|
-
โ โโโ types.ts # TypeScript
|
|
536
|
+
โ โโโ index.ts # Main exports
|
|
537
|
+
โ โโโ cli.ts # CLI logic (commander)
|
|
538
|
+
โ โโโ types.ts # TypeScript type definitions
|
|
466
539
|
โ โโโ analyzer/
|
|
467
540
|
โ โ โโโ index.ts
|
|
468
|
-
โ โ โโโ fileAnalyzer.ts #
|
|
469
|
-
โ โ โโโ componentAnalyzer.ts # React
|
|
470
|
-
โ โ โโโ functionAnalyzer.ts #
|
|
541
|
+
โ โ โโโ fileAnalyzer.ts # Main file analysis
|
|
542
|
+
โ โ โโโ componentAnalyzer.ts # React component analysis
|
|
543
|
+
โ โ โโโ functionAnalyzer.ts # Function analysis
|
|
471
544
|
โ โโโ parser/
|
|
472
545
|
โ โ โโโ index.ts
|
|
473
|
-
โ โ โโโ astParser.ts # Babel AST
|
|
474
|
-
โ โ โโโ typeExtractor.ts # TypeScript
|
|
546
|
+
โ โ โโโ astParser.ts # Babel AST parsing
|
|
547
|
+
โ โ โโโ typeExtractor.ts # TypeScript type extraction
|
|
475
548
|
โ โโโ generator/
|
|
476
549
|
โ โ โโโ index.ts
|
|
477
|
-
โ โ โโโ testGenerator.ts #
|
|
478
|
-
โ โ โโโ mockGenerator.ts # Mock
|
|
550
|
+
โ โ โโโ testGenerator.ts # Test code generation
|
|
551
|
+
โ โ โโโ mockGenerator.ts # Mock code generation
|
|
479
552
|
โ โโโ templates/
|
|
480
|
-
โ โ โโโ component.ejs #
|
|
481
|
-
โ โ โโโ function.ejs #
|
|
482
|
-
โ โ โโโ snapshot.ejs #
|
|
553
|
+
โ โ โโโ component.ejs # Component test template
|
|
554
|
+
โ โ โโโ function.ejs # Function test template
|
|
555
|
+
โ โ โโโ snapshot.ejs # Snapshot test template
|
|
483
556
|
โ โโโ utils/
|
|
484
|
-
โ โโโ fileUtils.ts #
|
|
485
|
-
โ โโโ naming.ts #
|
|
557
|
+
โ โโโ fileUtils.ts # File utilities
|
|
558
|
+
โ โโโ naming.ts # Naming utilities
|
|
486
559
|
โโโ .github/
|
|
487
560
|
โ โโโ workflows/
|
|
488
|
-
โ โโโ ci.yml # CI (
|
|
489
|
-
โ โโโ publish.yml # npm
|
|
561
|
+
โ โโโ ci.yml # CI (build/test)
|
|
562
|
+
โ โโโ publish.yml # Automated npm publish
|
|
490
563
|
โโโ package.json
|
|
491
564
|
โโโ tsconfig.json
|
|
492
565
|
โโโ README.md
|
|
@@ -494,11 +567,11 @@ test-gen-js/
|
|
|
494
567
|
|
|
495
568
|
---
|
|
496
569
|
|
|
497
|
-
## ๐ค
|
|
570
|
+
## ๐ค Contributing
|
|
498
571
|
|
|
499
|
-
|
|
572
|
+
Contributions are always welcome!
|
|
500
573
|
|
|
501
|
-
###
|
|
574
|
+
### How to Contribute
|
|
502
575
|
|
|
503
576
|
1. ๐ด Fork the repository
|
|
504
577
|
2. ๐ฟ Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
@@ -506,33 +579,33 @@ test-gen-js/
|
|
|
506
579
|
4. ๐ค Push to the branch (`git push origin feature/amazing-feature`)
|
|
507
580
|
5. ๐ Open a Pull Request
|
|
508
581
|
|
|
509
|
-
###
|
|
582
|
+
### Types of Contributions
|
|
510
583
|
|
|
511
|
-
- ๐
|
|
512
|
-
- ๐ก
|
|
513
|
-
- ๐
|
|
514
|
-
- ๐ง
|
|
515
|
-
- ๐
|
|
584
|
+
- ๐ Bug reports
|
|
585
|
+
- ๐ก Feature requests
|
|
586
|
+
- ๐ Documentation improvements
|
|
587
|
+
- ๐ง Code contributions
|
|
588
|
+
- ๐ Translations
|
|
516
589
|
|
|
517
590
|
---
|
|
518
591
|
|
|
519
|
-
## ๐
|
|
592
|
+
## ๐ License
|
|
520
593
|
|
|
521
|
-
MIT License -
|
|
594
|
+
MIT License - Feel free to use, modify, and distribute.
|
|
522
595
|
|
|
523
596
|
---
|
|
524
597
|
|
|
525
|
-
## ๐
|
|
598
|
+
## ๐ Acknowledgments
|
|
526
599
|
|
|
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/) -
|
|
600
|
+
- [Babel](https://babeljs.io/) - JavaScript AST parsing
|
|
601
|
+
- [Jest](https://jestjs.io/) - Testing framework
|
|
602
|
+
- [Testing Library](https://testing-library.com/) - Testing utilities
|
|
603
|
+
- [Commander.js](https://github.com/tj/commander.js) - CLI framework
|
|
604
|
+
- [EJS](https://ejs.co/) - Template engine
|
|
532
605
|
|
|
533
606
|
---
|
|
534
607
|
|
|
535
|
-
## ๐
|
|
608
|
+
## ๐ Contact
|
|
536
609
|
|
|
537
610
|
- GitHub Issues: [https://github.com/liveforownhappiness/test-gen-js/issues](https://github.com/liveforownhappiness/test-gen-js/issues)
|
|
538
611
|
- npm: [https://www.npmjs.com/package/test-gen-js](https://www.npmjs.com/package/test-gen-js)
|
package/dist/cli.js
CHANGED
|
@@ -9,6 +9,7 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
9
9
|
const ora_1 = __importDefault(require("ora"));
|
|
10
10
|
const analyzer_1 = require("./analyzer");
|
|
11
11
|
const generator_1 = require("./generator");
|
|
12
|
+
const commands_1 = require("./commands");
|
|
12
13
|
const program = new commander_1.Command();
|
|
13
14
|
program
|
|
14
15
|
.name('test-gen-js')
|
|
@@ -94,17 +95,19 @@ program
|
|
|
94
95
|
// Init command
|
|
95
96
|
program
|
|
96
97
|
.command('init')
|
|
97
|
-
.description('Initialize test-gen-js configuration')
|
|
98
|
-
.
|
|
99
|
-
|
|
98
|
+
.description('Initialize test-gen-js configuration and Git hooks')
|
|
99
|
+
.option('--no-hooks', 'Skip Git hooks setup')
|
|
100
|
+
.option('--force', 'Overwrite existing configuration', false)
|
|
101
|
+
.action(async (options) => {
|
|
100
102
|
try {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
+
await (0, commands_1.initCommand)({
|
|
104
|
+
hooks: options.hooks,
|
|
105
|
+
force: options.force,
|
|
106
|
+
});
|
|
103
107
|
}
|
|
104
108
|
catch (error) {
|
|
105
|
-
spinner.fail(chalk_1.default.red('Failed to create configuration'));
|
|
106
109
|
if (error instanceof Error) {
|
|
107
|
-
console.error(chalk_1.default.red(error.message));
|
|
110
|
+
console.error(chalk_1.default.red('Error: ' + error.message));
|
|
108
111
|
}
|
|
109
112
|
process.exit(1);
|
|
110
113
|
}
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AAEA,yCAAoC;AACpC,kDAA0B;AAC1B,8CAAsB;AACtB,yCAAyC;AACzC,2CAA2C;
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AAEA,yCAAoC;AACpC,kDAA0B;AAC1B,8CAAsB;AACtB,yCAAyC;AACzC,2CAA2C;AAC3C,yCAAyC;AAGzC,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,aAAa,CAAC;KACnB,WAAW,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,EAAE,MAAM,QAAQ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Commands module
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.initCommand = void 0;
|
|
7
|
+
var init_1 = require("./init");
|
|
8
|
+
Object.defineProperty(exports, "initCommand", { enumerable: true, get: function () { return init_1.initCommand; } });
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,+BAAqC;AAA5B,mGAAA,WAAW,OAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Init Command
|
|
3
|
+
* Sets up test-gen-js configuration and Git hooks for pre-commit testing
|
|
4
|
+
*/
|
|
5
|
+
interface InitOptions {
|
|
6
|
+
hooks?: boolean;
|
|
7
|
+
force?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Initialize test-gen-js in a project
|
|
11
|
+
*/
|
|
12
|
+
export declare function initCommand(options?: InitOptions): Promise<void>;
|
|
13
|
+
export default initCommand;
|
|
14
|
+
//# sourceMappingURL=init.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,UAAU,WAAW;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAC,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CA8B1E;AA8MD,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Init Command
|
|
4
|
+
* Sets up test-gen-js configuration and Git hooks for pre-commit testing
|
|
5
|
+
*/
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.initCommand = initCommand;
|
|
11
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
12
|
+
const path_1 = __importDefault(require("path"));
|
|
13
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
14
|
+
const ora_1 = __importDefault(require("ora"));
|
|
15
|
+
const child_process_1 = require("child_process");
|
|
16
|
+
/**
|
|
17
|
+
* Initialize test-gen-js in a project
|
|
18
|
+
*/
|
|
19
|
+
async function initCommand(options = {}) {
|
|
20
|
+
const { hooks = true, force = false } = options;
|
|
21
|
+
const cwd = process.cwd();
|
|
22
|
+
console.log('');
|
|
23
|
+
console.log(chalk_1.default.cyan('๐งช Initializing test-gen-js...'));
|
|
24
|
+
console.log('');
|
|
25
|
+
// Check if package.json exists
|
|
26
|
+
const packageJsonPath = path_1.default.join(cwd, 'package.json');
|
|
27
|
+
if (!(await fs_extra_1.default.pathExists(packageJsonPath))) {
|
|
28
|
+
throw new Error('package.json not found. Please run this command in a Node.js project.');
|
|
29
|
+
}
|
|
30
|
+
// Create configuration file
|
|
31
|
+
await createConfigFile(cwd, force);
|
|
32
|
+
// Setup Git hooks if requested
|
|
33
|
+
if (hooks) {
|
|
34
|
+
await setupGitHooks(cwd);
|
|
35
|
+
}
|
|
36
|
+
console.log('');
|
|
37
|
+
console.log(chalk_1.default.green('โ
test-gen-js initialized successfully!'));
|
|
38
|
+
console.log('');
|
|
39
|
+
console.log(chalk_1.default.cyan('Next steps:'));
|
|
40
|
+
console.log(' 1. Generate tests: ' + chalk_1.default.yellow('npx test-gen-js generate src/components/Button.tsx'));
|
|
41
|
+
console.log(' 2. Run tests: ' + chalk_1.default.yellow('npm test'));
|
|
42
|
+
console.log(' 3. Commit your code - tests will run automatically!');
|
|
43
|
+
console.log('');
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Create .testgenrc.js configuration file
|
|
47
|
+
*/
|
|
48
|
+
async function createConfigFile(cwd, force) {
|
|
49
|
+
const spinner = (0, ora_1.default)('Creating configuration file...').start();
|
|
50
|
+
const configPath = path_1.default.join(cwd, '.testgenrc.js');
|
|
51
|
+
if ((await fs_extra_1.default.pathExists(configPath)) && !force) {
|
|
52
|
+
spinner.info(chalk_1.default.yellow('.testgenrc.js already exists. Use --force to overwrite.'));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const configContent = `/**
|
|
56
|
+
* test-gen-js configuration
|
|
57
|
+
* @see https://github.com/liveforownhappiness/test-gen-js
|
|
58
|
+
*/
|
|
59
|
+
module.exports = {
|
|
60
|
+
// File patterns to include
|
|
61
|
+
include: ['src/**/*.{ts,tsx,js,jsx}'],
|
|
62
|
+
|
|
63
|
+
// File patterns to exclude
|
|
64
|
+
exclude: [
|
|
65
|
+
'node_modules',
|
|
66
|
+
'dist',
|
|
67
|
+
'build',
|
|
68
|
+
'**/*.test.*',
|
|
69
|
+
'**/*.spec.*',
|
|
70
|
+
'**/__tests__/**',
|
|
71
|
+
'**/__mocks__/**',
|
|
72
|
+
],
|
|
73
|
+
|
|
74
|
+
// Generator options
|
|
75
|
+
generator: {
|
|
76
|
+
// Include snapshot tests
|
|
77
|
+
snapshot: false,
|
|
78
|
+
|
|
79
|
+
// Auto-generate mocks
|
|
80
|
+
mock: true,
|
|
81
|
+
|
|
82
|
+
// Test file suffix (.test or .spec)
|
|
83
|
+
testSuffix: '.test',
|
|
84
|
+
|
|
85
|
+
// Overwrite existing test files
|
|
86
|
+
overwrite: false,
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
// Template options
|
|
90
|
+
templates: {
|
|
91
|
+
// Custom templates directory (optional)
|
|
92
|
+
// dir: './templates',
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
`;
|
|
96
|
+
await fs_extra_1.default.writeFile(configPath, configContent);
|
|
97
|
+
spinner.succeed(chalk_1.default.green('Created .testgenrc.js'));
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Setup Git hooks with husky and lint-staged
|
|
101
|
+
*/
|
|
102
|
+
async function setupGitHooks(cwd) {
|
|
103
|
+
const spinner = (0, ora_1.default)('Setting up Git hooks...').start();
|
|
104
|
+
const packageJsonPath = path_1.default.join(cwd, 'package.json');
|
|
105
|
+
try {
|
|
106
|
+
// Read package.json
|
|
107
|
+
const packageJson = await fs_extra_1.default.readJson(packageJsonPath);
|
|
108
|
+
// Check if husky is already installed
|
|
109
|
+
const hasHusky = packageJson.devDependencies?.husky || packageJson.dependencies?.husky;
|
|
110
|
+
const hasLintStaged = packageJson.devDependencies?.['lint-staged'] || packageJson.dependencies?.['lint-staged'];
|
|
111
|
+
// Install husky and lint-staged if not present
|
|
112
|
+
if (!hasHusky || !hasLintStaged) {
|
|
113
|
+
spinner.text = 'Installing husky and lint-staged...';
|
|
114
|
+
const packagesToInstall = [];
|
|
115
|
+
if (!hasHusky)
|
|
116
|
+
packagesToInstall.push('husky');
|
|
117
|
+
if (!hasLintStaged)
|
|
118
|
+
packagesToInstall.push('lint-staged');
|
|
119
|
+
try {
|
|
120
|
+
(0, child_process_1.execSync)(`npm install -D ${packagesToInstall.join(' ')}`, {
|
|
121
|
+
cwd,
|
|
122
|
+
stdio: 'pipe',
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
spinner.warn(chalk_1.default.yellow('Could not install packages automatically. Please run:'));
|
|
127
|
+
console.log(chalk_1.default.cyan(` npm install -D ${packagesToInstall.join(' ')}`));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// Re-read package.json after potential install
|
|
131
|
+
const updatedPackageJson = await fs_extra_1.default.readJson(packageJsonPath);
|
|
132
|
+
// Add lint-staged configuration
|
|
133
|
+
if (!updatedPackageJson['lint-staged']) {
|
|
134
|
+
updatedPackageJson['lint-staged'] = {
|
|
135
|
+
'*.{ts,tsx,js,jsx}': ['npm test -- --bail --findRelatedTests --passWithNoTests'],
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
// Add prepare script for husky
|
|
139
|
+
if (!updatedPackageJson.scripts) {
|
|
140
|
+
updatedPackageJson.scripts = {};
|
|
141
|
+
}
|
|
142
|
+
if (!updatedPackageJson.scripts.prepare) {
|
|
143
|
+
updatedPackageJson.scripts.prepare = 'husky install';
|
|
144
|
+
}
|
|
145
|
+
// Write updated package.json
|
|
146
|
+
await fs_extra_1.default.writeJson(packageJsonPath, updatedPackageJson, { spaces: 2 });
|
|
147
|
+
// Initialize husky
|
|
148
|
+
spinner.text = 'Initializing husky...';
|
|
149
|
+
const huskyDir = path_1.default.join(cwd, '.husky');
|
|
150
|
+
if (!(await fs_extra_1.default.pathExists(huskyDir))) {
|
|
151
|
+
try {
|
|
152
|
+
(0, child_process_1.execSync)('npx husky install', { cwd, stdio: 'pipe' });
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
// husky install might fail if .git doesn't exist, that's ok
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// Create pre-commit hook
|
|
159
|
+
spinner.text = 'Creating pre-commit hook...';
|
|
160
|
+
await fs_extra_1.default.ensureDir(huskyDir);
|
|
161
|
+
const preCommitPath = path_1.default.join(huskyDir, 'pre-commit');
|
|
162
|
+
const preCommitContent = `#!/usr/bin/env sh
|
|
163
|
+
. "$(dirname -- "$0")/_/husky.sh"
|
|
164
|
+
|
|
165
|
+
echo "๐งช Running tests before commit..."
|
|
166
|
+
npx lint-staged
|
|
167
|
+
`;
|
|
168
|
+
await fs_extra_1.default.writeFile(preCommitPath, preCommitContent);
|
|
169
|
+
await fs_extra_1.default.chmod(preCommitPath, '755');
|
|
170
|
+
// Create husky.sh helper if it doesn't exist
|
|
171
|
+
const huskyHelperDir = path_1.default.join(huskyDir, '_');
|
|
172
|
+
await fs_extra_1.default.ensureDir(huskyHelperDir);
|
|
173
|
+
const huskyShPath = path_1.default.join(huskyHelperDir, 'husky.sh');
|
|
174
|
+
if (!(await fs_extra_1.default.pathExists(huskyShPath))) {
|
|
175
|
+
const huskyShContent = `#!/usr/bin/env sh
|
|
176
|
+
if [ -z "$husky_skip_init" ]; then
|
|
177
|
+
debug () {
|
|
178
|
+
if [ "$HUSKY_DEBUG" = "1" ]; then
|
|
179
|
+
echo "husky (debug) - $1"
|
|
180
|
+
fi
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
readonly hook_name="$(basename -- "$0")"
|
|
184
|
+
debug "starting $hook_name..."
|
|
185
|
+
|
|
186
|
+
if [ "$HUSKY" = "0" ]; then
|
|
187
|
+
debug "HUSKY env variable is set to 0, skipping hook"
|
|
188
|
+
exit 0
|
|
189
|
+
fi
|
|
190
|
+
|
|
191
|
+
if [ -f ~/.huskyrc ]; then
|
|
192
|
+
debug "sourcing ~/.huskyrc"
|
|
193
|
+
. ~/.huskyrc
|
|
194
|
+
fi
|
|
195
|
+
|
|
196
|
+
readonly husky_skip_init=1
|
|
197
|
+
export husky_skip_init
|
|
198
|
+
sh -e "$0" "$@"
|
|
199
|
+
exitCode="$?"
|
|
200
|
+
|
|
201
|
+
if [ $exitCode != 0 ]; then
|
|
202
|
+
echo "husky - $hook_name hook exited with code $exitCode (error)"
|
|
203
|
+
fi
|
|
204
|
+
|
|
205
|
+
if [ $exitCode = 127 ]; then
|
|
206
|
+
echo "husky - command not found in PATH=$PATH"
|
|
207
|
+
fi
|
|
208
|
+
|
|
209
|
+
exit $exitCode
|
|
210
|
+
fi
|
|
211
|
+
`;
|
|
212
|
+
await fs_extra_1.default.writeFile(huskyShPath, huskyShContent);
|
|
213
|
+
await fs_extra_1.default.chmod(huskyShPath, '755');
|
|
214
|
+
}
|
|
215
|
+
spinner.succeed(chalk_1.default.green('Git hooks configured!'));
|
|
216
|
+
console.log('');
|
|
217
|
+
console.log(chalk_1.default.cyan('๐ What was set up:'));
|
|
218
|
+
console.log(' โข ' + chalk_1.default.yellow('husky') + ' - Git hooks manager');
|
|
219
|
+
console.log(' โข ' + chalk_1.default.yellow('lint-staged') + ' - Run tests on staged files');
|
|
220
|
+
console.log(' โข ' + chalk_1.default.yellow('pre-commit hook') + ' - Tests run before each commit');
|
|
221
|
+
console.log('');
|
|
222
|
+
console.log(chalk_1.default.cyan('๐ก How it works:'));
|
|
223
|
+
console.log(' When you run ' + chalk_1.default.yellow('git commit') + ', tests for changed files will run automatically.');
|
|
224
|
+
console.log(' If tests fail, the commit will be blocked.');
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
spinner.fail(chalk_1.default.red('Failed to setup Git hooks'));
|
|
228
|
+
throw error;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
exports.default = initCommand;
|
|
232
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;AAgBH,kCA8BC;AA5CD,wDAA0B;AAC1B,gDAAwB;AACxB,kDAA0B;AAC1B,8CAAsB;AACtB,iDAAyC;AAOzC;;GAEG;AACI,KAAK,UAAU,WAAW,CAAC,UAAuB,EAAE;IACzD,MAAM,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;IAChD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAE1B,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC,CAAC;IAC1D,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAEhB,+BAA+B;IAC/B,MAAM,eAAe,GAAG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