@tng-sh/js 0.0.5 → 0.0.7
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 +2 -2
- package/binaries/go-ui-darwin-amd64 +0 -0
- package/binaries/go-ui-darwin-arm64 +0 -0
- package/binaries/go-ui-linux-amd64 +0 -0
- package/binaries/go-ui-linux-arm64 +0 -0
- package/lib/generateTestsUi.js +67 -8
- package/lib/goUiSession.js +2 -0
- package/package.json +1 -1
- package/tng_sh_js.darwin-arm64.node +0 -0
- package/tng_sh_js.darwin-x64.node +0 -0
- package/tng_sh_js.linux-arm64-gnu.node +0 -0
- package/tng_sh_js.linux-x64-gnu.node +0 -0
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.
|
|
13
|
+
.description('TNG - Automated Test Generation, and audit generation for JavaScript')
|
|
14
|
+
.version('0.0.7');
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* @command init
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/lib/generateTestsUi.js
CHANGED
|
@@ -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 {
|
|
@@ -250,9 +250,13 @@ class GenerateTestsUI {
|
|
|
250
250
|
|
|
251
251
|
progress.update('Tests generated successfully!');
|
|
252
252
|
|
|
253
|
+
// Save the file inside the progress handler to match Python flow
|
|
254
|
+
const fileInfo = await saveTestFile(resultJson);
|
|
255
|
+
|
|
253
256
|
return {
|
|
254
257
|
message: 'Tests generated successfully!',
|
|
255
|
-
resultJson
|
|
258
|
+
resultJson,
|
|
259
|
+
file_path: fileInfo?.file_path
|
|
256
260
|
};
|
|
257
261
|
} catch (e) {
|
|
258
262
|
progress.error(`Failed to generate: ${e.message}`);
|
|
@@ -269,11 +273,7 @@ class GenerateTestsUI {
|
|
|
269
273
|
}
|
|
270
274
|
|
|
271
275
|
if (uiResult && uiResult.resultJson) {
|
|
272
|
-
|
|
273
|
-
return {
|
|
274
|
-
...uiResult,
|
|
275
|
-
file_path: fileInfo?.file_path
|
|
276
|
-
};
|
|
276
|
+
return uiResult;
|
|
277
277
|
}
|
|
278
278
|
|
|
279
279
|
return null;
|
|
@@ -287,12 +287,71 @@ class GenerateTestsUI {
|
|
|
287
287
|
const choice = this.goUiSession.showPostGenerationMenu(filePath, runCommand);
|
|
288
288
|
if (choice === 'back' || !choice) break;
|
|
289
289
|
|
|
290
|
-
if (choice === '
|
|
290
|
+
if (choice === 'run_tests') {
|
|
291
|
+
this._runAndShowTestResults(runCommand);
|
|
292
|
+
} else if (choice === 'copy_command') {
|
|
291
293
|
this._copyToClipboard(runCommand);
|
|
292
294
|
}
|
|
293
295
|
}
|
|
294
296
|
}
|
|
295
297
|
|
|
298
|
+
_runAndShowTestResults(command) {
|
|
299
|
+
const { execSync } = require('child_process');
|
|
300
|
+
|
|
301
|
+
const spinnerHandler = () => {
|
|
302
|
+
try {
|
|
303
|
+
const output = execSync(command, { encoding: 'utf8', stdio: 'pipe' });
|
|
304
|
+
return {
|
|
305
|
+
success: true,
|
|
306
|
+
message: "Tests completed",
|
|
307
|
+
output: output,
|
|
308
|
+
exit_code: 0
|
|
309
|
+
};
|
|
310
|
+
} catch (error) {
|
|
311
|
+
return {
|
|
312
|
+
success: true, // We still want to show the results even if tests failed
|
|
313
|
+
message: "Tests completed",
|
|
314
|
+
output: error.stdout + error.stderr,
|
|
315
|
+
exit_code: error.status
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
const testOutput = this.goUiSession.showSpinner("Running tests...", spinnerHandler);
|
|
321
|
+
|
|
322
|
+
// Note: For simplicity in the first pass, we provide counts.
|
|
323
|
+
// We can enhance _parseTestOutput if needed.
|
|
324
|
+
const { passed, failed, errors, total } = this._parseTestOutput(testOutput.output || "", testOutput.exit_code || 0);
|
|
325
|
+
|
|
326
|
+
this.goUiSession.showTestResults("Test Results", passed, failed, errors, total, []);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
_parseTestOutput(output, exitCode) {
|
|
330
|
+
let passed = 0, failed = 0, errors = 0;
|
|
331
|
+
|
|
332
|
+
const passedMatch = output.match(/(\d+) passed/);
|
|
333
|
+
const failedMatch = output.match(/(\d+) failed/);
|
|
334
|
+
const errorMatch = output.match(/(\d+) error/);
|
|
335
|
+
|
|
336
|
+
if (passedMatch) passed = parseInt(passedMatch[1]);
|
|
337
|
+
if (failedMatch) failed = parseInt(failedMatch[1]);
|
|
338
|
+
if (errorMatch) errors = parseInt(errorMatch[1]);
|
|
339
|
+
|
|
340
|
+
let total = passed + failed + errors;
|
|
341
|
+
|
|
342
|
+
if (total === 0) {
|
|
343
|
+
if (exitCode === 0) {
|
|
344
|
+
passed = 1;
|
|
345
|
+
total = 1;
|
|
346
|
+
} else {
|
|
347
|
+
failed = 1;
|
|
348
|
+
total = 1;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
return { passed, failed, errors, total };
|
|
353
|
+
}
|
|
354
|
+
|
|
296
355
|
_copyToClipboard(text) {
|
|
297
356
|
const { execSync } = require('child_process');
|
|
298
357
|
try {
|
package/lib/goUiSession.js
CHANGED
|
@@ -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
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|