test-gen-js 0.3.1 โ 0.3.2
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/README.md +123 -0
- package/dist/cli.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -590,6 +590,129 @@ git commit -m "feat: add new component"
|
|
|
590
590
|
|
|
591
591
|
---
|
|
592
592
|
|
|
593
|
+
## ๐งช Testing
|
|
594
|
+
|
|
595
|
+
test-gen-js has comprehensive test coverage to ensure reliability.
|
|
596
|
+
|
|
597
|
+
### Running Tests
|
|
598
|
+
|
|
599
|
+
```bash
|
|
600
|
+
# Run all tests
|
|
601
|
+
npm test
|
|
602
|
+
|
|
603
|
+
# Run with coverage report
|
|
604
|
+
npm test -- --coverage
|
|
605
|
+
|
|
606
|
+
# Run only unit tests
|
|
607
|
+
npm test -- --testPathIgnorePatterns=integration
|
|
608
|
+
|
|
609
|
+
# Run only integration tests
|
|
610
|
+
npm test -- --testPathPattern=integration
|
|
611
|
+
|
|
612
|
+
# Run tests in watch mode
|
|
613
|
+
npm test -- --watch
|
|
614
|
+
```
|
|
615
|
+
|
|
616
|
+
### Test Structure
|
|
617
|
+
|
|
618
|
+
| Test Type | Description | Files |
|
|
619
|
+
|-----------|-------------|-------|
|
|
620
|
+
| **Unit Tests** | Test individual modules in isolation | `*.test.ts` |
|
|
621
|
+
| **Integration Tests** | Test CLI commands end-to-end | `cli.integration.test.ts` |
|
|
622
|
+
|
|
623
|
+
### Test Coverage
|
|
624
|
+
|
|
625
|
+
```
|
|
626
|
+
-----------------------|---------|----------|---------|---------|
|
|
627
|
+
File | % Stmts | % Branch | % Funcs | % Lines |
|
|
628
|
+
-----------------------|---------|----------|---------|---------|
|
|
629
|
+
src/utils | 96.77 | 100 | 100 | 96.72 |
|
|
630
|
+
src/parser | 78.72 | 78.72 | 66.66 | 79.01 |
|
|
631
|
+
src/analyzer | 72.92 | 58.42 | 83.78 | 76.15 |
|
|
632
|
+
src/generator | 53.84 | 46.03 | 38.88 | 59.40 |
|
|
633
|
+
-----------------------|---------|----------|---------|---------|
|
|
634
|
+
```
|
|
635
|
+
|
|
636
|
+
### Writing Tests for Your Project
|
|
637
|
+
|
|
638
|
+
After generating test files with test-gen-js, you can run your project's tests:
|
|
639
|
+
|
|
640
|
+
```bash
|
|
641
|
+
# Run generated tests
|
|
642
|
+
npm test
|
|
643
|
+
|
|
644
|
+
# Run specific test file
|
|
645
|
+
npm test -- Button.test.tsx
|
|
646
|
+
|
|
647
|
+
# Run tests matching a pattern
|
|
648
|
+
npm test -- --testPathPattern=components
|
|
649
|
+
```
|
|
650
|
+
|
|
651
|
+
### Test Examples
|
|
652
|
+
|
|
653
|
+
**Unit Test Example:**
|
|
654
|
+
|
|
655
|
+
```typescript
|
|
656
|
+
// src/utils/helpers.test.ts
|
|
657
|
+
import { formatDate, calculateTotal } from './helpers';
|
|
658
|
+
|
|
659
|
+
describe('formatDate', () => {
|
|
660
|
+
it('should format date correctly', () => {
|
|
661
|
+
const result = formatDate(new Date('2024-01-15'));
|
|
662
|
+
expect(result).toBe('2024-01-15');
|
|
663
|
+
});
|
|
664
|
+
});
|
|
665
|
+
|
|
666
|
+
describe('calculateTotal', () => {
|
|
667
|
+
it('should calculate total with tax', () => {
|
|
668
|
+
const result = calculateTotal(100, 0.1);
|
|
669
|
+
expect(result).toBe(110);
|
|
670
|
+
});
|
|
671
|
+
});
|
|
672
|
+
```
|
|
673
|
+
|
|
674
|
+
**Integration Test Example:**
|
|
675
|
+
|
|
676
|
+
```typescript
|
|
677
|
+
// src/cli.integration.test.ts
|
|
678
|
+
import { execSync } from 'child_process';
|
|
679
|
+
import fs from 'fs-extra';
|
|
680
|
+
|
|
681
|
+
describe('CLI Integration', () => {
|
|
682
|
+
it('should generate test file', () => {
|
|
683
|
+
// Run CLI command
|
|
684
|
+
execSync('npx test-gen-js generate src/Button.tsx');
|
|
685
|
+
|
|
686
|
+
// Verify output
|
|
687
|
+
expect(fs.existsSync('src/Button.test.tsx')).toBe(true);
|
|
688
|
+
});
|
|
689
|
+
});
|
|
690
|
+
```
|
|
691
|
+
|
|
692
|
+
### Continuous Integration
|
|
693
|
+
|
|
694
|
+
Add to your CI/CD pipeline:
|
|
695
|
+
|
|
696
|
+
```yaml
|
|
697
|
+
# .github/workflows/test.yml
|
|
698
|
+
name: Tests
|
|
699
|
+
on: [push, pull_request]
|
|
700
|
+
|
|
701
|
+
jobs:
|
|
702
|
+
test:
|
|
703
|
+
runs-on: ubuntu-latest
|
|
704
|
+
steps:
|
|
705
|
+
- uses: actions/checkout@v4
|
|
706
|
+
- uses: actions/setup-node@v4
|
|
707
|
+
with:
|
|
708
|
+
node-version: '20'
|
|
709
|
+
- run: npm ci
|
|
710
|
+
- run: npm test -- --coverage
|
|
711
|
+
- run: npm run build
|
|
712
|
+
```
|
|
713
|
+
|
|
714
|
+
---
|
|
715
|
+
|
|
593
716
|
## ๐ Project Structure
|
|
594
717
|
|
|
595
718
|
```
|
package/dist/cli.js
CHANGED
|
@@ -14,7 +14,7 @@ const program = new commander_1.Command();
|
|
|
14
14
|
program
|
|
15
15
|
.name('test-gen-js')
|
|
16
16
|
.description('Auto-generate test boilerplate code for JavaScript/TypeScript projects')
|
|
17
|
-
.version('0.3.
|
|
17
|
+
.version('0.3.2');
|
|
18
18
|
// Generate command
|
|
19
19
|
program
|
|
20
20
|
.command('generate <file>')
|
package/package.json
CHANGED