@tng-sh/js 0.0.2 → 0.0.4
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/README.md +13 -3
- package/bin/tng.js +8 -24
- 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/config.js +0 -3
- package/lib/generateTestsUi.js +0 -2
- package/lib/jsonSession.js +0 -16
- package/lib/saveFile.js +0 -1
- 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/README.md
CHANGED
|
@@ -14,21 +14,31 @@ npm install @tng-sh/js --save-dev
|
|
|
14
14
|
Run the init command to create a `tng.config.js` configuration file in your project:
|
|
15
15
|
|
|
16
16
|
```bash
|
|
17
|
-
npx tng init
|
|
17
|
+
npx -p @tng-sh/js tng init
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
### 2. Generate Tests
|
|
21
21
|
Generate a test for a specific function in a file:
|
|
22
22
|
|
|
23
23
|
```bash
|
|
24
|
-
npx tng -f path/to/file.js -m functionName
|
|
24
|
+
npx -p @tng-sh/js tng -f path/to/file.js -m functionName -t react_component
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
+
**Supported Types (`-t`):**
|
|
28
|
+
- `react_component`
|
|
29
|
+
- `express_handler`
|
|
30
|
+
- `graphql_resolver`
|
|
31
|
+
- `nest_js` (Service/Controller)
|
|
32
|
+
- `orm_model`
|
|
33
|
+
- `background_job`
|
|
34
|
+
- `mailer`
|
|
35
|
+
- `utility`
|
|
36
|
+
|
|
27
37
|
### 3. Interactive Mode
|
|
28
38
|
Launch the interactive UI to explore and generate tests visually:
|
|
29
39
|
|
|
30
40
|
```bash
|
|
31
|
-
npx tng i
|
|
41
|
+
npx -p @tng-sh/js tng i
|
|
32
42
|
```
|
|
33
43
|
|
|
34
44
|
## Features
|
package/bin/tng.js
CHANGED
|
@@ -11,7 +11,7 @@ const { ping, getUserStats } = require('../index');
|
|
|
11
11
|
program
|
|
12
12
|
.name('tng')
|
|
13
13
|
.description('TNG - Automated Test Generation for JavaScript')
|
|
14
|
-
.version('0.0.
|
|
14
|
+
.version('0.0.4');
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* @command init
|
|
@@ -132,14 +132,16 @@ program
|
|
|
132
132
|
program
|
|
133
133
|
.option('-m, --method <name>', 'Method name to test')
|
|
134
134
|
.option('-f, --file <path>', 'JavaScript file path')
|
|
135
|
-
.option('-t, --type <type>', 'Component type (react_component, express_handler, etc)')
|
|
135
|
+
.option('-t, --type <type>', 'Component type (react_component, express_handler, etc) [required]')
|
|
136
136
|
.option('-a, --audit', 'Run audit mode instead of test generation')
|
|
137
137
|
.option('--json', 'Output results as JSON events (machine-readable)')
|
|
138
|
-
|
|
138
|
+
|
|
139
139
|
.action(async (options) => {
|
|
140
|
-
if (options.
|
|
141
|
-
|
|
142
|
-
|
|
140
|
+
if (options.method && options.file) {
|
|
141
|
+
if (!options.type && !options.audit) {
|
|
142
|
+
console.log(chalk.red('Error: --type <type> is required.'));
|
|
143
|
+
process.exit(1);
|
|
144
|
+
}
|
|
143
145
|
generateTest(options.file, options.method, options.type, options.audit, options.json);
|
|
144
146
|
} else if (options.file && !options.method) {
|
|
145
147
|
console.log(chalk.yellow('Specify a method with -m, use --outline to see methods, or run "tng i" for full selection.'));
|
|
@@ -148,25 +150,7 @@ program
|
|
|
148
150
|
}
|
|
149
151
|
});
|
|
150
152
|
|
|
151
|
-
/**
|
|
152
|
-
* Output file outline (methods)
|
|
153
|
-
*/
|
|
154
|
-
function printOutline(filePath) {
|
|
155
|
-
const absolutePath = path.resolve(filePath);
|
|
156
|
-
if (!fs.existsSync(absolutePath)) {
|
|
157
|
-
console.error(chalk.red(`File not found: ${filePath}`));
|
|
158
|
-
process.exit(1);
|
|
159
|
-
}
|
|
160
153
|
|
|
161
|
-
const { getFileOutline } = require('../index');
|
|
162
|
-
try {
|
|
163
|
-
const outlineJson = getFileOutline(absolutePath);
|
|
164
|
-
console.log(outlineJson);
|
|
165
|
-
} catch (error) {
|
|
166
|
-
console.error(chalk.red(`Error getting outline: ${error.message}`));
|
|
167
|
-
process.exit(1);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
154
|
|
|
171
155
|
/**
|
|
172
156
|
* Logic to generate test or run audit (delegates to native binary)
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/lib/config.js
CHANGED
|
@@ -9,12 +9,9 @@ const loadConfig = () => {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
try {
|
|
12
|
-
// Clear cache to allow reloading config in same process if needed (rare for CLI but good practice)
|
|
13
12
|
delete require.cache[require.resolve(configFile)];
|
|
14
13
|
const config = require(configFile);
|
|
15
14
|
|
|
16
|
-
// Filter for uppercase keys to match Python's convention,
|
|
17
|
-
// but fallback to the whole object if none are uppercase.
|
|
18
15
|
const filtered = {};
|
|
19
16
|
for (const [key, value] of Object.entries(config)) {
|
|
20
17
|
if (key === key.toUpperCase()) {
|
package/lib/generateTestsUi.js
CHANGED
|
@@ -150,11 +150,9 @@ class GenerateTestsUI {
|
|
|
150
150
|
const selectedMethod = items.find(i => i.name === selectedDisplay)?.methodData;
|
|
151
151
|
|
|
152
152
|
if (selectedMethod) {
|
|
153
|
-
// New Step: Select Test Type
|
|
154
153
|
const testType = this.goUiSession.showJsTestMenu();
|
|
155
154
|
if (testType === 'back') return this._showFileSelection(isAudit);
|
|
156
155
|
|
|
157
|
-
// Handle auto-detect (pass null)
|
|
158
156
|
const finalType = testType === 'auto' ? null : testType;
|
|
159
157
|
|
|
160
158
|
const choice = await this._generateTestsForMethod(filePath, selectedMethod, finalType, isAudit);
|
package/lib/jsonSession.js
CHANGED
|
@@ -36,10 +36,6 @@ class JsonSession {
|
|
|
36
36
|
return this.running;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
// ------------------------------------------------------------------
|
|
40
|
-
// Progress
|
|
41
|
-
// ------------------------------------------------------------------
|
|
42
|
-
|
|
43
39
|
showProgress(title, callback) {
|
|
44
40
|
this.emitEvent('progress_start', { title });
|
|
45
41
|
|
|
@@ -64,10 +60,6 @@ class JsonSession {
|
|
|
64
60
|
}
|
|
65
61
|
}
|
|
66
62
|
|
|
67
|
-
// ------------------------------------------------------------------
|
|
68
|
-
// Results Display
|
|
69
|
-
// ------------------------------------------------------------------
|
|
70
|
-
|
|
71
63
|
showAuditResults(auditResult) {
|
|
72
64
|
this.emitEvent('result', auditResult);
|
|
73
65
|
}
|
|
@@ -83,10 +75,6 @@ class JsonSession {
|
|
|
83
75
|
});
|
|
84
76
|
}
|
|
85
77
|
|
|
86
|
-
// ------------------------------------------------------------------
|
|
87
|
-
// Errors & Warnings
|
|
88
|
-
// ------------------------------------------------------------------
|
|
89
|
-
|
|
90
78
|
showAuthError(message = 'Authentication failed') {
|
|
91
79
|
this.emitEvent('auth_error', { message });
|
|
92
80
|
}
|
|
@@ -107,10 +95,6 @@ class JsonSession {
|
|
|
107
95
|
this.emitEvent('no_items', { type });
|
|
108
96
|
}
|
|
109
97
|
|
|
110
|
-
// ------------------------------------------------------------------
|
|
111
|
-
// Private Methods
|
|
112
|
-
// ------------------------------------------------------------------
|
|
113
|
-
|
|
114
98
|
stripColors(str) {
|
|
115
99
|
// Remove ANSI color codes
|
|
116
100
|
return str.replace(/\x1b\[\d+(;\d+)*m/g, '');
|
package/lib/saveFile.js
CHANGED
|
@@ -46,7 +46,6 @@ const saveTestFile = async (testContent) => {
|
|
|
46
46
|
filePath = filePath.replace(/\.[^.]+$/, '') + '.js';
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
// Add timestamp prefix (mirroring python logic)
|
|
50
49
|
const hasTimestamp = /^\d+_/.test(path.basename(filePath));
|
|
51
50
|
if (!hasTimestamp) {
|
|
52
51
|
const timestamp = new Date().toISOString().replace(/[-:T]/g, '').split('.')[0];
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|