@tng-sh/js 0.0.6 → 0.0.8

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/bin/tng.js CHANGED
@@ -10,8 +10,8 @@ const { ping, getUserStats } = require('../index');
10
10
 
11
11
  program
12
12
  .name('tng')
13
- .description('TNG - Automated Test Generation for JavaScript')
14
- .version('0.0.6');
13
+ .description('TNG - Automated Test Generation, and audit generation for JavaScript')
14
+ .version('0.0.8');
15
15
 
16
16
  /**
17
17
  * @command init
Binary file
Binary file
Binary file
Binary file
@@ -174,7 +174,7 @@ class GenerateTestsUI {
174
174
  const displayName = method.class_name ? `${method.class_name}#${method.name}` : `${fileName}#${method.name}`;
175
175
  const actionName = isAudit ? 'Auditing' : 'Generating test for';
176
176
 
177
- const progressHandler = (progress) => {
177
+ const progressHandler = async (progress) => {
178
178
  progress.update('Preparing request...');
179
179
 
180
180
  try {
@@ -240,19 +240,22 @@ class GenerateTestsUI {
240
240
  );
241
241
 
242
242
  if (isAudit) {
243
- // Auto-exit the progress UI so we can immediately show the audit results
244
- progress.complete('Audit complete!', { auto_exit: true });
243
+ progress.complete('Audit ready!', { auto_exit: false });
245
244
  return {
246
- message: 'Audit complete!',
245
+ message: 'Audit ready!',
247
246
  resultJson: resultJson
248
247
  };
249
248
  }
250
249
 
251
250
  progress.update('Tests generated successfully!');
252
251
 
252
+ // Save the file inside the progress handler to match Python flow
253
+ const fileInfo = await saveTestFile(resultJson);
254
+
253
255
  return {
254
256
  message: 'Tests generated successfully!',
255
- resultJson
257
+ resultJson,
258
+ file_path: fileInfo?.file_path
256
259
  };
257
260
  } catch (e) {
258
261
  progress.error(`Failed to generate: ${e.message}`);
@@ -269,11 +272,7 @@ class GenerateTestsUI {
269
272
  }
270
273
 
271
274
  if (uiResult && uiResult.resultJson) {
272
- const fileInfo = await saveTestFile(uiResult.resultJson);
273
- return {
274
- ...uiResult,
275
- file_path: fileInfo?.file_path
276
- };
275
+ return uiResult;
277
276
  }
278
277
 
279
278
  return null;
@@ -287,12 +286,71 @@ class GenerateTestsUI {
287
286
  const choice = this.goUiSession.showPostGenerationMenu(filePath, runCommand);
288
287
  if (choice === 'back' || !choice) break;
289
288
 
290
- if (choice === 'copy_command') {
289
+ if (choice === 'run_tests') {
290
+ this._runAndShowTestResults(runCommand);
291
+ } else if (choice === 'copy_command') {
291
292
  this._copyToClipboard(runCommand);
292
293
  }
293
294
  }
294
295
  }
295
296
 
297
+ _runAndShowTestResults(command) {
298
+ const { execSync } = require('child_process');
299
+
300
+ const spinnerHandler = () => {
301
+ try {
302
+ const output = execSync(command, { encoding: 'utf8', stdio: 'pipe' });
303
+ return {
304
+ success: true,
305
+ message: "Tests completed",
306
+ output: output,
307
+ exit_code: 0
308
+ };
309
+ } catch (error) {
310
+ return {
311
+ success: true, // We still want to show the results even if tests failed
312
+ message: "Tests completed",
313
+ output: error.stdout + error.stderr,
314
+ exit_code: error.status
315
+ };
316
+ }
317
+ };
318
+
319
+ const testOutput = this.goUiSession.showSpinner("Running tests...", spinnerHandler);
320
+
321
+ // Note: For simplicity in the first pass, we provide counts.
322
+ // We can enhance _parseTestOutput if needed.
323
+ const { passed, failed, errors, total } = this._parseTestOutput(testOutput.output || "", testOutput.exit_code || 0);
324
+
325
+ this.goUiSession.showTestResults("Test Results", passed, failed, errors, total, []);
326
+ }
327
+
328
+ _parseTestOutput(output, exitCode) {
329
+ let passed = 0, failed = 0, errors = 0;
330
+
331
+ const passedMatch = output.match(/(\d+) passed/);
332
+ const failedMatch = output.match(/(\d+) failed/);
333
+ const errorMatch = output.match(/(\d+) error/);
334
+
335
+ if (passedMatch) passed = parseInt(passedMatch[1]);
336
+ if (failedMatch) failed = parseInt(failedMatch[1]);
337
+ if (errorMatch) errors = parseInt(errorMatch[1]);
338
+
339
+ let total = passed + failed + errors;
340
+
341
+ if (total === 0) {
342
+ if (exitCode === 0) {
343
+ passed = 1;
344
+ total = 1;
345
+ } else {
346
+ failed = 1;
347
+ total = 1;
348
+ }
349
+ }
350
+
351
+ return { passed, failed, errors, total };
352
+ }
353
+
296
354
  _copyToClipboard(text) {
297
355
  const { execSync } = require('child_process');
298
356
  try {
@@ -106,9 +106,11 @@ class GoUISession {
106
106
 
107
107
  fs.writeFileSync(controlFile, JSON.stringify(status));
108
108
 
109
+ // Wait for process to exit
109
110
  // Wait for process to exit
110
111
  // In Node, we can't easily wait sync for background spawned process without busy loop or async
111
112
  // But for this simple implementation, we'll wait for the process to exit
113
+ return result;
112
114
  } catch (error) {
113
115
  const status = { status: 'error', message: error.message };
114
116
  fs.writeFileSync(controlFile, JSON.stringify(status));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tng-sh/js",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "TNG JavaScript CLI",
5
5
  "repository": {
6
6
  "type": "git",
Binary file
Binary file
Binary file
Binary file