@testspectra/cli 1.0.45 → 1.0.47

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/dist/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import { Command } from "commander";
2
+ import { init } from "./plugin.js";
2
3
  export * from "./config/schema.js";
3
4
  export * from "./config/loader.js";
4
5
  export * from "./types/generator.js";
5
6
  export * from "@testspectra/matchers";
6
- export { init as initTsPlugin, default as tsPlugin } from "./plugin.js";
7
+ export { init as initTsPlugin, init };
8
+ export default init;
7
9
  export declare function createCliProgram(): Command;
8
10
  export declare function runCli(args?: string[]): Promise<void>;
package/dist/index.js CHANGED
@@ -4,11 +4,13 @@ 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 { init } from "./plugin.js";
7
8
  export * from "./config/schema.js";
8
9
  export * from "./config/loader.js";
9
10
  export * from "./types/generator.js";
10
11
  export * from "@testspectra/matchers";
11
- export { init as initTsPlugin, default as tsPlugin } from "./plugin.js";
12
+ export { init as initTsPlugin, init };
13
+ export default init;
12
14
  export function createCliProgram() {
13
15
  const program = new Command();
14
16
  program
package/dist/plugin.d.ts CHANGED
@@ -10,6 +10,7 @@ declare function init(modules: {
10
10
  typescript: typeof ts;
11
11
  }): {
12
12
  create: (info: ts.server.PluginCreateInfo) => ts.LanguageService;
13
+ getExternalFiles: (project: ts.server.Project) => string[];
13
14
  };
14
15
  export default init;
15
16
  export { init };
package/dist/plugin.js CHANGED
@@ -18,6 +18,17 @@ function findWorkspaceRoot(startDir) {
18
18
  }
19
19
  return startDir;
20
20
  }
21
+ function appendLog(workspaceRoot, message) {
22
+ try {
23
+ const logDir = path.join(workspaceRoot, ".testspectra", "logs");
24
+ if (!fs.existsSync(logDir))
25
+ fs.mkdirSync(logDir, { recursive: true });
26
+ const logFile = path.join(logDir, "plugin.log");
27
+ const timestamp = new Date().toISOString();
28
+ fs.appendFileSync(logFile, `[${timestamp}] ${message}\n`, "utf-8");
29
+ }
30
+ catch { }
31
+ }
21
32
  /**
22
33
  * TypeScript Language Service Plugin Factory for TestSpectra.
23
34
  * Runs silently inside TSServer (VS Code, Cursor, WebStorm, Neovim, etc.).
@@ -36,11 +47,13 @@ function init(modules) {
36
47
  info.project.projectService.logger.info(`[TestSpectra TS Plugin] ${msg}`);
37
48
  }
38
49
  catch { }
50
+ appendLog(workspaceRoot, msg);
39
51
  };
52
+ log(`Plugin initialized on project: ${projectDir} (resolved root: ${workspaceRoot})`);
40
53
  // 1. Initial Generation on project load
41
54
  try {
42
55
  TypeGenerator.writeDeclarationFiles(workspaceRoot);
43
- log(`Initialized ambient declarations in workspace root: ${workspaceRoot}`);
56
+ log(`Generated ambient declarations on startup`);
44
57
  }
45
58
  catch (err) {
46
59
  log(`Failed initial type generation: ${err?.message}`);
@@ -89,10 +102,12 @@ function init(modules) {
89
102
  fn.includes("steps") ||
90
103
  fn.includes("hooks") ||
91
104
  fn.includes("spectra.config")) {
105
+ log(`Detected file change [${eventType}]: ${fn}`);
92
106
  triggerRegeneration(`fs.watch '${eventType}' on ${fn}`);
93
107
  }
94
108
  });
95
109
  watcher.on("error", () => { });
110
+ log(`Attached recursive fs.watch on ${workspaceRoot}`);
96
111
  }
97
112
  }
98
113
  catch (err) {
@@ -126,7 +141,33 @@ function init(modules) {
126
141
  };
127
142
  return proxy;
128
143
  }
129
- return { create };
144
+ function getExternalFiles(project) {
145
+ try {
146
+ const workspaceRoot = findWorkspaceRoot(project.getCurrentDirectory());
147
+ const typesDir = path.join(workspaceRoot, ".testspectra", "types");
148
+ const files = [];
149
+ function collectDts(dir) {
150
+ if (!fs.existsSync(dir))
151
+ return;
152
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
153
+ for (const entry of entries) {
154
+ const fullPath = path.join(dir, entry.name);
155
+ if (entry.isDirectory()) {
156
+ collectDts(fullPath);
157
+ }
158
+ else if (entry.isFile() && entry.name.endsWith(".d.ts")) {
159
+ files.push(fullPath);
160
+ }
161
+ }
162
+ }
163
+ collectDts(typesDir);
164
+ return files;
165
+ }
166
+ catch {
167
+ return [];
168
+ }
169
+ }
170
+ return { create, getExternalFiles };
130
171
  }
131
172
  export default init;
132
173
  export { init };
@@ -165,28 +165,51 @@ export class TypeGenerator {
165
165
  const classFolder = path.join(poDir, className);
166
166
  let matchedFile = null;
167
167
  for (const stem of hierarchy) {
168
- const cand = path.join(classFolder, `${stem}.ts`);
169
- if (fs.existsSync(cand)) {
170
- matchedFile = path.relative(outputTypesDir, cand).replace(/\\/g, "/").replace(/\.ts$/, ".js");
171
- if (!matchedFile.startsWith("."))
172
- matchedFile = `./${matchedFile}`;
173
- break;
168
+ const candidates = [
169
+ path.join(classFolder, `${stem}.ts`),
170
+ path.join(classFolder, `${stem}.page.ts`),
171
+ path.join(classFolder, `${stem}.po.ts`),
172
+ path.join(classFolder, "index.ts"),
173
+ path.join(classFolder, "common.ts"),
174
+ ];
175
+ for (const cand of candidates) {
176
+ if (fs.existsSync(cand)) {
177
+ matchedFile = path.relative(outputTypesDir, cand).replace(/\\/g, "/").replace(/\.ts$/, ".js");
178
+ if (!matchedFile.startsWith("."))
179
+ matchedFile = `./${matchedFile}`;
180
+ break;
181
+ }
174
182
  }
183
+ if (matchedFile)
184
+ break;
175
185
  }
176
186
  if (matchedFile) {
177
- content += `declare const ${className}: typeof import('${matchedFile}').default;\n`;
187
+ content += `declare const ${className}: (typeof import('${matchedFile}') extends { default: infer T } ? T : typeof import('${matchedFile}'));\n`;
178
188
  declaredPOMs.add(className);
179
189
  }
180
190
  }
181
191
  else if (entry.isFile() && entry.name.endsWith(".ts")) {
182
- const className = entry.name.split(".")[0];
192
+ const parts = entry.name.split(".");
193
+ const className = parts[0];
183
194
  if (declaredPOMs.has(className))
184
195
  continue;
185
- let rel = path.relative(outputTypesDir, path.join(poDir, entry.name)).replace(/\\/g, "/").replace(/\.ts$/, ".js");
186
- if (!rel.startsWith("."))
187
- rel = `./${rel}`;
188
- content += `declare const ${className}: typeof import('${rel}').default;\n`;
189
- declaredPOMs.add(className);
196
+ let isMatch = false;
197
+ if (parts.length === 2) {
198
+ // E.g. ProfilePage.ts (applies to all platforms)
199
+ isMatch = true;
200
+ }
201
+ else if (parts.length > 2) {
202
+ // E.g. ProfilePage.web.ts or ProfilePage.android.ts
203
+ const stem = parts[1];
204
+ isMatch = hierarchy.includes(stem);
205
+ }
206
+ if (isMatch) {
207
+ let rel = path.relative(outputTypesDir, path.join(poDir, entry.name)).replace(/\\/g, "/").replace(/\.ts$/, ".js");
208
+ if (!rel.startsWith("."))
209
+ rel = `./${rel}`;
210
+ content += `declare const ${className}: (typeof import('${rel}') extends { default: infer T } ? T : typeof import('${rel}'));\n`;
211
+ declaredPOMs.add(className);
212
+ }
190
213
  }
191
214
  }
192
215
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testspectra/cli",
3
- "version": "1.0.45",
3
+ "version": "1.0.47",
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.45",
24
+ "@testspectra/matchers": "^1.0.47",
25
25
  "chalk": "^5.3.0",
26
26
  "commander": "^12.1.0",
27
27
  "dotenv": "^16.4.5",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "devDependencies": {
11
11
  "@testspectra/cli": "workspace:*",
12
- "@testspectra/matchers": "^1.0.45",
12
+ "@testspectra/matchers": "^1.0.47",
13
13
  "@types/node": "^20.14.0",
14
14
  "@wdio/globals": "^9.2.8",
15
15
  "@wdio/mocha-framework": "^9.2.8",
@@ -11,7 +11,7 @@
11
11
  },
12
12
  "devDependencies": {
13
13
  "@testspectra/cli": "workspace:*",
14
- "@testspectra/matchers": "^1.0.45",
14
+ "@testspectra/matchers": "^1.0.47",
15
15
  "@types/node": "^20.14.0",
16
16
  "@wdio/globals": "^9.2.8",
17
17
  "@wdio/mocha-framework": "^9.2.8",