testdriverai 7.2.83 → 7.2.84
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/interfaces/cli/commands/init.js +11 -10
- package/lib/init-project.js +36 -27
- package/package.json +1 -1
|
@@ -28,15 +28,8 @@ class InitCommand extends BaseCommand {
|
|
|
28
28
|
// Prompt for API key first
|
|
29
29
|
const apiKey = await this.promptForApiKey();
|
|
30
30
|
|
|
31
|
-
//
|
|
32
|
-
const
|
|
33
|
-
targetDir: process.cwd(),
|
|
34
|
-
apiKey: apiKey,
|
|
35
|
-
skipInstall: false,
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
// Print results
|
|
39
|
-
for (const msg of result.results) {
|
|
31
|
+
// Helper to print progress messages with appropriate colors
|
|
32
|
+
const printProgress = (msg) => {
|
|
40
33
|
if (msg.startsWith("✓")) {
|
|
41
34
|
console.log(chalk.green(` ${msg}`));
|
|
42
35
|
} else if (msg.startsWith("⚠") || msg.startsWith("ℹ")) {
|
|
@@ -46,7 +39,15 @@ class InitCommand extends BaseCommand {
|
|
|
46
39
|
} else {
|
|
47
40
|
console.log(` ${msg}`);
|
|
48
41
|
}
|
|
49
|
-
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// Run the shared init logic with real-time progress output
|
|
45
|
+
const result = await initProject({
|
|
46
|
+
targetDir: process.cwd(),
|
|
47
|
+
apiKey: apiKey,
|
|
48
|
+
skipInstall: false,
|
|
49
|
+
onProgress: printProgress,
|
|
50
|
+
});
|
|
50
51
|
|
|
51
52
|
// Print errors if any
|
|
52
53
|
for (const err of result.errors) {
|
package/lib/init-project.js
CHANGED
|
@@ -9,18 +9,27 @@ const { execSync } = require("child_process");
|
|
|
9
9
|
* @param {string} [options.apiKey] - TestDriver API key (will be saved to .env)
|
|
10
10
|
* @param {boolean} [options.skipInstall=false] - Skip npm install step
|
|
11
11
|
* @param {boolean} [options.interactive=false] - Whether to prompt for missing values (CLI mode)
|
|
12
|
+
* @param {function} [options.onProgress] - Callback for progress updates (receives message string)
|
|
12
13
|
* @returns {Promise<{success: boolean, results: string[], errors: string[]}>}
|
|
13
14
|
*/
|
|
14
15
|
async function initProject(options = {}) {
|
|
15
16
|
const targetDir = options.targetDir || process.cwd();
|
|
16
17
|
const results = [];
|
|
17
18
|
const errors = [];
|
|
19
|
+
|
|
20
|
+
// Helper to report progress in real-time if callback provided
|
|
21
|
+
const progress = (msg) => {
|
|
22
|
+
results.push(msg);
|
|
23
|
+
if (options.onProgress) {
|
|
24
|
+
options.onProgress(msg);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
18
27
|
|
|
19
28
|
try {
|
|
20
29
|
// Create target directory if it doesn't exist
|
|
21
30
|
if (!fs.existsSync(targetDir)) {
|
|
22
31
|
fs.mkdirSync(targetDir, { recursive: true });
|
|
23
|
-
|
|
32
|
+
progress(`✓ Created directory: ${targetDir}`);
|
|
24
33
|
}
|
|
25
34
|
|
|
26
35
|
// 1. Setup package.json
|
|
@@ -44,9 +53,9 @@ async function initProject(options = {}) {
|
|
|
44
53
|
},
|
|
45
54
|
};
|
|
46
55
|
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + "\n");
|
|
47
|
-
|
|
56
|
+
progress("✓ Created package.json");
|
|
48
57
|
} else {
|
|
49
|
-
|
|
58
|
+
progress("⊘ package.json already exists, skipping");
|
|
50
59
|
}
|
|
51
60
|
|
|
52
61
|
// 2. Create test directory and example files
|
|
@@ -88,7 +97,7 @@ export async function login(testdriver) {
|
|
|
88
97
|
}
|
|
89
98
|
`;
|
|
90
99
|
fs.writeFileSync(loginSnippetFile, loginSnippetContent);
|
|
91
|
-
|
|
100
|
+
progress("✓ Created login snippet: tests/login.js");
|
|
92
101
|
}
|
|
93
102
|
|
|
94
103
|
// Create example test file
|
|
@@ -129,7 +138,7 @@ test('should login and add item to cart', async (context) => {
|
|
|
129
138
|
});
|
|
130
139
|
`;
|
|
131
140
|
fs.writeFileSync(testFile, vitestContent);
|
|
132
|
-
|
|
141
|
+
progress("✓ Created test file: tests/example.test.js");
|
|
133
142
|
}
|
|
134
143
|
|
|
135
144
|
// 3. Create vitest.config.js
|
|
@@ -152,7 +161,7 @@ export default defineConfig({
|
|
|
152
161
|
});
|
|
153
162
|
`;
|
|
154
163
|
fs.writeFileSync(configFile, configContent);
|
|
155
|
-
|
|
164
|
+
progress("✓ Created vitest.config.js");
|
|
156
165
|
}
|
|
157
166
|
|
|
158
167
|
// 4. Create/update .gitignore
|
|
@@ -171,9 +180,9 @@ export default defineConfig({
|
|
|
171
180
|
];
|
|
172
181
|
const newContent = gitignoreContent.trim() + "\n" + ignoresToAdd.join("\n") + "\n";
|
|
173
182
|
fs.writeFileSync(gitignorePath, newContent);
|
|
174
|
-
|
|
183
|
+
progress("✓ Updated .gitignore");
|
|
175
184
|
} else {
|
|
176
|
-
|
|
185
|
+
progress("⊘ .env already in .gitignore");
|
|
177
186
|
}
|
|
178
187
|
} else {
|
|
179
188
|
const ignoresToAdd = [
|
|
@@ -184,7 +193,7 @@ export default defineConfig({
|
|
|
184
193
|
"*.log",
|
|
185
194
|
];
|
|
186
195
|
fs.writeFileSync(gitignorePath, ignoresToAdd.join("\n") + "\n");
|
|
187
|
-
|
|
196
|
+
progress("✓ Created .gitignore");
|
|
188
197
|
}
|
|
189
198
|
|
|
190
199
|
// 5. Create GitHub Actions workflow
|
|
@@ -233,9 +242,9 @@ jobs:
|
|
|
233
242
|
retention-days: 30
|
|
234
243
|
`;
|
|
235
244
|
fs.writeFileSync(workflowFile, workflowContent);
|
|
236
|
-
|
|
245
|
+
progress("✓ Created GitHub workflow: .github/workflows/testdriver.yml");
|
|
237
246
|
} else {
|
|
238
|
-
|
|
247
|
+
progress("⊘ GitHub workflow already exists");
|
|
239
248
|
}
|
|
240
249
|
|
|
241
250
|
// 6. Create VSCode MCP config
|
|
@@ -266,9 +275,9 @@ jobs:
|
|
|
266
275
|
},
|
|
267
276
|
};
|
|
268
277
|
fs.writeFileSync(mcpConfigFile, JSON.stringify(mcpConfig, null, 2) + "\n");
|
|
269
|
-
|
|
278
|
+
progress("✓ Created MCP config: .vscode/mcp.json");
|
|
270
279
|
} else {
|
|
271
|
-
|
|
280
|
+
progress("⊘ MCP config already exists");
|
|
272
281
|
}
|
|
273
282
|
|
|
274
283
|
// 7. Create VSCode extensions recommendations
|
|
@@ -280,9 +289,9 @@ jobs:
|
|
|
280
289
|
],
|
|
281
290
|
};
|
|
282
291
|
fs.writeFileSync(extensionsFile, JSON.stringify(extensionsConfig, null, 2) + "\n");
|
|
283
|
-
|
|
292
|
+
progress("✓ Created extensions config: .vscode/extensions.json");
|
|
284
293
|
} else {
|
|
285
|
-
|
|
294
|
+
progress("⊘ Extensions config already exists");
|
|
286
295
|
}
|
|
287
296
|
|
|
288
297
|
// 8. Copy TestDriver skills
|
|
@@ -326,10 +335,10 @@ jobs:
|
|
|
326
335
|
}
|
|
327
336
|
|
|
328
337
|
if (copiedCount > 0) {
|
|
329
|
-
|
|
338
|
+
progress(`✓ Copied ${copiedCount} skills to .github/skills/`);
|
|
330
339
|
}
|
|
331
340
|
} else {
|
|
332
|
-
|
|
341
|
+
progress("⚠ Skills directory not found (will be available after npm install)");
|
|
333
342
|
}
|
|
334
343
|
|
|
335
344
|
// 9. Copy TestDriver agents
|
|
@@ -367,10 +376,10 @@ jobs:
|
|
|
367
376
|
}
|
|
368
377
|
|
|
369
378
|
if (copiedCount > 0) {
|
|
370
|
-
|
|
379
|
+
progress(`✓ Copied ${copiedCount} agent(s) to .github/agents/`);
|
|
371
380
|
}
|
|
372
381
|
} else {
|
|
373
|
-
|
|
382
|
+
progress("⚠ Agents directory not found (will be available after npm install)");
|
|
374
383
|
}
|
|
375
384
|
|
|
376
385
|
// 10. Handle API key if provided
|
|
@@ -390,30 +399,30 @@ jobs:
|
|
|
390
399
|
|
|
391
400
|
const newEnvContent = envContent.trim() + `\nTD_API_KEY=${options.apiKey}\n`;
|
|
392
401
|
fs.writeFileSync(envPath, newEnvContent);
|
|
393
|
-
|
|
402
|
+
progress("✓ Saved API key to .env");
|
|
394
403
|
} else {
|
|
395
|
-
|
|
396
|
-
|
|
404
|
+
progress("ℹ No API key provided - add it to .env manually:");
|
|
405
|
+
progress(" TD_API_KEY=your_api_key");
|
|
397
406
|
}
|
|
398
407
|
|
|
399
408
|
// 11. Install dependencies (unless skipped)
|
|
400
409
|
if (!options.skipInstall) {
|
|
401
|
-
|
|
410
|
+
progress("\n📦 Installing dependencies...");
|
|
402
411
|
try {
|
|
403
412
|
execSync("npm install -D vitest testdriverai@beta && npm install dotenv", {
|
|
404
413
|
cwd: targetDir,
|
|
405
414
|
stdio: "pipe",
|
|
406
415
|
});
|
|
407
|
-
|
|
416
|
+
progress("✓ Dependencies installed successfully");
|
|
408
417
|
} catch (error) {
|
|
409
418
|
errors.push("Failed to install dependencies. Run manually:");
|
|
410
419
|
errors.push(" npm install -D vitest testdriverai@beta");
|
|
411
420
|
errors.push(" npm install dotenv");
|
|
412
421
|
}
|
|
413
422
|
} else {
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
423
|
+
progress("\nℹ Skipped dependency installation. Run manually:");
|
|
424
|
+
progress(" npm install -D vitest testdriverai@beta");
|
|
425
|
+
progress(" npm install dotenv");
|
|
417
426
|
}
|
|
418
427
|
|
|
419
428
|
return { success: true, results, errors };
|