@testspectra/cli 1.0.47 → 1.0.48

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.
@@ -76,6 +76,23 @@ function ensurePnpmWorkspaceIncludes(pnpmWorkspacePath, targetPath) {
76
76
  }
77
77
  }
78
78
  }
79
+ function ensureVsCodeSettings(cwd) {
80
+ const vscodeDir = path.join(cwd, ".vscode");
81
+ const settingsFile = path.join(vscodeDir, "settings.json");
82
+ if (!fs.existsSync(vscodeDir))
83
+ fs.mkdirSync(vscodeDir, { recursive: true });
84
+ let settings = {};
85
+ if (fs.existsSync(settingsFile)) {
86
+ try {
87
+ settings = JSON.parse(fs.readFileSync(settingsFile, "utf-8"));
88
+ }
89
+ catch { }
90
+ }
91
+ settings["typescript.tsdk"] = "node_modules/typescript/lib";
92
+ settings["typescript.enablePromptUseWorkspaceTsdk"] = true;
93
+ settings["typescript.tsserver.pluginPaths"] = ["./node_modules"];
94
+ fs.writeFileSync(settingsFile, JSON.stringify(settings, null, 2) + "\n", "utf-8");
95
+ }
79
96
  function scanDirectoriesForProjects(cwd, patterns) {
80
97
  const foundProjects = [];
81
98
  const visited = new Set();
@@ -502,6 +519,7 @@ export async function initCommand(options = {}) {
502
519
  fs.writeFileSync(rootTsConfigPath, JSON.stringify(rootTsConfig, null, 2), "utf-8");
503
520
  // 7. Generate Ambient Types in ROOT only
504
521
  TypeGenerator.writeDeclarationFiles(cwd);
522
+ ensureVsCodeSettings(cwd);
505
523
  const sharedPoLine = `${sharedTestingRelPath}/page-objects`.padEnd(28, " ");
506
524
  const sharedStepsLine = `${sharedTestingRelPath}/steps`.padEnd(28, " ");
507
525
  const sharedActLine = `${sharedTestingRelPath}/actions`.padEnd(28, " ");
@@ -692,6 +710,7 @@ pnpm type-check
692
710
  }
693
711
  }
694
712
  TypeGenerator.writeDeclarationFiles(cwd);
713
+ ensureVsCodeSettings(cwd);
695
714
  // Standalone Architecture Documentation
696
715
  const standaloneArchDoc = `# TestSpectra Project Architecture
697
716
 
@@ -1,3 +1,4 @@
1
- export declare function watchCommand(options?: {
2
- once?: boolean;
3
- }): void;
1
+ export interface WatchCommandOptions {
2
+ cwd?: string;
3
+ }
4
+ export declare function watchCommand(options?: WatchCommandOptions): Promise<void>;
@@ -1,30 +1,65 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
+ import chalk from "chalk";
3
4
  import { TypeGenerator } from "../types/generator.js";
4
- export function watchCommand(options = {}) {
5
- const cwd = process.cwd();
6
- // Run initial generation
7
- TypeGenerator.writeDeclarationFiles(cwd);
8
- console.log(`\x1b[32m[TestSpectra]\x1b[0m Generated ambient types in .testspectra/types/`);
9
- if (options.once) {
10
- return;
5
+ export async function watchCommand(options = {}) {
6
+ const cwd = options.cwd ? path.resolve(options.cwd) : process.cwd();
7
+ console.log(chalk.bold.cyan("\nšŸ”­ TestSpectra Ambient Types Watcher"));
8
+ console.log(chalk.gray(`Watching workspace: ${cwd}\n`));
9
+ // Initial generation
10
+ try {
11
+ TypeGenerator.writeDeclarationFiles(cwd);
12
+ console.log(chalk.green("āœ” Initialized ambient declarations in .testspectra/types/"));
11
13
  }
12
- console.log(`\x1b[34m[TestSpectra]\x1b[0m Watching for changes in page-objects/, actions/, steps/, fixtures/...`);
13
- const watchDirs = ["page-objects", "pageobjects", "actions", "steps", "fixtures"];
14
- let debounceTimeout = null;
15
- for (const dir of watchDirs) {
16
- const fullPath = path.join(cwd, dir);
17
- if (fs.existsSync(fullPath)) {
18
- fs.watch(fullPath, { recursive: true }, (_eventType, filename) => {
19
- if (!filename || filename.startsWith("."))
20
- return;
21
- if (debounceTimeout)
22
- clearTimeout(debounceTimeout);
23
- debounceTimeout = setTimeout(() => {
24
- TypeGenerator.writeDeclarationFiles(cwd);
25
- console.log(`\x1b[32m[TestSpectra]\x1b[0m Updated ambient declarations (.testspectra/types/) due to ${filename}`);
26
- }, 150);
27
- });
28
- }
14
+ catch (err) {
15
+ console.error(chalk.red(`āœ– Failed initial type generation: ${err?.message}`));
16
+ }
17
+ let debounceTimer = null;
18
+ const triggerRegen = (filePath, eventType) => {
19
+ if (debounceTimer)
20
+ clearTimeout(debounceTimer);
21
+ debounceTimer = setTimeout(() => {
22
+ try {
23
+ TypeGenerator.writeDeclarationFiles(cwd);
24
+ const time = new Date().toLocaleTimeString();
25
+ const rel = path.relative(cwd, filePath) || filePath;
26
+ console.log(chalk.gray(`[${time}] `) +
27
+ chalk.cyan(`✨ Updated ambient types `) +
28
+ chalk.gray(`(${eventType}: ${rel})`));
29
+ }
30
+ catch (err) {
31
+ console.error(chalk.red(`āœ– Error regenerating declarations: ${err?.message}`));
32
+ }
33
+ }, 100);
34
+ };
35
+ try {
36
+ const watcher = fs.watch(cwd, { recursive: true }, (eventType, filename) => {
37
+ if (!filename)
38
+ return;
39
+ const fn = filename.toString();
40
+ if (fn.includes(".testspectra") ||
41
+ fn.includes("node_modules") ||
42
+ fn.includes(".git") ||
43
+ fn.includes("dist") ||
44
+ fn.includes(".nx")) {
45
+ return;
46
+ }
47
+ if (fn.includes("fixtures") ||
48
+ fn.includes("page-objects") ||
49
+ fn.includes("pageobjects") ||
50
+ fn.includes("actions") ||
51
+ fn.includes("steps") ||
52
+ fn.includes("hooks") ||
53
+ fn.includes("spectra.config")) {
54
+ triggerRegen(path.join(cwd, fn), eventType);
55
+ }
56
+ });
57
+ watcher.on("error", (err) => {
58
+ console.error(chalk.red(`Watcher error: ${err?.message}`));
59
+ });
60
+ console.log(chalk.gray("Press Ctrl+C to stop watching.\n"));
61
+ }
62
+ catch (err) {
63
+ console.error(chalk.red(`Failed to start workspace watcher: ${err?.message}`));
29
64
  }
30
65
  }
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ import { devicesCommand } from "./commands/devices.js";
4
4
  import { doctorCommand } from "./commands/doctor.js";
5
5
  import { initCommand } from "./commands/init.js";
6
6
  import { runCommand } from "./commands/run.js";
7
+ import { watchCommand } from "./commands/watch.js";
7
8
  import { init } from "./plugin.js";
8
9
  export * from "./config/schema.js";
9
10
  export * from "./config/loader.js";
@@ -29,6 +30,11 @@ export function createCliProgram() {
29
30
  .option("-e, --e2e-folder <name>", "Name of E2E sub-folder (default: e2e)")
30
31
  .option("-f, --force", "Overwrite existing module files if present")
31
32
  .action(addCommand);
33
+ program
34
+ .command("watch")
35
+ .description("Watch workspace and continuously auto-generate TestSpectra ambient declarations")
36
+ .option("-w, --cwd <dir>", "Custom workspace directory")
37
+ .action(watchCommand);
32
38
  program
33
39
  .command("doctor")
34
40
  .description("Verify local environment prerequisites (ADB, Java, Chrome, Bun, Node)")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testspectra/cli",
3
- "version": "1.0.47",
3
+ "version": "1.0.48",
4
4
  "description": "TestSpectra Zero-Config Cross-Platform Test Runner CLI",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -21,7 +21,7 @@
21
21
  ],
22
22
  "dependencies": {
23
23
  "@clack/prompts": "^1.7.0",
24
- "@testspectra/matchers": "^1.0.47",
24
+ "@testspectra/matchers": "^1.0.48",
25
25
  "chalk": "^5.3.0",
26
26
  "commander": "^12.1.0",
27
27
  "dotenv": "^16.4.5",
@@ -0,0 +1,5 @@
1
+ {
2
+ "typescript.tsdk": "node_modules/typescript/lib",
3
+ "typescript.enablePromptUseWorkspaceTsdk": true,
4
+ "typescript.tsserver.pluginPaths": ["./node_modules"]
5
+ }
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "devDependencies": {
11
11
  "@testspectra/cli": "workspace:*",
12
- "@testspectra/matchers": "^1.0.47",
12
+ "@testspectra/matchers": "^1.0.48",
13
13
  "@types/node": "^20.14.0",
14
14
  "@wdio/globals": "^9.2.8",
15
15
  "@wdio/mocha-framework": "^9.2.8",
@@ -0,0 +1,5 @@
1
+ {
2
+ "typescript.tsdk": "node_modules/typescript/lib",
3
+ "typescript.enablePromptUseWorkspaceTsdk": true,
4
+ "typescript.tsserver.pluginPaths": ["./node_modules"]
5
+ }
@@ -11,7 +11,7 @@
11
11
  },
12
12
  "devDependencies": {
13
13
  "@testspectra/cli": "workspace:*",
14
- "@testspectra/matchers": "^1.0.47",
14
+ "@testspectra/matchers": "^1.0.48",
15
15
  "@types/node": "^20.14.0",
16
16
  "@wdio/globals": "^9.2.8",
17
17
  "@wdio/mocha-framework": "^9.2.8",