codeguard-testgen 1.0.9 → 1.0.10

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.
@@ -0,0 +1,25 @@
1
+ export interface ToolCheckResult {
2
+ available: boolean;
3
+ success: boolean;
4
+ errors: string[];
5
+ }
6
+ export interface ValidationResult {
7
+ success: boolean;
8
+ hasErrors: boolean;
9
+ typescript: ToolCheckResult;
10
+ eslint: ToolCheckResult;
11
+ formattedErrors: string;
12
+ }
13
+ /**
14
+ * Check if TypeScript compiler is available and run type checking on a file
15
+ */
16
+ export declare function checkTypeScriptCompilation(testFilePath: string): ToolCheckResult;
17
+ /**
18
+ * Check if ESLint is available and run linting on a file
19
+ */
20
+ export declare function checkESLint(testFilePath: string): ToolCheckResult;
21
+ /**
22
+ * Main validation function that checks both TypeScript and ESLint
23
+ */
24
+ export declare function validateTestFile(testFilePath: string): ValidationResult;
25
+ //# sourceMappingURL=typeValidator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeValidator.d.ts","sourceRoot":"","sources":["../src/typeValidator.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,eAAe,CAAC;IAC5B,MAAM,EAAE,eAAe,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,YAAY,EAAE,MAAM,GAAG,eAAe,CAmChF;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,eAAe,CAmCjE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,gBAAgB,CA0CvE"}
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkTypeScriptCompilation = checkTypeScriptCompilation;
4
+ exports.checkESLint = checkESLint;
5
+ exports.validateTestFile = validateTestFile;
6
+ const child_process_1 = require("child_process");
7
+ /**
8
+ * Check if TypeScript compiler is available and run type checking on a file
9
+ */
10
+ function checkTypeScriptCompilation(testFilePath) {
11
+ // Check if TypeScript is available
12
+ try {
13
+ (0, child_process_1.execSync)('npx tsc --version', { stdio: 'pipe' });
14
+ }
15
+ catch (error) {
16
+ return {
17
+ available: false,
18
+ success: true, // Consider it a success if not available (graceful degradation)
19
+ errors: []
20
+ };
21
+ }
22
+ // Run TypeScript compilation check
23
+ try {
24
+ (0, child_process_1.execSync)(`npx tsc --noEmit ${testFilePath}`, {
25
+ encoding: 'utf-8',
26
+ stdio: 'pipe'
27
+ });
28
+ return {
29
+ available: true,
30
+ success: true,
31
+ errors: []
32
+ };
33
+ }
34
+ catch (error) {
35
+ // Parse TypeScript errors from stderr/stdout
36
+ const output = error.stdout || error.stderr || error.message || '';
37
+ const errors = parseTypeScriptErrors(output);
38
+ return {
39
+ available: true,
40
+ success: false,
41
+ errors
42
+ };
43
+ }
44
+ }
45
+ /**
46
+ * Check if ESLint is available and run linting on a file
47
+ */
48
+ function checkESLint(testFilePath) {
49
+ // Check if ESLint is available
50
+ try {
51
+ (0, child_process_1.execSync)('npx eslint --version', { stdio: 'pipe' });
52
+ }
53
+ catch (error) {
54
+ return {
55
+ available: false,
56
+ success: true, // Consider it a success if not available (graceful degradation)
57
+ errors: []
58
+ };
59
+ }
60
+ // Run ESLint check
61
+ try {
62
+ (0, child_process_1.execSync)(`npx eslint ${testFilePath}`, {
63
+ encoding: 'utf-8',
64
+ stdio: 'pipe'
65
+ });
66
+ return {
67
+ available: true,
68
+ success: true,
69
+ errors: []
70
+ };
71
+ }
72
+ catch (error) {
73
+ // Parse ESLint errors from stderr/stdout
74
+ const output = error.stdout || error.stderr || error.message || '';
75
+ const errors = parseESLintErrors(output);
76
+ return {
77
+ available: true,
78
+ success: false,
79
+ errors
80
+ };
81
+ }
82
+ }
83
+ /**
84
+ * Main validation function that checks both TypeScript and ESLint
85
+ */
86
+ function validateTestFile(testFilePath) {
87
+ console.log(`\nšŸ” Running type checking and linting validation on: ${testFilePath}`);
88
+ const typescript = checkTypeScriptCompilation(testFilePath);
89
+ const eslint = checkESLint(testFilePath);
90
+ const hasErrors = (typescript.available && !typescript.success) ||
91
+ (eslint.available && !eslint.success);
92
+ const success = !hasErrors;
93
+ // Format errors for AI consumption
94
+ const formattedErrors = formatValidationErrors(typescript, eslint);
95
+ // Log results
96
+ if (!typescript.available && !eslint.available) {
97
+ console.log(' ā„¹ļø TypeScript and ESLint not available - skipping validation');
98
+ }
99
+ else {
100
+ if (typescript.available) {
101
+ if (typescript.success) {
102
+ console.log(' āœ… TypeScript compilation: PASSED');
103
+ }
104
+ else {
105
+ console.log(` āŒ TypeScript compilation: FAILED (${typescript.errors.length} error(s))`);
106
+ }
107
+ }
108
+ if (eslint.available) {
109
+ if (eslint.success) {
110
+ console.log(' āœ… ESLint: PASSED');
111
+ }
112
+ else {
113
+ console.log(` āŒ ESLint: FAILED (${eslint.errors.length} error(s))`);
114
+ }
115
+ }
116
+ }
117
+ return {
118
+ success,
119
+ hasErrors,
120
+ typescript,
121
+ eslint,
122
+ formattedErrors
123
+ };
124
+ }
125
+ /**
126
+ * Parse TypeScript compiler errors into a readable array
127
+ */
128
+ function parseTypeScriptErrors(output) {
129
+ const errors = [];
130
+ const lines = output.split('\n');
131
+ for (const line of lines) {
132
+ // TypeScript errors typically follow pattern: filename(line,col): error TS####: message
133
+ if (line.includes('error TS') || line.includes(': error')) {
134
+ errors.push(line.trim());
135
+ }
136
+ }
137
+ // If no specific errors found, return the full output (may be a general error)
138
+ if (errors.length === 0 && output.trim()) {
139
+ errors.push(output.trim());
140
+ }
141
+ return errors;
142
+ }
143
+ /**
144
+ * Parse ESLint errors into a readable array
145
+ */
146
+ function parseESLintErrors(output) {
147
+ const errors = [];
148
+ const lines = output.split('\n');
149
+ for (const line of lines) {
150
+ // ESLint errors typically show line:col and rule name
151
+ if (line.includes('error') || line.includes('warning')) {
152
+ const trimmed = line.trim();
153
+ if (trimmed) {
154
+ errors.push(trimmed);
155
+ }
156
+ }
157
+ }
158
+ // If no specific errors found, return the full output
159
+ if (errors.length === 0 && output.trim()) {
160
+ errors.push(output.trim());
161
+ }
162
+ return errors;
163
+ }
164
+ /**
165
+ * Format validation errors for AI consumption
166
+ */
167
+ function formatValidationErrors(typescript, eslint) {
168
+ const sections = [];
169
+ if (typescript.available && !typescript.success) {
170
+ sections.push('## TypeScript Compilation Errors\n\n' + typescript.errors.join('\n'));
171
+ }
172
+ if (eslint.available && !eslint.success) {
173
+ sections.push('## ESLint Errors\n\n' + eslint.errors.join('\n'));
174
+ }
175
+ if (sections.length === 0) {
176
+ return 'No validation errors found.';
177
+ }
178
+ return sections.join('\n\n');
179
+ }
180
+ //# sourceMappingURL=typeValidator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeValidator.js","sourceRoot":"","sources":["../src/typeValidator.ts"],"names":[],"mappings":";;AAmBA,gEAmCC;AAKD,kCAmCC;AAKD,4CA0CC;AA7ID,iDAAyC;AAgBzC;;GAEG;AACH,SAAgB,0BAA0B,CAAC,YAAoB;IAC7D,mCAAmC;IACnC,IAAI,CAAC;QACH,IAAA,wBAAQ,EAAC,mBAAmB,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;IACnD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO;YACL,SAAS,EAAE,KAAK;YAChB,OAAO,EAAE,IAAI,EAAE,gEAAgE;YAC/E,MAAM,EAAE,EAAE;SACX,CAAC;IACJ,CAAC;IAED,mCAAmC;IACnC,IAAI,CAAC;QACH,IAAA,wBAAQ,EAAC,oBAAoB,YAAY,EAAE,EAAE;YAC3C,Q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BACZ,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACvB,CAAC;QACH,CAAC;IACH,CAAC;IAED,sDAAsD;IACtD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;QACzC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7B,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,SAAS,sBAAsB,CAAC,UAA2B,EAAE,MAAuB;IAClF,MAAM,QAAQ,GAAa,EAAE,CAAC;IAE9B,IAAI,UAAU,CAAC,SAAS,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;QAChD,QAAQ,CAAC,IAAI,CAAC,sCAAsC,GAAG,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACvF,CAAC;IAED,IAAI,MAAM,CAAC,SAAS,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACxC,QAAQ,CAAC,IAAI,CAAC,sBAAsB,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACnE,CAAC;IAED,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,6BAA6B,CAAC;IACvC,CAAC;IAED,OAAO,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC/B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeguard-testgen",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "AI-powered unit test generator with AST analysis for TypeScript/JavaScript projects",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",