@tng-sh/js 0.1.9 → 0.2.0

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
@@ -284,7 +284,7 @@ program
284
284
  const binaryPath = session._binaryPath;
285
285
 
286
286
  const { spawnSync } = require('child_process');
287
- spawnSync(binaryPath, ['trace-results', '--file', tmpFile], {
287
+ spawnSync(binaryPath, ['js-trace-results', '--file', tmpFile], {
288
288
  stdio: 'inherit'
289
289
  });
290
290
 
@@ -611,17 +611,20 @@ async function generateTest(filePath, methodName, testType, auditMode = false, j
611
611
  if (saved) {
612
612
  jsonSession.emitEvent('test_saved', {
613
613
  file_path: saved.file_path,
614
+ absolute_path: saved.absolute_path,
614
615
  message: `Test saved to: ${saved.file_path}`
615
616
  });
616
617
  } else {
617
- jsonSession.displayError('Failed to save test file');
618
+ const details = saveTestFile.lastError ? `: ${saveTestFile.lastError}` : '';
619
+ jsonSession.displayError(`Failed to save test file${details}`);
618
620
  }
619
621
  jsonSession.stop();
620
622
  } else {
621
623
  if (saved) {
622
624
  console.log(chalk.green(`✓ Test saved to: ${saved.file_path}`));
623
625
  } else {
624
- console.log(chalk.yellow('Failed to save test file'));
626
+ const details = saveTestFile.lastError ? `: ${saveTestFile.lastError}` : '';
627
+ console.log(chalk.yellow(`Failed to save test file${details}`));
625
628
  }
626
629
  }
627
630
  }
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -700,7 +700,7 @@ class GenerateTestsUI {
700
700
  if (result && result.success && result.file) {
701
701
  // 2. Show Trace UI
702
702
  const { spawnSync } = require('child_process');
703
- spawnSync(this.goUiSession._binaryPath, ['trace-results', '--file', result.file], {
703
+ spawnSync(this.goUiSession._binaryPath, ['js-trace-results', '--file', result.file], {
704
704
  stdio: 'inherit'
705
705
  });
706
706
 
package/lib/saveFile.js CHANGED
@@ -4,6 +4,7 @@ const chalk = require('chalk');
4
4
  const prettier = require('prettier');
5
5
 
6
6
  const saveTestFile = async (testContent) => {
7
+ saveTestFile.lastError = null;
7
8
  try {
8
9
  const parsed = typeof testContent === 'string' ? JSON.parse(testContent) : testContent;
9
10
 
@@ -31,6 +32,14 @@ const saveTestFile = async (testContent) => {
31
32
  return null;
32
33
  }
33
34
 
35
+ // Quick sanity check for likely truncation (common when API cuts the response)
36
+ const trimmedContent = contentStr.trim();
37
+ if (trimmedContent.includes('describe(') && !/}\);\s*$/.test(trimmedContent)) {
38
+ const msg = 'Generated test content appears truncated (missing closing `});`)';
39
+ console.log(chalk.red.bold(`❌ ${msg}`));
40
+ return null;
41
+ }
42
+
34
43
  // Resolve file path
35
44
  let filePath = metaSource.test_file_path || metaSource.file_path || metaSource.file_name || metaSource.file ||
36
45
  parsed.test_file_path || parsed.file_path || 'generated_test.js';
@@ -60,14 +69,66 @@ const saveTestFile = async (testContent) => {
60
69
 
61
70
  // Format with Prettier
62
71
  let formattedContent = contentStr;
63
- try {
72
+ const tryFormat = async (input) => {
64
73
  const prettierOptions = (await prettier.resolveConfig(absolutePath)) || { semi: true, singleQuote: true, parser: 'babel' };
65
- // Fallback parser if filepath doesn't help
66
74
  if (!prettierOptions.parser) prettierOptions.parser = 'babel';
67
- formattedContent = prettier.format(contentStr, { ...prettierOptions, filepath: absolutePath });
75
+ return prettier.format(input, { ...prettierOptions, filepath: absolutePath });
76
+ };
77
+
78
+ const sanitizeExpectStringHelpers = (input) => {
79
+ const targets = ['expect.stringContaining("', 'expect.stringMatching("'];
80
+ let output = '';
81
+ let idx = 0;
82
+
83
+ while (idx < input.length) {
84
+ let nextIndex = -1;
85
+ let matched = '';
86
+ for (const t of targets) {
87
+ const i = input.indexOf(t, idx);
88
+ if (i !== -1 && (nextIndex === -1 || i < nextIndex)) {
89
+ nextIndex = i;
90
+ matched = t;
91
+ }
92
+ }
93
+ if (nextIndex === -1) {
94
+ output += input.slice(idx);
95
+ break;
96
+ }
97
+
98
+ output += input.slice(idx, nextIndex);
99
+ const start = nextIndex + matched.length;
100
+ const end = input.indexOf('")', start);
101
+ if (end === -1) {
102
+ output += input.slice(nextIndex);
103
+ break;
104
+ }
105
+
106
+ const inner = input.slice(start, end);
107
+ const escaped = inner.replace(/`/g, '\\`');
108
+ const helper = matched.startsWith('expect.stringMatching')
109
+ ? 'expect.stringMatching'
110
+ : 'expect.stringContaining';
111
+ output += `${helper}(String.raw\`${escaped}\`)`;
112
+ idx = end + 2;
113
+ }
114
+
115
+ return output;
116
+ };
117
+
118
+ try {
119
+ formattedContent = await tryFormat(contentStr);
68
120
  } catch (prettierError) {
69
- // Best effort formatting
70
- console.log(chalk.yellow(`⚠ Prettier formatting failed, saving raw: ${prettierError.message}`));
121
+ // Try a targeted sanitize pass for malformed string literals, then re-format
122
+ const sanitized = sanitizeExpectStringHelpers(contentStr);
123
+ if (sanitized !== contentStr) {
124
+ try {
125
+ formattedContent = await tryFormat(sanitized);
126
+ } catch (secondError) {
127
+ console.log(chalk.yellow(`⚠ Prettier formatting failed after sanitize, saving raw: ${secondError.message}`));
128
+ }
129
+ } else {
130
+ console.log(chalk.yellow(`⚠ Prettier formatting failed, saving raw: ${prettierError.message}`));
131
+ }
71
132
  }
72
133
 
73
134
  fs.writeFileSync(absolutePath, formattedContent);
@@ -78,9 +139,12 @@ const saveTestFile = async (testContent) => {
78
139
  framework: metaSource.framework || parsed.framework || 'jest'
79
140
  };
80
141
  } catch (error) {
81
- console.log(chalk.red.bold(`❌ Failed to save test file: ${error.message}`));
142
+ saveTestFile.lastError = error?.message || 'Unknown error';
143
+ console.log(chalk.red.bold(`❌ Failed to save test file: ${saveTestFile.lastError}`));
82
144
  return null;
83
145
  }
84
146
  };
85
147
 
148
+ saveTestFile.lastError = null;
149
+
86
150
  module.exports = { saveTestFile };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tng-sh/js",
3
- "version": "0.1.9",
3
+ "version": "0.2.0",
4
4
  "description": "TNG JavaScript CLI",
5
5
  "repository": {
6
6
  "type": "git",