test-gen-js 0.2.0 → 0.2.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 +11 -0
- package/README.md +53 -6
- package/dist/cli.js +11 -11
- package/dist/cli.js.map +1 -1
- package/dist/commands/index.d.ts +1 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +3 -1
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/scan.d.ts +30 -0
- package/dist/commands/scan.d.ts.map +1 -0
- package/dist/commands/scan.js +161 -0
- package/dist/commands/scan.js.map +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -23,12 +23,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
23
23
|
- Creates `.testgenrc.js` configuration file
|
|
24
24
|
- Sets up Git hooks with husky and lint-staged
|
|
25
25
|
- Pre-commit hook runs tests automatically before each commit
|
|
26
|
+
- 🎉 `scan` command - Scan directory and generate tests for all files
|
|
27
|
+
- Batch generate tests for entire directories
|
|
28
|
+
- Dry-run mode to preview without creating files
|
|
29
|
+
- Progress tracking and summary report
|
|
30
|
+
- Skip files with no components/functions
|
|
26
31
|
- Configuration file support (`.testgenrc.js`)
|
|
27
32
|
|
|
28
33
|
### Commands
|
|
29
34
|
- `test-gen-js init` - Initialize configuration and Git hooks
|
|
30
35
|
- `--no-hooks` - Skip Git hooks setup
|
|
31
36
|
- `--force` - Overwrite existing configuration
|
|
37
|
+
- `test-gen-js scan <directory>` - Scan and generate tests
|
|
38
|
+
- `--dry-run` - Preview without creating files
|
|
39
|
+
- `--pattern` - File pattern to match
|
|
40
|
+
- `--exclude` - Patterns to exclude
|
|
41
|
+
- `--snapshot` - Include snapshot tests
|
|
42
|
+
- `--overwrite` - Overwrite existing files
|
|
32
43
|
|
|
33
44
|
### How Pre-commit Testing Works
|
|
34
45
|
1. Run `npx test-gen-js init` in your project
|
package/README.md
CHANGED
|
@@ -352,18 +352,65 @@ tgjs g src/components/Header.tsx -o __tests__/Header.test.tsx
|
|
|
352
352
|
tgjs g src/components/Header.tsx --overwrite
|
|
353
353
|
```
|
|
354
354
|
|
|
355
|
-
### `scan` (alias: `s`)
|
|
355
|
+
### `scan` (alias: `s`)
|
|
356
356
|
|
|
357
|
-
Scan directory and generate tests for all files
|
|
357
|
+
Scan directory and generate tests for all files at once.
|
|
358
358
|
|
|
359
359
|
```bash
|
|
360
|
-
# Basic usage
|
|
361
|
-
test-gen-js scan
|
|
360
|
+
# Basic usage - scan entire src folder
|
|
361
|
+
test-gen-js scan src
|
|
362
|
+
tgjs s src
|
|
362
363
|
|
|
363
364
|
# Options
|
|
364
365
|
--dry-run # Preview without creating files
|
|
365
366
|
--pattern <glob> # File pattern (default: **/*.{ts,tsx,js,jsx})
|
|
366
367
|
--exclude <patterns> # Patterns to exclude
|
|
368
|
+
--snapshot # Include snapshot tests
|
|
369
|
+
--overwrite # Overwrite existing test files
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
**Examples:**
|
|
373
|
+
|
|
374
|
+
```bash
|
|
375
|
+
# Preview what will be generated (no files created)
|
|
376
|
+
tgjs scan src --dry-run
|
|
377
|
+
|
|
378
|
+
# Generate tests for all components in src/components
|
|
379
|
+
tgjs scan src/components
|
|
380
|
+
|
|
381
|
+
# Generate tests with snapshots
|
|
382
|
+
tgjs scan src --snapshot
|
|
383
|
+
|
|
384
|
+
# Overwrite existing test files
|
|
385
|
+
tgjs scan src --overwrite
|
|
386
|
+
|
|
387
|
+
# Custom pattern (only .tsx files)
|
|
388
|
+
tgjs scan src --pattern "**/*.tsx"
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
**Output example:**
|
|
392
|
+
|
|
393
|
+
```
|
|
394
|
+
🔍 Scanning directory: /your-project/src
|
|
395
|
+
📝 Pattern: **/*.{ts,tsx,js,jsx}
|
|
396
|
+
🚫 Exclude: node_modules/**, dist/**, **/*.test.*, ...
|
|
397
|
+
|
|
398
|
+
📦 Processing files...
|
|
399
|
+
|
|
400
|
+
[1/5] ✅ components/Button.tsx → components/Button.test.tsx
|
|
401
|
+
[2/5] ✅ components/Card.tsx → components/Card.test.tsx
|
|
402
|
+
[3/5] ⏭️ components/index.ts (no components/functions)
|
|
403
|
+
[4/5] ✅ utils/helpers.ts → utils/helpers.test.ts
|
|
404
|
+
[5/5] ❌ utils/broken.ts: Parse error
|
|
405
|
+
|
|
406
|
+
══════════════════════════════════════════════════
|
|
407
|
+
📊 Summary
|
|
408
|
+
══════════════════════════════════════════════════
|
|
409
|
+
Total files: 5
|
|
410
|
+
Created: 3
|
|
411
|
+
Updated: 0
|
|
412
|
+
Skipped: 1
|
|
413
|
+
Failed: 1
|
|
367
414
|
```
|
|
368
415
|
|
|
369
416
|
### `init`
|
|
@@ -505,9 +552,9 @@ git commit -m "feat: add new component"
|
|
|
505
552
|
- [x] GitHub Actions CI/CD
|
|
506
553
|
- [x] Automated npm publishing
|
|
507
554
|
|
|
508
|
-
###
|
|
555
|
+
### ✅ Phase 2: Extended Features (v0.2.x) - Current
|
|
509
556
|
|
|
510
|
-
- [
|
|
557
|
+
- [x] Directory scanning and batch generation (`scan` command)
|
|
511
558
|
- [x] Configuration file support (`.testgenrc.js`)
|
|
512
559
|
- [x] Git hooks for pre-commit testing (`init` command)
|
|
513
560
|
- [ ] Node.js backend support
|
package/dist/cli.js
CHANGED
|
@@ -72,22 +72,22 @@ program
|
|
|
72
72
|
.description('Scan directory and generate tests for all files')
|
|
73
73
|
.option('--dry-run', 'Preview without creating files', false)
|
|
74
74
|
.option('--pattern <glob>', 'File pattern to match', '**/*.{ts,tsx,js,jsx}')
|
|
75
|
-
.option('--exclude <patterns...>', 'Patterns to exclude'
|
|
75
|
+
.option('--exclude <patterns...>', 'Patterns to exclude')
|
|
76
|
+
.option('--snapshot', 'Include snapshot tests', false)
|
|
77
|
+
.option('--overwrite', 'Overwrite existing test files', false)
|
|
76
78
|
.action(async (directory, options) => {
|
|
77
|
-
const spinner = (0, ora_1.default)('Scanning directory...').start();
|
|
78
79
|
try {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
80
|
+
await (0, commands_1.scanCommand)(directory, {
|
|
81
|
+
pattern: options.pattern,
|
|
82
|
+
exclude: options.exclude,
|
|
83
|
+
dryRun: options.dryRun,
|
|
84
|
+
snapshot: options.snapshot,
|
|
85
|
+
overwrite: options.overwrite,
|
|
86
|
+
});
|
|
86
87
|
}
|
|
87
88
|
catch (error) {
|
|
88
|
-
spinner.fail(chalk_1.default.red('Failed to scan directory'));
|
|
89
89
|
if (error instanceof Error) {
|
|
90
|
-
console.error(chalk_1.default.red(error.message));
|
|
90
|
+
console.error(chalk_1.default.red('Error: ' + error.message));
|
|
91
91
|
}
|
|
92
92
|
process.exit(1);
|
|
93
93
|
}
|
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;AAC3C,
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AAEA,yCAAoC;AACpC,kDAA0B;AAC1B,8CAAsB;AACtB,yCAAyC;AACzC,2CAA2C;AAC3C,yCAAsD;AAGtD,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,aAAa,CAAC;KACnB,WAAW,CAAC,wEAAwE,CAAC;KACrF,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpB,mBAAmB;AACnB,OAAO;KACJ,OAAO,CAAC,iBAAiB,CAAC;KAC1B,KAAK,CAAC,GAAG,CAAC;KACV,WAAW,CAAC,gDAAgD,CAAC;KAC7D,MAAM,CAAC,q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A2C,EAAE,EAAE;IAC5D,IAAI,CAAC;QACH,MAAM,IAAA,sBAAW,EAAC;YAChB,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,KAAK,EAAE,OAAO,CAAC,KAAK;SACrB,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC3B,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QACtD,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,EAAE,CAAC"}
|
package/dist/commands/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC"}
|
package/dist/commands/index.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
* Commands module
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.initCommand = void 0;
|
|
6
|
+
exports.scanCommand = exports.initCommand = void 0;
|
|
7
7
|
var init_1 = require("./init");
|
|
8
8
|
Object.defineProperty(exports, "initCommand", { enumerable: true, get: function () { return init_1.initCommand; } });
|
|
9
|
+
var scan_1 = require("./scan");
|
|
10
|
+
Object.defineProperty(exports, "scanCommand", { enumerable: true, get: function () { return scan_1.scanCommand; } });
|
|
9
11
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,+BAAqC;AAA5B,mGAAA,WAAW,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,+BAAqC;AAA5B,mGAAA,WAAW,OAAA;AACpB,+BAAqC;AAA5B,mGAAA,WAAW,OAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scan Command
|
|
3
|
+
* Scans a directory and generates tests for all components/functions
|
|
4
|
+
*/
|
|
5
|
+
import type { GeneratedTest } from '../types';
|
|
6
|
+
interface ScanOptions {
|
|
7
|
+
pattern?: string;
|
|
8
|
+
exclude?: string[];
|
|
9
|
+
dryRun?: boolean;
|
|
10
|
+
snapshot?: boolean;
|
|
11
|
+
overwrite?: boolean;
|
|
12
|
+
}
|
|
13
|
+
interface ScanResult {
|
|
14
|
+
total: number;
|
|
15
|
+
created: number;
|
|
16
|
+
updated: number;
|
|
17
|
+
skipped: number;
|
|
18
|
+
failed: number;
|
|
19
|
+
files: GeneratedTest[];
|
|
20
|
+
errors: Array<{
|
|
21
|
+
file: string;
|
|
22
|
+
error: string;
|
|
23
|
+
}>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Scan a directory and generate tests for all files
|
|
27
|
+
*/
|
|
28
|
+
export declare function scanCommand(directory: string, options?: ScanOptions): Promise<ScanResult>;
|
|
29
|
+
export default scanCommand;
|
|
30
|
+
//# sourceMappingURL=scan.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../src/commands/scan.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,OAAO,KAAK,EAAoB,aAAa,EAAE,MAAM,UAAU,CAAC;AAEhE,UAAU,WAAW;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,UAAU,UAAU;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,aAAa,EAAE,CAAC;IACvB,MAAM,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChD;AAED;;GAEG;AACH,wBAAsB,WAAW,CAC/B,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,UAAU,CAAC,CA0JrB;AAYD,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Scan Command
|
|
4
|
+
* Scans a directory and generates tests for all components/functions
|
|
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.scanCommand = scanCommand;
|
|
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 glob_1 = require("glob");
|
|
16
|
+
const analyzer_1 = require("../analyzer");
|
|
17
|
+
const generator_1 = require("../generator");
|
|
18
|
+
/**
|
|
19
|
+
* Scan a directory and generate tests for all files
|
|
20
|
+
*/
|
|
21
|
+
async function scanCommand(directory, options = {}) {
|
|
22
|
+
const { pattern = '**/*.{ts,tsx,js,jsx}', exclude = [
|
|
23
|
+
'node_modules/**',
|
|
24
|
+
'dist/**',
|
|
25
|
+
'build/**',
|
|
26
|
+
'**/*.test.*',
|
|
27
|
+
'**/*.spec.*',
|
|
28
|
+
'**/__tests__/**',
|
|
29
|
+
'**/__mocks__/**',
|
|
30
|
+
'**/coverage/**',
|
|
31
|
+
], dryRun = false, snapshot = false, overwrite = false, } = options;
|
|
32
|
+
const cwd = process.cwd();
|
|
33
|
+
const targetDir = path_1.default.resolve(cwd, directory);
|
|
34
|
+
// Check if directory exists
|
|
35
|
+
if (!(await fs_extra_1.default.pathExists(targetDir))) {
|
|
36
|
+
throw new Error(`Directory not found: ${targetDir}`);
|
|
37
|
+
}
|
|
38
|
+
console.log('');
|
|
39
|
+
console.log(chalk_1.default.cyan('🔍 Scanning directory:'), targetDir);
|
|
40
|
+
console.log(chalk_1.default.cyan('📝 Pattern:'), pattern);
|
|
41
|
+
console.log(chalk_1.default.cyan('🚫 Exclude:'), exclude.join(', '));
|
|
42
|
+
if (dryRun) {
|
|
43
|
+
console.log(chalk_1.default.yellow('⚠️ Dry run mode - no files will be created'));
|
|
44
|
+
}
|
|
45
|
+
console.log('');
|
|
46
|
+
// Find all matching files
|
|
47
|
+
const spinner = (0, ora_1.default)('Finding files...').start();
|
|
48
|
+
const files = await (0, glob_1.glob)(pattern, {
|
|
49
|
+
cwd: targetDir,
|
|
50
|
+
ignore: exclude,
|
|
51
|
+
absolute: true,
|
|
52
|
+
nodir: true,
|
|
53
|
+
});
|
|
54
|
+
spinner.succeed(`Found ${files.length} files`);
|
|
55
|
+
if (files.length === 0) {
|
|
56
|
+
console.log(chalk_1.default.yellow('No files found matching the pattern.'));
|
|
57
|
+
return {
|
|
58
|
+
total: 0,
|
|
59
|
+
created: 0,
|
|
60
|
+
updated: 0,
|
|
61
|
+
skipped: 0,
|
|
62
|
+
failed: 0,
|
|
63
|
+
files: [],
|
|
64
|
+
errors: [],
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
// Process each file
|
|
68
|
+
const result = {
|
|
69
|
+
total: files.length,
|
|
70
|
+
created: 0,
|
|
71
|
+
updated: 0,
|
|
72
|
+
skipped: 0,
|
|
73
|
+
failed: 0,
|
|
74
|
+
files: [],
|
|
75
|
+
errors: [],
|
|
76
|
+
};
|
|
77
|
+
console.log('');
|
|
78
|
+
console.log(chalk_1.default.cyan('📦 Processing files...'));
|
|
79
|
+
console.log('');
|
|
80
|
+
for (let i = 0; i < files.length; i++) {
|
|
81
|
+
const file = files[i];
|
|
82
|
+
const relativePath = path_1.default.relative(cwd, file);
|
|
83
|
+
const progress = `[${i + 1}/${files.length}]`;
|
|
84
|
+
try {
|
|
85
|
+
// Analyze the file
|
|
86
|
+
const analysis = await (0, analyzer_1.analyzeFile)(file);
|
|
87
|
+
// Skip files with no components or functions
|
|
88
|
+
if (analysis.components.length === 0 && analysis.functions.length === 0) {
|
|
89
|
+
console.log(chalk_1.default.gray(`${progress} ⏭️ ${relativePath} (no components/functions)`));
|
|
90
|
+
result.skipped++;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
// Generate test (or preview in dry-run mode)
|
|
94
|
+
if (dryRun) {
|
|
95
|
+
const testPath = getTestFilePath(file);
|
|
96
|
+
const exists = await fs_extra_1.default.pathExists(testPath);
|
|
97
|
+
console.log(chalk_1.default.blue(`${progress} 👁️ ${relativePath}`) +
|
|
98
|
+
chalk_1.default.gray(` → ${path_1.default.relative(cwd, testPath)}`) +
|
|
99
|
+
(exists ? chalk_1.default.yellow(' (exists)') : chalk_1.default.green(' (new)')));
|
|
100
|
+
result.files.push({
|
|
101
|
+
code: '',
|
|
102
|
+
outputPath: testPath,
|
|
103
|
+
sourcePath: file,
|
|
104
|
+
action: exists ? 'skipped' : 'created',
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
const generatorOptions = {
|
|
109
|
+
snapshot,
|
|
110
|
+
overwrite,
|
|
111
|
+
mock: true,
|
|
112
|
+
};
|
|
113
|
+
const testResult = await (0, generator_1.generateTest)(analysis, generatorOptions);
|
|
114
|
+
result.files.push(testResult);
|
|
115
|
+
const icon = testResult.action === 'created' ? '✅' : testResult.action === 'updated' ? '🔄' : '⏭️';
|
|
116
|
+
const color = testResult.action === 'created' ? chalk_1.default.green : testResult.action === 'updated' ? chalk_1.default.blue : chalk_1.default.gray;
|
|
117
|
+
console.log(color(`${progress} ${icon} ${relativePath}`) +
|
|
118
|
+
chalk_1.default.gray(` → ${path_1.default.relative(cwd, testResult.outputPath)}`));
|
|
119
|
+
if (testResult.action === 'created')
|
|
120
|
+
result.created++;
|
|
121
|
+
else if (testResult.action === 'updated')
|
|
122
|
+
result.updated++;
|
|
123
|
+
else
|
|
124
|
+
result.skipped++;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
129
|
+
console.log(chalk_1.default.red(`${progress} ❌ ${relativePath}: ${errorMessage}`));
|
|
130
|
+
result.failed++;
|
|
131
|
+
result.errors.push({ file: relativePath, error: errorMessage });
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// Summary
|
|
135
|
+
console.log('');
|
|
136
|
+
console.log(chalk_1.default.cyan('═'.repeat(50)));
|
|
137
|
+
console.log(chalk_1.default.cyan('📊 Summary'));
|
|
138
|
+
console.log(chalk_1.default.cyan('═'.repeat(50)));
|
|
139
|
+
console.log(` Total files: ${result.total}`);
|
|
140
|
+
console.log(chalk_1.default.green(` Created: ${result.created}`));
|
|
141
|
+
console.log(chalk_1.default.blue(` Updated: ${result.updated}`));
|
|
142
|
+
console.log(chalk_1.default.gray(` Skipped: ${result.skipped}`));
|
|
143
|
+
console.log(chalk_1.default.red(` Failed: ${result.failed}`));
|
|
144
|
+
console.log('');
|
|
145
|
+
if (dryRun) {
|
|
146
|
+
console.log(chalk_1.default.yellow('💡 This was a dry run. Run without --dry-run to create files.'));
|
|
147
|
+
console.log('');
|
|
148
|
+
}
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Get test file path for a source file
|
|
153
|
+
*/
|
|
154
|
+
function getTestFilePath(sourcePath) {
|
|
155
|
+
const ext = path_1.default.extname(sourcePath);
|
|
156
|
+
const baseName = path_1.default.basename(sourcePath, ext);
|
|
157
|
+
const dirName = path_1.default.dirname(sourcePath);
|
|
158
|
+
return path_1.default.join(dirName, `${baseName}.test${ext}`);
|
|
159
|
+
}
|
|
160
|
+
exports.default = scanCommand;
|
|
161
|
+
//# sourceMappingURL=scan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scan.js","sourceRoot":"","sources":["../../src/commands/scan.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;AAgCH,kCA6JC;AA3LD,wDAA0B;AAC1B,gDAAwB;AACxB,kDAA0B;AAC1B,8CAAsB;AACtB,+BAA4B;AAC5B,0CAA0C;AAC1C,4CAA4C;AAqB5C;;GAEG;AACI,KAAK,UAAU,WAAW,CAC/B,SAAiB,EACjB,UAAuB,EAAE;IAEzB,MAAM,EACJ,OAAO,GAAG,sBAAsB,EAChC,OAAO,GAAG;QACR,iBAAiB;QACjB,SAAS;QACT,UAAU;QACV,aAAa;QACb,aAAa;QACb,iBAAiB;QACjB,iBAAiB;QACjB,gBAAgB;KACjB,EACD,MAAM,GAAG,KAAK,EACd,QAAQ,GAAG,KAAK,EAChB,SAAS,GAAG,KAAK,GAClB,GAAG,OAAO,CAAC;IAEZ,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAC1B,MAAM,SAAS,GAAG,cAAI,CAAC,OAAO,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IAE/C,4B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