spana-test 0.1.0 → 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/.agents/skills/spana-testing/SKILL.md +4 -1
- package/README.md +277 -86
- package/dist/agent/index.d.ts +34 -5
- package/dist/agent/index.js +14 -10
- package/dist/{chunk-RK4Z6C7M.js → chunk-3YR4GUGE.js} +3 -2
- package/dist/chunk-3YR4GUGE.js.map +1 -0
- package/dist/{chunk-WIJYK22K.js → chunk-AEKDFFPJ.js} +2 -2
- package/dist/chunk-BF37W5EG.js +125 -0
- package/dist/chunk-BF37W5EG.js.map +1 -0
- package/dist/chunk-EXLUY7KT.js +21 -0
- package/dist/chunk-EXLUY7KT.js.map +1 -0
- package/dist/chunk-FNDOEMOL.js +62 -0
- package/dist/chunk-FNDOEMOL.js.map +1 -0
- package/dist/chunk-HWFDXIXR.js +183 -0
- package/dist/chunk-HWFDXIXR.js.map +1 -0
- package/dist/chunk-IJIASIX5.js +314 -0
- package/dist/chunk-IJIASIX5.js.map +1 -0
- package/dist/chunk-KJPHH2TW.js +168 -0
- package/dist/chunk-KJPHH2TW.js.map +1 -0
- package/dist/{chunk-RJ5VPHVX.js → chunk-L7MFJF46.js} +16 -6
- package/dist/chunk-L7MFJF46.js.map +1 -0
- package/dist/{chunk-5XO6S7AI.js → chunk-MRH7SK52.js} +4 -4
- package/dist/chunk-MRH7SK52.js.map +1 -0
- package/dist/{chunk-53MUJUJY.js → chunk-P7JQRLP4.js} +5 -4
- package/dist/{chunk-53MUJUJY.js.map → chunk-P7JQRLP4.js.map} +1 -1
- package/dist/chunk-S2XNAKSO.js +1087 -0
- package/dist/chunk-S2XNAKSO.js.map +1 -0
- package/dist/{chunk-VDWWIVM6.js → chunk-S4R4OR7T.js} +108 -53
- package/dist/chunk-S4R4OR7T.js.map +1 -0
- package/dist/{chunk-V62HFH6E.js → chunk-SFBRFB2N.js} +14 -6
- package/dist/chunk-SFBRFB2N.js.map +1 -0
- package/dist/{chunk-PWEOJKUF.js → chunk-VNYF5BHX.js} +28 -7
- package/dist/chunk-VNYF5BHX.js.map +1 -0
- package/dist/chunk-WBU34APM.js +38 -0
- package/dist/chunk-WBU34APM.js.map +1 -0
- package/dist/{chunk-CKJQX73M.js → chunk-WQ4GXUUE.js} +921 -352
- package/dist/chunk-WQ4GXUUE.js.map +1 -0
- package/dist/chunk-YBZCOQXJ.js +311 -0
- package/dist/chunk-YBZCOQXJ.js.map +1 -0
- package/dist/cli.js +316 -40
- package/dist/cli.js.map +1 -1
- package/dist/{compiler-G75RIIYS.js → compiler-74VGKZO6.js} +2 -2
- package/dist/{compiler-G75RIIYS.js.map → compiler-74VGKZO6.js.map} +1 -1
- package/dist/config-loader-BJJ3IJJ7.js +9 -0
- package/dist/{console-FV4RJPO4.js → console-XWKUTP3D.js} +39 -7
- package/dist/console-XWKUTP3D.js.map +1 -0
- package/dist/{config-Dg9O0rcQ.d.ts → coordinator-BbUjvvnX.d.ts} +165 -1
- package/dist/{discover-RWBKI5IB.js → discover-KZKXHZZA.js} +3 -3
- package/dist/doctor-command-T2UX5RV5.js +732 -0
- package/dist/doctor-command-T2UX5RV5.js.map +1 -0
- package/dist/{element-CGteXiXB.d.ts → element-DZ0HyJ3C.d.ts} +2 -0
- package/dist/{flow-D-_tlLpp.d.ts → flow-BUC9Mf8W.d.ts} +38 -9
- package/dist/gherkin/steps.d.ts +2 -2
- package/dist/{html-JP2HBIJQ.js → html-GE6Q4DCG.js} +23 -3
- package/dist/html-GE6Q4DCG.js.map +1 -0
- package/dist/index.d.ts +171 -3
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/dist/{init-command-CELKL2CX.js → init-command-GVMRXIMY.js} +37 -21
- package/dist/init-command-GVMRXIMY.js.map +1 -0
- package/dist/init-flow-command-R76AXF4Z.js +34 -0
- package/dist/init-flow-command-R76AXF4Z.js.map +1 -0
- package/dist/{installer-R6NX7BYQ.js → installer-YZJ4DV3F.js} +4 -2
- package/dist/{ios-ZZU6DHH7.js → ios-ZW6XVNLG.js} +4 -2
- package/dist/json-KS67BZYU.js +39 -0
- package/dist/json-KS67BZYU.js.map +1 -0
- package/dist/{junit-UDY5JG22.js → junit-HLC62MK6.js} +2 -2
- package/dist/junit-HLC62MK6.js.map +1 -0
- package/dist/provider-A57C3MU6.js +12 -0
- package/dist/{redact-IDA3C4UH.js → redact-U72BUBBR.js} +2 -2
- package/dist/{redact-IDA3C4UH.js.map → redact-U72BUBBR.js.map} +1 -1
- package/dist/{runner-QEF6PJOE.js → runner-UXNHVVGG.js} +2 -2
- package/dist/{server-MMK7PZIH.js → server-W7OA3DDN.js} +49 -24
- package/dist/server-W7OA3DDN.js.map +1 -0
- package/dist/session-TMNOKYLG.js +17 -0
- package/dist/{studio-command-CDVPREMG.js → studio-command-6VHTHDUK.js} +2 -2
- package/dist/{test-command-SB5KYPQI.js → test-command-AHMOZLV4.js} +1280 -357
- package/dist/test-command-AHMOZLV4.js.map +1 -0
- package/dist/validator-35624P7S.js +20 -0
- package/package.json +1 -1
- package/studio-dist/assets/index-DC6DIXfl.js +188 -0
- package/studio-dist/assets/index-DDKsnBwD.css +1 -0
- package/studio-dist/index.html +2 -2
- package/dist/chunk-5XO6S7AI.js.map +0 -1
- package/dist/chunk-BZRLA4Z3.js +0 -82
- package/dist/chunk-BZRLA4Z3.js.map +0 -1
- package/dist/chunk-CKJQX73M.js.map +0 -1
- package/dist/chunk-PANFRTIU.js +0 -310
- package/dist/chunk-PANFRTIU.js.map +0 -1
- package/dist/chunk-PWEOJKUF.js.map +0 -1
- package/dist/chunk-RJ5VPHVX.js.map +0 -1
- package/dist/chunk-RK4Z6C7M.js.map +0 -1
- package/dist/chunk-U564GCO2.js +0 -259
- package/dist/chunk-U564GCO2.js.map +0 -1
- package/dist/chunk-V62HFH6E.js.map +0 -1
- package/dist/chunk-VDWWIVM6.js.map +0 -1
- package/dist/config-loader-JJ5RPP53.js +0 -9
- package/dist/console-FV4RJPO4.js.map +0 -1
- package/dist/html-JP2HBIJQ.js.map +0 -1
- package/dist/init-command-CELKL2CX.js.map +0 -1
- package/dist/json-JMRPUVY2.js +0 -20
- package/dist/json-JMRPUVY2.js.map +0 -1
- package/dist/junit-UDY5JG22.js.map +0 -1
- package/dist/provider-CUWPULGC.js +0 -10
- package/dist/server-MMK7PZIH.js.map +0 -1
- package/dist/session-FBJABNXL.js +0 -16
- package/dist/test-command-SB5KYPQI.js.map +0 -1
- package/dist/validator-CFQ55NUQ.js +0 -13
- package/studio-dist/assets/index-CPdpC9i-.css +0 -1
- package/studio-dist/assets/index-L1Wd0vop.js +0 -183
- /package/dist/{chunk-WIJYK22K.js.map → chunk-AEKDFFPJ.js.map} +0 -0
- /package/dist/{config-loader-JJ5RPP53.js.map → config-loader-BJJ3IJJ7.js.map} +0 -0
- /package/dist/{discover-RWBKI5IB.js.map → discover-KZKXHZZA.js.map} +0 -0
- /package/dist/{installer-R6NX7BYQ.js.map → installer-YZJ4DV3F.js.map} +0 -0
- /package/dist/{ios-ZZU6DHH7.js.map → ios-ZW6XVNLG.js.map} +0 -0
- /package/dist/{provider-CUWPULGC.js.map → provider-A57C3MU6.js.map} +0 -0
- /package/dist/{runner-QEF6PJOE.js.map → runner-UXNHVVGG.js.map} +0 -0
- /package/dist/{session-FBJABNXL.js.map → session-TMNOKYLG.js.map} +0 -0
- /package/dist/{studio-command-CDVPREMG.js.map → studio-command-6VHTHDUK.js.map} +0 -0
- /package/dist/{validator-CFQ55NUQ.js.map → validator-35624P7S.js.map} +0 -0
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
2
|
+
collectDiagnosticSections
|
|
3
|
+
} from "./chunk-KJPHH2TW.js";
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
resolveCapabilities
|
|
6
|
+
} from "./chunk-EXLUY7KT.js";
|
|
7
|
+
import {
|
|
8
|
+
loadConfig
|
|
9
|
+
} from "./chunk-P7JQRLP4.js";
|
|
8
10
|
import {
|
|
9
11
|
createPromiseApp,
|
|
10
12
|
createPromiseExpect
|
|
11
|
-
} from "./chunk-
|
|
12
|
-
import "./chunk-
|
|
13
|
+
} from "./chunk-YBZCOQXJ.js";
|
|
14
|
+
import "./chunk-L7MFJF46.js";
|
|
13
15
|
import {
|
|
14
16
|
createUiAutomator2Driver,
|
|
15
17
|
createWDADriver,
|
|
16
18
|
makePlaywrightDriver,
|
|
17
19
|
parseAndroidHierarchy,
|
|
18
20
|
parseIOSHierarchy,
|
|
19
|
-
parseWebHierarchy
|
|
21
|
+
parseWebHierarchy
|
|
22
|
+
} from "./chunk-WQ4GXUUE.js";
|
|
23
|
+
import {
|
|
20
24
|
setupUiAutomator2
|
|
21
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-BF37W5EG.js";
|
|
22
26
|
import {
|
|
23
27
|
applyShard,
|
|
24
28
|
discoverFlows,
|
|
@@ -26,15 +30,21 @@ import {
|
|
|
26
30
|
filterFlows,
|
|
27
31
|
loadStepFiles,
|
|
28
32
|
loadTestSource
|
|
29
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-MRH7SK52.js";
|
|
30
34
|
import {
|
|
31
35
|
DriverError,
|
|
32
|
-
flattenElements
|
|
33
|
-
|
|
36
|
+
flattenElements,
|
|
37
|
+
splitGraphemes,
|
|
38
|
+
withBufferedDriverLogs
|
|
39
|
+
} from "./chunk-S2XNAKSO.js";
|
|
34
40
|
import {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
} from "./chunk-
|
|
41
|
+
failureCategoryToDocsUrl,
|
|
42
|
+
failureCategoryToErrorCode
|
|
43
|
+
} from "./chunk-FNDOEMOL.js";
|
|
44
|
+
import {
|
|
45
|
+
createCloudProviderHelper,
|
|
46
|
+
detectProvider
|
|
47
|
+
} from "./chunk-VNYF5BHX.js";
|
|
38
48
|
import {
|
|
39
49
|
ensureAndroidDevice
|
|
40
50
|
} from "./chunk-GZK22EIE.js";
|
|
@@ -43,11 +53,18 @@ import {
|
|
|
43
53
|
ensureAppInstalled,
|
|
44
54
|
ensureIOSSimulator,
|
|
45
55
|
firstIOSPhysicalDevice
|
|
46
|
-
} from "./chunk-
|
|
56
|
+
} from "./chunk-SFBRFB2N.js";
|
|
57
|
+
import {
|
|
58
|
+
allocatePort,
|
|
59
|
+
setupWDA
|
|
60
|
+
} from "./chunk-3YR4GUGE.js";
|
|
47
61
|
import "./chunk-DGUM43GV.js";
|
|
48
62
|
|
|
49
63
|
// src/cli/test-command.ts
|
|
50
|
-
import { resolve, dirname } from "path";
|
|
64
|
+
import { resolve as resolve3, dirname as dirname3 } from "path";
|
|
65
|
+
|
|
66
|
+
// src/core/engine.ts
|
|
67
|
+
import { Effect as Effect3 } from "effect";
|
|
51
68
|
|
|
52
69
|
// src/core/artifacts.ts
|
|
53
70
|
import { writeFileSync, mkdirSync } from "fs";
|
|
@@ -59,10 +76,13 @@ var DEFAULT_ARTIFACT_CONFIG = {
|
|
|
59
76
|
captureOnSuccess: false,
|
|
60
77
|
captureSteps: false,
|
|
61
78
|
screenshot: true,
|
|
62
|
-
uiHierarchy: true
|
|
79
|
+
uiHierarchy: true,
|
|
80
|
+
consoleLogs: true,
|
|
81
|
+
jsErrors: true,
|
|
82
|
+
har: true
|
|
63
83
|
};
|
|
64
84
|
function safeName(value) {
|
|
65
|
-
return value.
|
|
85
|
+
return value.replaceAll(/[^a-zA-Z0-9-_]/g, "_").replaceAll(/_+/g, "_").replaceAll(/^_+|_+$/g, "").slice(0, 80) || "artifact";
|
|
66
86
|
}
|
|
67
87
|
function flowArtifactDir(config, flowName, platform) {
|
|
68
88
|
const dir = join(config.outputDir, `${safeName(flowName)}-${platform}`);
|
|
@@ -72,6 +92,16 @@ function flowArtifactDir(config, flowName, platform) {
|
|
|
72
92
|
function createAttachment(name, contentType, path) {
|
|
73
93
|
return { name, contentType, path };
|
|
74
94
|
}
|
|
95
|
+
function writeJsonAttachment(dir, fileName, attachmentName, value) {
|
|
96
|
+
const path = join(dir, fileName);
|
|
97
|
+
writeFileSync(path, JSON.stringify(value, null, 2), "utf-8");
|
|
98
|
+
return createAttachment(attachmentName, "application/json", path);
|
|
99
|
+
}
|
|
100
|
+
function writeTextAttachment(dir, fileName, attachmentName, value) {
|
|
101
|
+
const path = join(dir, fileName);
|
|
102
|
+
writeFileSync(path, value, "utf-8");
|
|
103
|
+
return createAttachment(attachmentName, "text/plain", path);
|
|
104
|
+
}
|
|
75
105
|
function resolveArtifactConfig(...configs) {
|
|
76
106
|
return configs.reduce(
|
|
77
107
|
(resolved, config) => ({
|
|
@@ -104,6 +134,53 @@ async function captureArtifacts(driver, config, flowName, platform, status) {
|
|
|
104
134
|
} catch {
|
|
105
135
|
}
|
|
106
136
|
}
|
|
137
|
+
if (config.consoleLogs && driver.getConsoleLogs) {
|
|
138
|
+
try {
|
|
139
|
+
const consoleLogs = await Effect.runPromise(Effect.orDie(driver.getConsoleLogs()));
|
|
140
|
+
if (consoleLogs.length > 0) {
|
|
141
|
+
attachments.push(
|
|
142
|
+
writeJsonAttachment(dir, "console-logs.json", `${status}-console-logs`, consoleLogs)
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
} catch {
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (config.jsErrors && driver.getJSErrors) {
|
|
149
|
+
try {
|
|
150
|
+
const jsErrors = await Effect.runPromise(Effect.orDie(driver.getJSErrors()));
|
|
151
|
+
if (jsErrors.length > 0) {
|
|
152
|
+
attachments.push(
|
|
153
|
+
writeJsonAttachment(dir, "js-errors.json", `${status}-js-errors`, jsErrors)
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
} catch {
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (config.har && driver.getHAR) {
|
|
160
|
+
try {
|
|
161
|
+
const har = await Effect.runPromise(Effect.orDie(driver.getHAR()));
|
|
162
|
+
if (har.log.entries.length > 0) {
|
|
163
|
+
attachments.push(writeJsonAttachment(dir, "network.har", `${status}-network-har`, har));
|
|
164
|
+
}
|
|
165
|
+
} catch {
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (status === "failed" && driver.getDriverLogs) {
|
|
169
|
+
try {
|
|
170
|
+
const driverLogs = await Effect.runPromise(Effect.orDie(driver.getDriverLogs()));
|
|
171
|
+
if (driverLogs.length > 0) {
|
|
172
|
+
attachments.push(
|
|
173
|
+
writeTextAttachment(
|
|
174
|
+
dir,
|
|
175
|
+
"driver-logs.txt",
|
|
176
|
+
`${status}-driver-logs`,
|
|
177
|
+
driverLogs.join("\n")
|
|
178
|
+
)
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
} catch {
|
|
182
|
+
}
|
|
183
|
+
}
|
|
107
184
|
return attachments;
|
|
108
185
|
}
|
|
109
186
|
async function captureStepScreenshot(driver, config, flowName, platform, stepIndex, stepName, screenshot) {
|
|
@@ -173,7 +250,7 @@ async function runDebugReplOnce(context) {
|
|
|
173
250
|
console.log("selectors Async helper returning suggested selectors");
|
|
174
251
|
console.log(".exit Leave the REPL");
|
|
175
252
|
};
|
|
176
|
-
await new Promise((
|
|
253
|
+
await new Promise((resolve4) => replServer.on("exit", resolve4));
|
|
177
254
|
console.log("");
|
|
178
255
|
return true;
|
|
179
256
|
}
|
|
@@ -289,17 +366,74 @@ function selectorHint(selector) {
|
|
|
289
366
|
}
|
|
290
367
|
return JSON.stringify(selector);
|
|
291
368
|
}
|
|
292
|
-
function
|
|
293
|
-
const
|
|
369
|
+
function categorizeElementFailure(message) {
|
|
370
|
+
const lower = message.toLowerCase();
|
|
371
|
+
if (lower.includes("not visible") || lower.includes("visible=false")) {
|
|
372
|
+
return "element-not-visible";
|
|
373
|
+
}
|
|
374
|
+
if (lower.includes("off-screen") || lower.includes("zero size")) {
|
|
375
|
+
return "element-off-screen";
|
|
376
|
+
}
|
|
377
|
+
if (lower.includes("disabled") || lower.includes("not interactive")) {
|
|
378
|
+
return "element-not-interactive";
|
|
379
|
+
}
|
|
380
|
+
return "element-not-found";
|
|
381
|
+
}
|
|
382
|
+
function elementSuggestion(category, selector, timeoutMs) {
|
|
383
|
+
switch (category) {
|
|
384
|
+
case "element-not-visible":
|
|
385
|
+
return [
|
|
386
|
+
`Selector ${selector} matched an element, but it is currently hidden.`,
|
|
387
|
+
"Check whether an animation, modal, or loading state is covering it before retrying.",
|
|
388
|
+
"Consider increasing waitTimeout if the element becomes visible after a delay."
|
|
389
|
+
].join("\n");
|
|
390
|
+
case "element-off-screen":
|
|
391
|
+
return [
|
|
392
|
+
`Selector ${selector} matched an element that is off-screen.`,
|
|
393
|
+
"Use scrollUntilVisible() or scroll to the element before interacting with it.",
|
|
394
|
+
"If the target is above the current viewport, reverse the search direction."
|
|
395
|
+
].join("\n");
|
|
396
|
+
case "element-not-interactive":
|
|
397
|
+
return [
|
|
398
|
+
`Selector ${selector} matched an element that is disabled or not interactive.`,
|
|
399
|
+
"Wait for the app to enable it, or verify the prerequisite app state first.",
|
|
400
|
+
"Consider increasing waitTimeout if the control becomes enabled after async work completes."
|
|
401
|
+
].join("\n");
|
|
402
|
+
default:
|
|
403
|
+
return [
|
|
404
|
+
`Selector ${selector} was not found within ${timeoutMs ?? "?"}ms.`,
|
|
405
|
+
"Run `spana selectors` to inspect the current screen and confirm the best selector.",
|
|
406
|
+
"Consider increasing waitTimeout if the element appears after a delay."
|
|
407
|
+
].join("\n");
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
function categorizeDynamic(error, tag, msg) {
|
|
294
411
|
if (tag === "ElementNotFoundError" || tag === "WaitTimeoutError") {
|
|
295
412
|
const sel = selectorHint(error.selector);
|
|
413
|
+
if (msg.includes("scroll(s) toward")) {
|
|
414
|
+
return {
|
|
415
|
+
category: "element-not-found",
|
|
416
|
+
suggestion: [
|
|
417
|
+
`Selector ${sel} stayed off-screen while scrolling.`,
|
|
418
|
+
"Try increasing `maxScrolls` or `timeout`, or reverse the search direction",
|
|
419
|
+
'if the target is actually above the current viewport (for example `{ direction: "up" }`).'
|
|
420
|
+
].join("\n")
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
if (msg.includes("back action(s)")) {
|
|
424
|
+
return {
|
|
425
|
+
category: "element-not-found",
|
|
426
|
+
suggestion: [
|
|
427
|
+
`Selector ${sel} was not reached while navigating back.`,
|
|
428
|
+
"Try increasing `maxBacks` or `timeout`, or prefer an explicit in-app",
|
|
429
|
+
"back / close control on iOS-style screens instead of relying on system back."
|
|
430
|
+
].join("\n")
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
const category = categorizeElementFailure(msg);
|
|
296
434
|
return {
|
|
297
|
-
category
|
|
298
|
-
suggestion:
|
|
299
|
-
`Selector ${sel} was not found within ${error.timeoutMs ?? "?"}ms.`,
|
|
300
|
-
"Try: run `spana selectors` to see available selectors on the current screen,",
|
|
301
|
-
"or increase the timeout with `{ timeout: 10000 }` on the assertion."
|
|
302
|
-
].join("\n")
|
|
435
|
+
category,
|
|
436
|
+
suggestion: elementSuggestion(category, sel, error.timeoutMs)
|
|
303
437
|
};
|
|
304
438
|
}
|
|
305
439
|
if (tag === "TextMismatchError") {
|
|
@@ -313,16 +447,6 @@ function categorize(error) {
|
|
|
313
447
|
].join("\n")
|
|
314
448
|
};
|
|
315
449
|
}
|
|
316
|
-
if (tag === "TimeoutError") {
|
|
317
|
-
return {
|
|
318
|
-
category: "timeout",
|
|
319
|
-
suggestion: [
|
|
320
|
-
"The operation took longer than the allowed timeout.",
|
|
321
|
-
"Try increasing `defaults.waitTimeout` in spana.config.ts,",
|
|
322
|
-
"or set a per-flow timeout: `flow('name', { timeout: 30000 }, ...)`."
|
|
323
|
-
].join("\n")
|
|
324
|
-
};
|
|
325
|
-
}
|
|
326
450
|
if (tag === "DeviceDisconnectedError") {
|
|
327
451
|
const id = error.deviceId ? ` (${error.deviceId})` : "";
|
|
328
452
|
return {
|
|
@@ -357,35 +481,125 @@ function categorize(error) {
|
|
|
357
481
|
};
|
|
358
482
|
}
|
|
359
483
|
if (tag === "DriverError") {
|
|
360
|
-
return
|
|
361
|
-
category: "driver-error",
|
|
362
|
-
suggestion: error.command ? `Driver command "${error.command}" failed. Check the device connection and driver logs.` : "A low-level driver operation failed. Check the device connection and driver logs."
|
|
363
|
-
};
|
|
484
|
+
return categorizeDynamicDriver(error, msg);
|
|
364
485
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
486
|
+
return void 0;
|
|
487
|
+
}
|
|
488
|
+
function categorizeDynamicDriver(error, msg) {
|
|
489
|
+
for (const rule of driverRules) {
|
|
490
|
+
if (rule.pattern && matchesPattern(msg, rule.pattern)) {
|
|
491
|
+
return {
|
|
492
|
+
category: typeof rule.category === "function" ? rule.category(msg) : rule.category,
|
|
493
|
+
suggestion: typeof rule.suggestion === "function" ? rule.suggestion(error, msg) : rule.suggestion
|
|
494
|
+
};
|
|
495
|
+
}
|
|
370
496
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
497
|
+
return {
|
|
498
|
+
category: "driver-error",
|
|
499
|
+
suggestion: error.command ? `Driver command "${error.command}" failed. Check the device connection and driver logs.` : "A low-level driver operation failed. Check the device connection and driver logs."
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
var driverRules = [
|
|
503
|
+
{
|
|
504
|
+
pattern: "dismissKeyboard()",
|
|
505
|
+
category: "driver-error",
|
|
506
|
+
suggestion: [
|
|
507
|
+
"Keyboard dismissal failed.",
|
|
508
|
+
'On Android, try `app.dismissKeyboard({ strategy: "back" })`.',
|
|
509
|
+
"On iOS, prefer tapping a visible Done / Close control or a non-input element."
|
|
510
|
+
].join("\n")
|
|
511
|
+
},
|
|
512
|
+
{
|
|
513
|
+
pattern: "backUntilVisible()",
|
|
514
|
+
category: "driver-error",
|
|
515
|
+
suggestion: [
|
|
516
|
+
"System back navigation failed before the target screen became visible.",
|
|
517
|
+
"If this route uses app-level navigation, tap the visible back / close control instead.",
|
|
518
|
+
"This is especially common on iOS where a system back button may not exist."
|
|
519
|
+
].join("\n")
|
|
520
|
+
},
|
|
521
|
+
{
|
|
522
|
+
pattern: "Input text failed",
|
|
523
|
+
category: "driver-error",
|
|
524
|
+
suggestion: [
|
|
525
|
+
"Text input failed at the driver layer.",
|
|
526
|
+
"Make sure the field is focused first, and retry with shorter input chunks if needed.",
|
|
527
|
+
"If the keyboard is in the way, dismiss it before continuing the flow."
|
|
528
|
+
].join("\n")
|
|
377
529
|
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
530
|
+
];
|
|
531
|
+
var tagOnlyRules = [
|
|
532
|
+
{
|
|
533
|
+
tag: "TimeoutError",
|
|
534
|
+
category: "timeout",
|
|
535
|
+
suggestion: [
|
|
536
|
+
"The operation took longer than the allowed timeout.",
|
|
537
|
+
"Try increasing `defaults.waitTimeout` in spana.config.ts,",
|
|
538
|
+
"or set a per-flow timeout: `flow('name', { timeout: 30000 }, ...)`."
|
|
539
|
+
].join("\n")
|
|
540
|
+
},
|
|
541
|
+
{
|
|
542
|
+
tag: ["ConfigError", "FlowSyntaxError"],
|
|
543
|
+
category: "config-error",
|
|
544
|
+
suggestion: "Run `spana validate-config` to check your configuration."
|
|
383
545
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
546
|
+
];
|
|
547
|
+
var heuristicRules = [
|
|
548
|
+
{
|
|
549
|
+
pattern: /[Tt]imed out/,
|
|
550
|
+
category: "timeout",
|
|
551
|
+
suggestion: "The operation timed out. Try increasing `defaults.waitTimeout` in spana.config.ts."
|
|
552
|
+
},
|
|
553
|
+
{
|
|
554
|
+
pattern: /not found|not visible/,
|
|
555
|
+
category: (msg) => categorizeElementFailure(msg),
|
|
556
|
+
suggestion: (_error, msg) => {
|
|
557
|
+
if (msg.includes("scroll(s) toward")) {
|
|
558
|
+
return "The target stayed off-screen while scrolling. Increase `maxScrolls` / `timeout`, or reverse the scroll search direction.";
|
|
559
|
+
}
|
|
560
|
+
const category = categorizeElementFailure(msg);
|
|
561
|
+
return elementSuggestion(category, "the target selector", void 0);
|
|
562
|
+
}
|
|
563
|
+
},
|
|
564
|
+
{
|
|
565
|
+
pattern: "dismissKeyboard()",
|
|
566
|
+
category: "driver-error",
|
|
567
|
+
suggestion: 'Keyboard dismissal failed. On Android try `app.dismissKeyboard({ strategy: "back" })`; on iOS prefer an explicit Done / Close control.'
|
|
568
|
+
},
|
|
569
|
+
{
|
|
570
|
+
pattern: /ECONNREFUSED|ECONNRESET|disconnected/,
|
|
571
|
+
category: "device-disconnected",
|
|
572
|
+
suggestion: "The connection was lost. Check the device or emulator/simulator is still running."
|
|
573
|
+
}
|
|
574
|
+
];
|
|
575
|
+
function matchesPattern(msg, pattern) {
|
|
576
|
+
return typeof pattern === "string" ? msg.includes(pattern) : pattern.test(msg);
|
|
577
|
+
}
|
|
578
|
+
function matchesTag(tag, rule) {
|
|
579
|
+
if (!rule.tag) return true;
|
|
580
|
+
if (Array.isArray(rule.tag)) return tag != null && rule.tag.includes(tag);
|
|
581
|
+
return tag === rule.tag;
|
|
582
|
+
}
|
|
583
|
+
function categorize(error) {
|
|
584
|
+
const tag = error[TAG_KEY];
|
|
585
|
+
const msg = error.message ?? "";
|
|
586
|
+
const dynamic = categorizeDynamic(error, tag, msg);
|
|
587
|
+
if (dynamic) return dynamic;
|
|
588
|
+
for (const rule of tagOnlyRules) {
|
|
589
|
+
if (matchesTag(tag, rule)) {
|
|
590
|
+
return {
|
|
591
|
+
category: typeof rule.category === "function" ? rule.category(msg) : rule.category,
|
|
592
|
+
suggestion: typeof rule.suggestion === "function" ? rule.suggestion(error, msg) : rule.suggestion
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
for (const rule of heuristicRules) {
|
|
597
|
+
if (rule.pattern && matchesPattern(msg, rule.pattern)) {
|
|
598
|
+
return {
|
|
599
|
+
category: typeof rule.category === "function" ? rule.category(msg) : rule.category,
|
|
600
|
+
suggestion: typeof rule.suggestion === "function" ? rule.suggestion(error, msg) : rule.suggestion
|
|
601
|
+
};
|
|
602
|
+
}
|
|
389
603
|
}
|
|
390
604
|
return { category: "unknown" };
|
|
391
605
|
}
|
|
@@ -396,7 +610,10 @@ function classifyError(error) {
|
|
|
396
610
|
message: error.message,
|
|
397
611
|
stack: error.stack,
|
|
398
612
|
category,
|
|
399
|
-
|
|
613
|
+
errorCode: failureCategoryToErrorCode(category),
|
|
614
|
+
suggestion,
|
|
615
|
+
suggestedFix: suggestion,
|
|
616
|
+
docsUrl: failureCategoryToDocsUrl(category)
|
|
400
617
|
};
|
|
401
618
|
}
|
|
402
619
|
|
|
@@ -415,25 +632,42 @@ async function executeFlow(flow, driver, config) {
|
|
|
415
632
|
...coordinatorConfig.defaults,
|
|
416
633
|
timeout: flowDefaults.waitTimeout ?? coordinatorConfig.defaults?.timeout,
|
|
417
634
|
pollInterval: flowDefaults.pollInterval ?? coordinatorConfig.defaults?.pollInterval,
|
|
418
|
-
settleTimeout: flowDefaults.settleTimeout ?? coordinatorConfig.defaults?.settleTimeout
|
|
635
|
+
settleTimeout: flowDefaults.settleTimeout ?? coordinatorConfig.defaults?.settleTimeout,
|
|
636
|
+
initialPollInterval: flowDefaults.initialPollInterval ?? coordinatorConfig.defaults?.initialPollInterval
|
|
419
637
|
},
|
|
420
638
|
waitForIdleTimeout: flowDefaults.waitForIdleTimeout ?? coordinatorConfig.waitForIdleTimeout,
|
|
421
|
-
typingDelay: flowDefaults.typingDelay ?? coordinatorConfig.typingDelay
|
|
639
|
+
typingDelay: flowDefaults.typingDelay ?? coordinatorConfig.typingDelay,
|
|
640
|
+
hierarchyCacheTtl: flowDefaults.hierarchyCacheTtl ?? coordinatorConfig.hierarchyCacheTtl
|
|
422
641
|
} : coordinatorConfig;
|
|
423
642
|
const app = createPromiseApp(driver, appId, mergedCoordinatorConfig, stepRecorder);
|
|
424
643
|
const expect = createPromiseExpect(driver, mergedCoordinatorConfig, stepRecorder);
|
|
425
644
|
const flowCtx = { app, expect, platform };
|
|
645
|
+
const buildFailureResult = async (error) => {
|
|
646
|
+
const attachments = await captureArtifacts(driver, artifactConfig, flow.name, platform, "failed");
|
|
647
|
+
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
648
|
+
return {
|
|
649
|
+
name: flow.name,
|
|
650
|
+
platform,
|
|
651
|
+
status: "failed",
|
|
652
|
+
durationMs: Date.now() - start2,
|
|
653
|
+
error: classifyError(normalized),
|
|
654
|
+
attachments,
|
|
655
|
+
steps: stepRecorder.getSteps(),
|
|
656
|
+
scenarioSteps: flowCtx.__scenarioSteps
|
|
657
|
+
};
|
|
658
|
+
};
|
|
659
|
+
if (driver.beginFlow) {
|
|
660
|
+
try {
|
|
661
|
+
await Effect3.runPromise(driver.beginFlow(flow.name));
|
|
662
|
+
} catch (error) {
|
|
663
|
+
return buildFailureResult(error);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
426
666
|
if (config.hooks?.beforeEach) {
|
|
427
667
|
try {
|
|
428
668
|
await config.hooks.beforeEach({ app, platform });
|
|
429
669
|
} catch (error) {
|
|
430
|
-
return
|
|
431
|
-
name: flow.name,
|
|
432
|
-
platform,
|
|
433
|
-
status: "failed",
|
|
434
|
-
durationMs: Date.now() - start2,
|
|
435
|
-
error: classifyError(error instanceof Error ? error : new Error(String(error)))
|
|
436
|
-
};
|
|
670
|
+
return buildFailureResult(error);
|
|
437
671
|
}
|
|
438
672
|
}
|
|
439
673
|
let result;
|
|
@@ -509,112 +743,234 @@ async function executeFlow(flow, driver, config) {
|
|
|
509
743
|
return result;
|
|
510
744
|
}
|
|
511
745
|
|
|
512
|
-
// src/core/
|
|
513
|
-
async function
|
|
746
|
+
// src/core/parallel.ts
|
|
747
|
+
async function runParallel(config) {
|
|
748
|
+
const { workers, flows, onFlowComplete, onFlowStart, retries = 0, retryDelay = 0, bail } = config;
|
|
514
749
|
const start2 = Date.now();
|
|
515
|
-
const
|
|
516
|
-
|
|
750
|
+
const results = [];
|
|
751
|
+
let nextFlowIndex = 0;
|
|
517
752
|
let failureCount = 0;
|
|
518
753
|
let bailedOut = false;
|
|
519
|
-
const
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
754
|
+
const workerPromises = workers.map(async (worker) => {
|
|
755
|
+
const stats = { flowCount: 0, totalMs: 0 };
|
|
756
|
+
while (true) {
|
|
757
|
+
if (bail !== void 0 && failureCount >= bail) break;
|
|
758
|
+
const flowIdx = nextFlowIndex++;
|
|
759
|
+
if (flowIdx >= flows.length) break;
|
|
760
|
+
const flow = flows[flowIdx];
|
|
761
|
+
let result;
|
|
762
|
+
let attempts = 0;
|
|
763
|
+
onFlowStart?.(flow.name, worker.name);
|
|
764
|
+
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
765
|
+
if (attempt > 0 && retryDelay > 0) {
|
|
766
|
+
await new Promise((resolve4) => setTimeout(resolve4, retryDelay));
|
|
767
|
+
}
|
|
768
|
+
result = await executeFlow(flow, worker.driver, worker.engineConfig);
|
|
769
|
+
attempts++;
|
|
770
|
+
if (result.status === "passed") break;
|
|
771
|
+
}
|
|
772
|
+
if (result.status === "passed" && attempts > 1) {
|
|
773
|
+
result.flaky = true;
|
|
774
|
+
}
|
|
775
|
+
result.attempts = attempts;
|
|
776
|
+
results.push(result);
|
|
777
|
+
stats.flowCount++;
|
|
778
|
+
stats.totalMs += result.durationMs;
|
|
779
|
+
if (result.status === "failed") {
|
|
780
|
+
failureCount++;
|
|
781
|
+
}
|
|
782
|
+
onFlowComplete?.(result, worker.name);
|
|
783
|
+
}
|
|
784
|
+
return { workerId: worker.id, stats };
|
|
785
|
+
});
|
|
786
|
+
const workerResults = await Promise.all(workerPromises);
|
|
787
|
+
if (bail !== void 0 && failureCount >= bail) {
|
|
788
|
+
bailedOut = true;
|
|
789
|
+
while (nextFlowIndex < flows.length) {
|
|
790
|
+
const flow = flows[nextFlowIndex++];
|
|
791
|
+
results.push({
|
|
792
|
+
name: flow.name,
|
|
793
|
+
platform: workers[0].engineConfig.platform,
|
|
794
|
+
status: "skipped",
|
|
795
|
+
durationMs: 0,
|
|
796
|
+
attempts: 0
|
|
797
|
+
});
|
|
524
798
|
}
|
|
799
|
+
}
|
|
800
|
+
const workerStats = /* @__PURE__ */ new Map();
|
|
801
|
+
for (const wr of workerResults) {
|
|
802
|
+
workerStats.set(wr.workerId, wr.stats);
|
|
803
|
+
}
|
|
804
|
+
return {
|
|
805
|
+
results,
|
|
806
|
+
totalDurationMs: Date.now() - start2,
|
|
807
|
+
passed: results.filter((r) => r.status === "passed").length,
|
|
808
|
+
failed: results.filter((r) => r.status === "failed").length,
|
|
809
|
+
skipped: results.filter((r) => r.status === "skipped").length,
|
|
810
|
+
flaky: results.filter((r) => r.flaky === true).length,
|
|
811
|
+
bailedOut: bailedOut || void 0,
|
|
812
|
+
workerStats
|
|
525
813
|
};
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
// src/core/orchestrator.ts
|
|
817
|
+
async function sleep(ms) {
|
|
818
|
+
if (ms <= 0) return;
|
|
819
|
+
return new Promise((resolve4) => setTimeout(resolve4, ms));
|
|
820
|
+
}
|
|
821
|
+
async function runPlatform(flows, platformConfig, options, shouldBail, noteFailure) {
|
|
822
|
+
const { platform, driver, engineConfig } = platformConfig;
|
|
823
|
+
const retries = options?.retries ?? 0;
|
|
824
|
+
const retryDelay = options?.retryDelay ?? 0;
|
|
825
|
+
const results = [];
|
|
826
|
+
const platformFlows = flows.filter((f) => {
|
|
827
|
+
const fp = f.config.platforms;
|
|
828
|
+
return !fp || fp.includes(platform);
|
|
829
|
+
});
|
|
830
|
+
if (shouldBail()) {
|
|
831
|
+
for (const flow of platformFlows) {
|
|
832
|
+
results.push({ name: flow.name, platform, status: "skipped", durationMs: 0 });
|
|
833
|
+
}
|
|
834
|
+
return { results };
|
|
835
|
+
}
|
|
836
|
+
const hooks = engineConfig.hooks;
|
|
837
|
+
if (hooks?.beforeAll) {
|
|
838
|
+
try {
|
|
839
|
+
await hooks.beforeAll({ app: void 0, platform });
|
|
840
|
+
} catch (error) {
|
|
535
841
|
for (const flow of platformFlows) {
|
|
536
842
|
results.push({
|
|
537
843
|
name: flow.name,
|
|
538
844
|
platform,
|
|
539
|
-
status: "
|
|
540
|
-
durationMs: 0
|
|
845
|
+
status: "failed",
|
|
846
|
+
durationMs: 0,
|
|
847
|
+
error: classifyError(error instanceof Error ? error : new Error(String(error)))
|
|
541
848
|
});
|
|
542
849
|
}
|
|
543
|
-
|
|
544
|
-
|
|
850
|
+
noteFailure(platformFlows.length);
|
|
851
|
+
return { results };
|
|
545
852
|
}
|
|
546
|
-
|
|
547
|
-
|
|
853
|
+
}
|
|
854
|
+
if (platformConfig.additionalWorkers && platformConfig.additionalWorkers.length > 0) {
|
|
855
|
+
const allWorkers = [
|
|
856
|
+
{
|
|
857
|
+
id: `${platform}-primary`,
|
|
858
|
+
name: platform,
|
|
859
|
+
driver,
|
|
860
|
+
engineConfig
|
|
861
|
+
},
|
|
862
|
+
...platformConfig.additionalWorkers
|
|
863
|
+
];
|
|
864
|
+
const parallelResult = await runParallel({
|
|
865
|
+
workers: allWorkers,
|
|
866
|
+
flows: platformFlows,
|
|
867
|
+
retries: options?.retries ?? 0,
|
|
868
|
+
retryDelay: options?.retryDelay ?? 0,
|
|
869
|
+
bail: options?.bail,
|
|
870
|
+
onFlowStart: (name, workerName) => {
|
|
871
|
+
options?.onFlowStart?.(name, platform, workerName);
|
|
872
|
+
},
|
|
873
|
+
onFlowComplete: (result, workerName) => {
|
|
874
|
+
const resultWithWorker = { ...result, workerName };
|
|
875
|
+
options?.onResult?.(resultWithWorker);
|
|
876
|
+
if (result.status === "failed") noteFailure();
|
|
877
|
+
}
|
|
878
|
+
});
|
|
879
|
+
if (hooks?.afterAll) {
|
|
548
880
|
try {
|
|
549
|
-
await hooks.
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
results.
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
});
|
|
559
|
-
}
|
|
560
|
-
noteFailure(platformFlows.length);
|
|
561
|
-
platformResults.push(results);
|
|
562
|
-
continue;
|
|
881
|
+
await hooks.afterAll({
|
|
882
|
+
app: void 0,
|
|
883
|
+
platform,
|
|
884
|
+
summary: { results: parallelResult.results }
|
|
885
|
+
});
|
|
886
|
+
} catch (hookError) {
|
|
887
|
+
console.warn(
|
|
888
|
+
`afterAll hook failed: ${hookError instanceof Error ? hookError.message : hookError}`
|
|
889
|
+
);
|
|
563
890
|
}
|
|
564
891
|
}
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
platform,
|
|
573
|
-
status: "skipped",
|
|
574
|
-
durationMs: 0
|
|
575
|
-
});
|
|
576
|
-
}
|
|
577
|
-
break;
|
|
892
|
+
return { results: parallelResult.results, workerStats: parallelResult.workerStats };
|
|
893
|
+
}
|
|
894
|
+
for (let index = 0; index < platformFlows.length; index++) {
|
|
895
|
+
const flow = platformFlows[index];
|
|
896
|
+
if (shouldBail()) {
|
|
897
|
+
for (const skippedFlow of platformFlows.slice(index)) {
|
|
898
|
+
results.push({ name: skippedFlow.name, platform, status: "skipped", durationMs: 0 });
|
|
578
899
|
}
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
}
|
|
594
|
-
result = { ...retryResult, attempts };
|
|
595
|
-
}
|
|
596
|
-
if (result.status === "failed") {
|
|
597
|
-
result = { ...result, attempts };
|
|
900
|
+
break;
|
|
901
|
+
}
|
|
902
|
+
options?.onFlowStart?.(flow.name, platform);
|
|
903
|
+
let result = await executeFlow(flow, driver, engineConfig);
|
|
904
|
+
let attempts = 1;
|
|
905
|
+
if (result.status === "failed" && retries > 0) {
|
|
906
|
+
for (let retry = 0; retry < retries; retry++) {
|
|
907
|
+
if (shouldBail()) break;
|
|
908
|
+
await sleep(retryDelay);
|
|
909
|
+
const retryResult = await executeFlow(flow, driver, engineConfig);
|
|
910
|
+
attempts++;
|
|
911
|
+
if (retryResult.status === "passed") {
|
|
912
|
+
result = { ...retryResult, flaky: true, attempts };
|
|
913
|
+
break;
|
|
598
914
|
}
|
|
915
|
+
result = { ...retryResult, attempts };
|
|
599
916
|
}
|
|
600
|
-
results.push(result);
|
|
601
|
-
options?.onResult?.(result);
|
|
602
917
|
if (result.status === "failed") {
|
|
603
|
-
|
|
918
|
+
result = { ...result, attempts };
|
|
604
919
|
}
|
|
605
920
|
}
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
921
|
+
results.push(result);
|
|
922
|
+
options?.onResult?.(result);
|
|
923
|
+
if (result.status === "failed") {
|
|
924
|
+
noteFailure();
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
if (hooks?.afterAll) {
|
|
928
|
+
try {
|
|
929
|
+
await hooks.afterAll({ app: void 0, platform, summary: { results } });
|
|
930
|
+
} catch (hookError) {
|
|
931
|
+
console.warn(
|
|
932
|
+
`afterAll hook failed: ${hookError instanceof Error ? hookError.message : hookError}`
|
|
933
|
+
);
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
return { results };
|
|
937
|
+
}
|
|
938
|
+
async function orchestrate(flows, platforms, options) {
|
|
939
|
+
const start2 = Date.now();
|
|
940
|
+
const bail = options?.bail;
|
|
941
|
+
let failureCount = 0;
|
|
942
|
+
let bailedOut = false;
|
|
943
|
+
const shouldBail = () => {
|
|
944
|
+
if (bail !== void 0 && failureCount >= bail) {
|
|
945
|
+
bailedOut = true;
|
|
946
|
+
return true;
|
|
947
|
+
}
|
|
948
|
+
return false;
|
|
949
|
+
};
|
|
950
|
+
const noteFailure = (count = 1) => {
|
|
951
|
+
failureCount += count;
|
|
952
|
+
};
|
|
953
|
+
let platformResults;
|
|
954
|
+
if (options?.parallelPlatforms && platforms.length > 1) {
|
|
955
|
+
platformResults = await Promise.all(
|
|
956
|
+
platforms.map((pc) => runPlatform(flows, pc, options, shouldBail, noteFailure))
|
|
957
|
+
);
|
|
958
|
+
} else {
|
|
959
|
+
platformResults = [];
|
|
960
|
+
for (const pc of platforms) {
|
|
961
|
+
const pr = await runPlatform(flows, pc, options, shouldBail, noteFailure);
|
|
962
|
+
platformResults.push(pr);
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
const allResults = platformResults.flatMap((pr) => pr.results);
|
|
966
|
+
const allWorkerStats = /* @__PURE__ */ new Map();
|
|
967
|
+
for (const pr of platformResults) {
|
|
968
|
+
if (pr.workerStats) {
|
|
969
|
+
for (const [id, stats] of pr.workerStats) {
|
|
970
|
+
allWorkerStats.set(id, stats);
|
|
613
971
|
}
|
|
614
972
|
}
|
|
615
|
-
platformResults.push(results);
|
|
616
973
|
}
|
|
617
|
-
const allResults = platformResults.flat();
|
|
618
974
|
return {
|
|
619
975
|
results: allResults,
|
|
620
976
|
totalDurationMs: Date.now() - start2,
|
|
@@ -623,29 +979,13 @@ async function orchestrate(flows, platforms, options) {
|
|
|
623
979
|
skipped: allResults.filter((r) => r.status === "skipped").length,
|
|
624
980
|
flaky: allResults.filter((r) => r.flaky).length,
|
|
625
981
|
bailedOut,
|
|
626
|
-
bailLimit: bail
|
|
982
|
+
bailLimit: bail,
|
|
983
|
+
workerStats: allWorkerStats.size > 0 ? allWorkerStats : void 0
|
|
627
984
|
};
|
|
628
985
|
}
|
|
629
986
|
|
|
630
|
-
// src/runtime/capabilities.ts
|
|
631
|
-
import { readFile } from "fs/promises";
|
|
632
|
-
async function resolveCapabilities(config, opts) {
|
|
633
|
-
const configCaps = config.capabilities ?? {};
|
|
634
|
-
let fileCaps = {};
|
|
635
|
-
const capsFilePath = opts.capsPath ?? config.capabilitiesFile;
|
|
636
|
-
if (capsFilePath) {
|
|
637
|
-
const raw = await readFile(capsFilePath, "utf-8");
|
|
638
|
-
fileCaps = JSON.parse(raw);
|
|
639
|
-
}
|
|
640
|
-
let cliCaps = {};
|
|
641
|
-
if (opts.capsJson) {
|
|
642
|
-
cliCaps = JSON.parse(opts.capsJson);
|
|
643
|
-
}
|
|
644
|
-
return { ...configCaps, ...fileCaps, ...cliCaps };
|
|
645
|
-
}
|
|
646
|
-
|
|
647
987
|
// src/runtime/local.ts
|
|
648
|
-
import { Effect as
|
|
988
|
+
import { Effect as Effect4 } from "effect";
|
|
649
989
|
async function safeCleanup(...fns) {
|
|
650
990
|
for (const fn of fns) {
|
|
651
991
|
try {
|
|
@@ -677,18 +1017,20 @@ function buildEngineConfig(appId, platform, parseFn, config) {
|
|
|
677
1017
|
async function buildWebRuntime(config) {
|
|
678
1018
|
const webUrl = config.apps?.web?.url ?? "http://localhost:3000";
|
|
679
1019
|
const webExecution = config.execution?.web;
|
|
680
|
-
const
|
|
1020
|
+
const rawDriver = await Effect4.runPromise(
|
|
681
1021
|
makePlaywrightDriver({
|
|
682
1022
|
browser: webExecution?.browser,
|
|
683
1023
|
headless: webExecution?.headless ?? true,
|
|
684
1024
|
baseUrl: webUrl,
|
|
685
|
-
storageState: webExecution?.storageState
|
|
1025
|
+
storageState: webExecution?.storageState,
|
|
1026
|
+
verboseLogging: webExecution?.verboseLogging
|
|
686
1027
|
})
|
|
687
1028
|
);
|
|
1029
|
+
const driver = withBufferedDriverLogs(rawDriver);
|
|
688
1030
|
return {
|
|
689
1031
|
runtime: {
|
|
690
1032
|
driver,
|
|
691
|
-
cleanup: () => safeCleanup(() =>
|
|
1033
|
+
cleanup: () => safeCleanup(() => Effect4.runPromise(driver.killApp(""))),
|
|
692
1034
|
metadata: {
|
|
693
1035
|
platform: "web",
|
|
694
1036
|
mode: "local"
|
|
@@ -726,14 +1068,15 @@ async function buildLocalAndroidRuntime(config, targetDevice, resolveFromConfig)
|
|
|
726
1068
|
const hostPort = allocatePort(8200);
|
|
727
1069
|
try {
|
|
728
1070
|
const conn = await setupUiAutomator2(device.serial, hostPort);
|
|
729
|
-
const
|
|
1071
|
+
const rawDriver = await Effect4.runPromise(
|
|
730
1072
|
createUiAutomator2Driver(conn.host, conn.port, device.serial, packageName)
|
|
731
1073
|
);
|
|
1074
|
+
const driver = withBufferedDriverLogs(rawDriver);
|
|
732
1075
|
return {
|
|
733
1076
|
runtime: {
|
|
734
1077
|
driver,
|
|
735
1078
|
cleanup: () => safeCleanup(
|
|
736
|
-
() =>
|
|
1079
|
+
() => Effect4.runPromise(driver.killApp("")),
|
|
737
1080
|
() => conn.cleanup?.() ?? Promise.resolve()
|
|
738
1081
|
),
|
|
739
1082
|
metadata: {
|
|
@@ -764,14 +1107,15 @@ async function buildLocalIOSRuntime(config, targetDevice, resolveFromConfig) {
|
|
|
764
1107
|
const wdaPort2 = allocatePort(8100);
|
|
765
1108
|
try {
|
|
766
1109
|
const conn = await setupWDA(targetDevice.id, wdaPort2);
|
|
767
|
-
const
|
|
1110
|
+
const rawDriver = await Effect4.runPromise(
|
|
768
1111
|
createWDADriver(conn.host, conn.port, bundleId, targetDevice.id)
|
|
769
1112
|
);
|
|
1113
|
+
const driver = withBufferedDriverLogs(rawDriver);
|
|
770
1114
|
return {
|
|
771
1115
|
runtime: {
|
|
772
1116
|
driver,
|
|
773
1117
|
cleanup: () => safeCleanup(
|
|
774
|
-
() =>
|
|
1118
|
+
() => Effect4.runPromise(driver.killApp("")),
|
|
775
1119
|
() => conn.cleanup?.() ?? Promise.resolve()
|
|
776
1120
|
),
|
|
777
1121
|
metadata: {
|
|
@@ -804,7 +1148,7 @@ async function buildLocalIOSRuntime(config, targetDevice, resolveFromConfig) {
|
|
|
804
1148
|
});
|
|
805
1149
|
}
|
|
806
1150
|
if (signing?.teamId) {
|
|
807
|
-
const { setupWDAForDevice } = await import("./installer-
|
|
1151
|
+
const { setupWDAForDevice } = await import("./installer-YZJ4DV3F.js");
|
|
808
1152
|
const wdaPort2 = allocatePort(8100);
|
|
809
1153
|
conn = await setupWDAForDevice(
|
|
810
1154
|
physicalDevice.udid,
|
|
@@ -816,14 +1160,15 @@ async function buildLocalIOSRuntime(config, targetDevice, resolveFromConfig) {
|
|
|
816
1160
|
conn = connectPhysicalDevice(physicalDevice.udid);
|
|
817
1161
|
}
|
|
818
1162
|
const activeConn = conn;
|
|
819
|
-
const
|
|
1163
|
+
const rawDriver = await Effect4.runPromise(
|
|
820
1164
|
createWDADriver(activeConn.host, activeConn.port, bundleId)
|
|
821
1165
|
);
|
|
1166
|
+
const driver = withBufferedDriverLogs(rawDriver);
|
|
822
1167
|
return {
|
|
823
1168
|
runtime: {
|
|
824
1169
|
driver,
|
|
825
1170
|
cleanup: () => safeCleanup(
|
|
826
|
-
() =>
|
|
1171
|
+
() => Effect4.runPromise(driver.killApp("")),
|
|
827
1172
|
() => activeConn.cleanup?.() ?? Promise.resolve()
|
|
828
1173
|
),
|
|
829
1174
|
metadata: {
|
|
@@ -865,14 +1210,15 @@ async function buildLocalIOSRuntime(config, targetDevice, resolveFromConfig) {
|
|
|
865
1210
|
const wdaPort = allocatePort(8100);
|
|
866
1211
|
try {
|
|
867
1212
|
const conn = await setupWDA(simulator.udid, wdaPort);
|
|
868
|
-
const
|
|
1213
|
+
const rawDriver = await Effect4.runPromise(
|
|
869
1214
|
createWDADriver(conn.host, conn.port, bundleId, simulator.udid)
|
|
870
1215
|
);
|
|
1216
|
+
const driver = withBufferedDriverLogs(rawDriver);
|
|
871
1217
|
return {
|
|
872
1218
|
runtime: {
|
|
873
1219
|
driver,
|
|
874
1220
|
cleanup: () => safeCleanup(
|
|
875
|
-
() =>
|
|
1221
|
+
() => Effect4.runPromise(driver.killApp("")),
|
|
876
1222
|
() => conn.cleanup?.() ?? Promise.resolve()
|
|
877
1223
|
),
|
|
878
1224
|
metadata: {
|
|
@@ -890,7 +1236,7 @@ async function buildLocalIOSRuntime(config, targetDevice, resolveFromConfig) {
|
|
|
890
1236
|
}
|
|
891
1237
|
|
|
892
1238
|
// src/runtime/appium.ts
|
|
893
|
-
import { Effect as
|
|
1239
|
+
import { Effect as Effect7 } from "effect";
|
|
894
1240
|
|
|
895
1241
|
// src/drivers/appium/client.ts
|
|
896
1242
|
var AppiumClient = class {
|
|
@@ -1005,39 +1351,39 @@ var AppiumClient = class {
|
|
|
1005
1351
|
};
|
|
1006
1352
|
|
|
1007
1353
|
// src/drivers/appium/android.ts
|
|
1008
|
-
import { Effect as
|
|
1354
|
+
import { Effect as Effect5 } from "effect";
|
|
1009
1355
|
function createAppiumAndroidDriver(client) {
|
|
1010
1356
|
const service = {
|
|
1011
1357
|
// -----------------------------------------------------------------------
|
|
1012
1358
|
// Hierarchy
|
|
1013
1359
|
// -----------------------------------------------------------------------
|
|
1014
|
-
dumpHierarchy: () =>
|
|
1360
|
+
dumpHierarchy: () => Effect5.tryPromise({
|
|
1015
1361
|
try: () => client.request("GET", client.sessionPath("/source")),
|
|
1016
1362
|
catch: (e) => new DriverError({ message: `Failed to get page source: ${e}` })
|
|
1017
1363
|
}),
|
|
1018
1364
|
// -----------------------------------------------------------------------
|
|
1019
1365
|
// Coordinate-level actions
|
|
1020
1366
|
// -----------------------------------------------------------------------
|
|
1021
|
-
tapAtCoordinate: (x, y) =>
|
|
1367
|
+
tapAtCoordinate: (x, y) => Effect5.tryPromise({
|
|
1022
1368
|
try: () => client.request("POST", client.sessionPath("/appium/gestures/click"), {
|
|
1023
1369
|
offset: { x, y }
|
|
1024
1370
|
}),
|
|
1025
1371
|
catch: (e) => new DriverError({ message: `Tap failed: ${e}` })
|
|
1026
1372
|
}),
|
|
1027
|
-
doubleTapAtCoordinate: (x, y) =>
|
|
1373
|
+
doubleTapAtCoordinate: (x, y) => Effect5.tryPromise({
|
|
1028
1374
|
try: () => client.request("POST", client.sessionPath("/appium/gestures/double_click"), {
|
|
1029
1375
|
offset: { x, y }
|
|
1030
1376
|
}),
|
|
1031
1377
|
catch: (e) => new DriverError({ message: `Double tap failed: ${e}` })
|
|
1032
1378
|
}),
|
|
1033
|
-
longPressAtCoordinate: (x, y, duration) =>
|
|
1379
|
+
longPressAtCoordinate: (x, y, duration) => Effect5.tryPromise({
|
|
1034
1380
|
try: () => client.request("POST", client.sessionPath("/appium/gestures/long_click"), {
|
|
1035
1381
|
offset: { x, y },
|
|
1036
1382
|
duration
|
|
1037
1383
|
}),
|
|
1038
1384
|
catch: (e) => new DriverError({ message: `Long press failed: ${e}` })
|
|
1039
1385
|
}),
|
|
1040
|
-
swipe: (sx, sy, ex, ey, dur) =>
|
|
1386
|
+
swipe: (sx, sy, ex, ey, dur) => Effect5.tryPromise({
|
|
1041
1387
|
try: () => client.request("POST", client.sessionPath("/actions"), {
|
|
1042
1388
|
actions: [
|
|
1043
1389
|
{
|
|
@@ -1058,12 +1404,12 @@ function createAppiumAndroidDriver(client) {
|
|
|
1058
1404
|
// -----------------------------------------------------------------------
|
|
1059
1405
|
// Text input
|
|
1060
1406
|
// -----------------------------------------------------------------------
|
|
1061
|
-
inputText: (text) =>
|
|
1407
|
+
inputText: (text) => Effect5.tryPromise({
|
|
1062
1408
|
try: () => {
|
|
1063
1409
|
const keyActions = [];
|
|
1064
|
-
for (const
|
|
1065
|
-
keyActions.push({ type: "keyDown", value:
|
|
1066
|
-
keyActions.push({ type: "keyUp", value:
|
|
1410
|
+
for (const segment of splitGraphemes(text)) {
|
|
1411
|
+
keyActions.push({ type: "keyDown", value: segment });
|
|
1412
|
+
keyActions.push({ type: "keyUp", value: segment });
|
|
1067
1413
|
}
|
|
1068
1414
|
return client.request("POST", client.sessionPath("/actions"), {
|
|
1069
1415
|
actions: [
|
|
@@ -1077,27 +1423,27 @@ function createAppiumAndroidDriver(client) {
|
|
|
1077
1423
|
},
|
|
1078
1424
|
catch: (e) => new DriverError({ message: `Input text failed: ${e}` })
|
|
1079
1425
|
}),
|
|
1080
|
-
pressKey: (key) =>
|
|
1426
|
+
pressKey: (key) => Effect5.tryPromise({
|
|
1081
1427
|
try: () => client.request("POST", client.sessionPath("/appium/device/press_keycode"), {
|
|
1082
1428
|
keycode: parseInt(key, 10) || 0
|
|
1083
1429
|
}),
|
|
1084
1430
|
catch: (e) => new DriverError({ message: `Press key failed: ${e}` })
|
|
1085
1431
|
}),
|
|
1086
|
-
hideKeyboard: () =>
|
|
1432
|
+
hideKeyboard: () => Effect5.tryPromise({
|
|
1087
1433
|
try: () => client.request("POST", client.sessionPath("/appium/device/hide_keyboard")),
|
|
1088
1434
|
catch: (e) => new DriverError({ message: `Hide keyboard failed: ${e}` })
|
|
1089
1435
|
}),
|
|
1090
1436
|
// -----------------------------------------------------------------------
|
|
1091
1437
|
// Queries
|
|
1092
1438
|
// -----------------------------------------------------------------------
|
|
1093
|
-
takeScreenshot: () =>
|
|
1439
|
+
takeScreenshot: () => Effect5.tryPromise({
|
|
1094
1440
|
try: async () => {
|
|
1095
1441
|
const base64 = await client.request("GET", client.sessionPath("/screenshot"));
|
|
1096
1442
|
return Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
|
|
1097
1443
|
},
|
|
1098
1444
|
catch: (e) => new DriverError({ message: `Screenshot failed: ${e}` })
|
|
1099
1445
|
}),
|
|
1100
|
-
getDeviceInfo: () =>
|
|
1446
|
+
getDeviceInfo: () => Effect5.tryPromise({
|
|
1101
1447
|
try: async () => {
|
|
1102
1448
|
const size = await client.request(
|
|
1103
1449
|
"GET",
|
|
@@ -1119,7 +1465,7 @@ function createAppiumAndroidDriver(client) {
|
|
|
1119
1465
|
// -----------------------------------------------------------------------
|
|
1120
1466
|
// App lifecycle
|
|
1121
1467
|
// -----------------------------------------------------------------------
|
|
1122
|
-
launchApp: (bundleId, opts) =>
|
|
1468
|
+
launchApp: (bundleId, opts) => Effect5.tryPromise({
|
|
1123
1469
|
try: async () => {
|
|
1124
1470
|
if (opts?.clearState) {
|
|
1125
1471
|
try {
|
|
@@ -1155,19 +1501,19 @@ function createAppiumAndroidDriver(client) {
|
|
|
1155
1501
|
},
|
|
1156
1502
|
catch: (e) => new DriverError({ message: `Launch app failed: ${e}` })
|
|
1157
1503
|
}),
|
|
1158
|
-
stopApp: (bundleId) =>
|
|
1504
|
+
stopApp: (bundleId) => Effect5.tryPromise({
|
|
1159
1505
|
try: () => client.request("POST", client.sessionPath("/appium/device/terminate_app"), {
|
|
1160
1506
|
appId: bundleId
|
|
1161
1507
|
}),
|
|
1162
1508
|
catch: (e) => new DriverError({ message: `Stop app failed: ${e}` })
|
|
1163
1509
|
}),
|
|
1164
|
-
killApp: (bundleId) =>
|
|
1510
|
+
killApp: (bundleId) => Effect5.tryPromise({
|
|
1165
1511
|
try: () => client.request("POST", client.sessionPath("/appium/device/terminate_app"), {
|
|
1166
1512
|
appId: bundleId
|
|
1167
1513
|
}),
|
|
1168
1514
|
catch: (e) => new DriverError({ message: `Kill app failed: ${e}` })
|
|
1169
1515
|
}),
|
|
1170
|
-
clearAppState: (bundleId) =>
|
|
1516
|
+
clearAppState: (bundleId) => Effect5.tryPromise({
|
|
1171
1517
|
try: async () => {
|
|
1172
1518
|
try {
|
|
1173
1519
|
await client.request("POST", client.sessionPath("/appium/device/terminate_app"), {
|
|
@@ -1184,18 +1530,18 @@ function createAppiumAndroidDriver(client) {
|
|
|
1184
1530
|
// -----------------------------------------------------------------------
|
|
1185
1531
|
// Navigation
|
|
1186
1532
|
// -----------------------------------------------------------------------
|
|
1187
|
-
openLink: (url) =>
|
|
1533
|
+
openLink: (url) => Effect5.tryPromise({
|
|
1188
1534
|
try: () => client.request("POST", client.sessionPath("/url"), { url }),
|
|
1189
1535
|
catch: (e) => new DriverError({ message: `Open link failed: ${e}` })
|
|
1190
1536
|
}),
|
|
1191
|
-
back: () =>
|
|
1537
|
+
back: () => Effect5.tryPromise({
|
|
1192
1538
|
try: () => client.request("POST", client.sessionPath("/back")),
|
|
1193
1539
|
catch: (e) => new DriverError({ message: `Back failed: ${e}` })
|
|
1194
1540
|
}),
|
|
1195
1541
|
// -----------------------------------------------------------------------
|
|
1196
1542
|
// Scripting (works when switched to a WebView context)
|
|
1197
1543
|
// -----------------------------------------------------------------------
|
|
1198
|
-
evaluate: (script, ...args) =>
|
|
1544
|
+
evaluate: (script, ...args) => Effect5.tryPromise({
|
|
1199
1545
|
try: () => client.executeScript(
|
|
1200
1546
|
typeof script === "function" ? `return (${script})(...arguments)` : script,
|
|
1201
1547
|
args
|
|
@@ -1205,37 +1551,37 @@ function createAppiumAndroidDriver(client) {
|
|
|
1205
1551
|
// -----------------------------------------------------------------------
|
|
1206
1552
|
// WebView / hybrid context switching
|
|
1207
1553
|
// -----------------------------------------------------------------------
|
|
1208
|
-
getContexts: () =>
|
|
1554
|
+
getContexts: () => Effect5.tryPromise({
|
|
1209
1555
|
try: () => client.getContexts(),
|
|
1210
1556
|
catch: (e) => new DriverError({ message: `getContexts failed: ${e}` })
|
|
1211
1557
|
}),
|
|
1212
|
-
getCurrentContext: () =>
|
|
1558
|
+
getCurrentContext: () => Effect5.tryPromise({
|
|
1213
1559
|
try: () => client.getCurrentContext(),
|
|
1214
1560
|
catch: (e) => new DriverError({ message: `getCurrentContext failed: ${e}` })
|
|
1215
1561
|
}),
|
|
1216
|
-
setContext: (contextId) =>
|
|
1562
|
+
setContext: (contextId) => Effect5.tryPromise({
|
|
1217
1563
|
try: () => client.setContext(contextId),
|
|
1218
1564
|
catch: (e) => new DriverError({ message: `setContext failed: ${e}` })
|
|
1219
1565
|
})
|
|
1220
1566
|
};
|
|
1221
|
-
return
|
|
1567
|
+
return Effect5.succeed(service);
|
|
1222
1568
|
}
|
|
1223
1569
|
|
|
1224
1570
|
// src/drivers/appium/ios.ts
|
|
1225
|
-
import { Effect as
|
|
1571
|
+
import { Effect as Effect6 } from "effect";
|
|
1226
1572
|
function createAppiumIOSDriver(client) {
|
|
1227
1573
|
const service = {
|
|
1228
1574
|
// -----------------------------------------------------------------------
|
|
1229
1575
|
// Hierarchy
|
|
1230
1576
|
// -----------------------------------------------------------------------
|
|
1231
|
-
dumpHierarchy: () =>
|
|
1577
|
+
dumpHierarchy: () => Effect6.tryPromise({
|
|
1232
1578
|
try: () => client.request("GET", client.sessionPath("/source")),
|
|
1233
1579
|
catch: (e) => new DriverError({ message: `Failed to get page source: ${e}` })
|
|
1234
1580
|
}),
|
|
1235
1581
|
// -----------------------------------------------------------------------
|
|
1236
1582
|
// Coordinate-level actions (W3C touch pointer actions for iOS)
|
|
1237
1583
|
// -----------------------------------------------------------------------
|
|
1238
|
-
tapAtCoordinate: (x, y) =>
|
|
1584
|
+
tapAtCoordinate: (x, y) => Effect6.tryPromise({
|
|
1239
1585
|
try: () => client.request("POST", client.sessionPath("/actions"), {
|
|
1240
1586
|
actions: [
|
|
1241
1587
|
{
|
|
@@ -1252,7 +1598,7 @@ function createAppiumIOSDriver(client) {
|
|
|
1252
1598
|
}),
|
|
1253
1599
|
catch: (e) => new DriverError({ message: `Tap failed: ${e}` })
|
|
1254
1600
|
}),
|
|
1255
|
-
doubleTapAtCoordinate: (x, y) =>
|
|
1601
|
+
doubleTapAtCoordinate: (x, y) => Effect6.tryPromise({
|
|
1256
1602
|
try: () => client.request("POST", client.sessionPath("/actions"), {
|
|
1257
1603
|
actions: [
|
|
1258
1604
|
{
|
|
@@ -1272,7 +1618,7 @@ function createAppiumIOSDriver(client) {
|
|
|
1272
1618
|
}),
|
|
1273
1619
|
catch: (e) => new DriverError({ message: `Double tap failed: ${e}` })
|
|
1274
1620
|
}),
|
|
1275
|
-
longPressAtCoordinate: (x, y, duration) =>
|
|
1621
|
+
longPressAtCoordinate: (x, y, duration) => Effect6.tryPromise({
|
|
1276
1622
|
try: () => client.request("POST", client.sessionPath("/actions"), {
|
|
1277
1623
|
actions: [
|
|
1278
1624
|
{
|
|
@@ -1290,7 +1636,7 @@ function createAppiumIOSDriver(client) {
|
|
|
1290
1636
|
}),
|
|
1291
1637
|
catch: (e) => new DriverError({ message: `Long press failed: ${e}` })
|
|
1292
1638
|
}),
|
|
1293
|
-
swipe: (sx, sy, ex, ey, dur) =>
|
|
1639
|
+
swipe: (sx, sy, ex, ey, dur) => Effect6.tryPromise({
|
|
1294
1640
|
try: () => client.request("POST", client.sessionPath("/actions"), {
|
|
1295
1641
|
actions: [
|
|
1296
1642
|
{
|
|
@@ -1311,12 +1657,12 @@ function createAppiumIOSDriver(client) {
|
|
|
1311
1657
|
// -----------------------------------------------------------------------
|
|
1312
1658
|
// Text input
|
|
1313
1659
|
// -----------------------------------------------------------------------
|
|
1314
|
-
inputText: (text) =>
|
|
1660
|
+
inputText: (text) => Effect6.tryPromise({
|
|
1315
1661
|
try: () => {
|
|
1316
1662
|
const keyActions = [];
|
|
1317
|
-
for (const
|
|
1318
|
-
keyActions.push({ type: "keyDown", value:
|
|
1319
|
-
keyActions.push({ type: "keyUp", value:
|
|
1663
|
+
for (const segment of splitGraphemes(text)) {
|
|
1664
|
+
keyActions.push({ type: "keyDown", value: segment });
|
|
1665
|
+
keyActions.push({ type: "keyUp", value: segment });
|
|
1320
1666
|
}
|
|
1321
1667
|
return client.request("POST", client.sessionPath("/actions"), {
|
|
1322
1668
|
actions: [
|
|
@@ -1330,7 +1676,7 @@ function createAppiumIOSDriver(client) {
|
|
|
1330
1676
|
},
|
|
1331
1677
|
catch: (e) => new DriverError({ message: `Input text failed: ${e}` })
|
|
1332
1678
|
}),
|
|
1333
|
-
pressKey: (key) =>
|
|
1679
|
+
pressKey: (key) => Effect6.tryPromise({
|
|
1334
1680
|
try: () => client.request("POST", client.sessionPath("/actions"), {
|
|
1335
1681
|
actions: [
|
|
1336
1682
|
{
|
|
@@ -1345,21 +1691,21 @@ function createAppiumIOSDriver(client) {
|
|
|
1345
1691
|
}),
|
|
1346
1692
|
catch: (e) => new DriverError({ message: `Press key failed: ${e}` })
|
|
1347
1693
|
}),
|
|
1348
|
-
hideKeyboard: () =>
|
|
1694
|
+
hideKeyboard: () => Effect6.tryPromise({
|
|
1349
1695
|
try: () => client.request("POST", client.sessionPath("/appium/device/hide_keyboard")),
|
|
1350
1696
|
catch: (e) => new DriverError({ message: `Hide keyboard failed: ${e}` })
|
|
1351
1697
|
}),
|
|
1352
1698
|
// -----------------------------------------------------------------------
|
|
1353
1699
|
// Queries
|
|
1354
1700
|
// -----------------------------------------------------------------------
|
|
1355
|
-
takeScreenshot: () =>
|
|
1701
|
+
takeScreenshot: () => Effect6.tryPromise({
|
|
1356
1702
|
try: async () => {
|
|
1357
1703
|
const base64 = await client.request("GET", client.sessionPath("/screenshot"));
|
|
1358
1704
|
return Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
|
|
1359
1705
|
},
|
|
1360
1706
|
catch: (e) => new DriverError({ message: `Screenshot failed: ${e}` })
|
|
1361
1707
|
}),
|
|
1362
|
-
getDeviceInfo: () =>
|
|
1708
|
+
getDeviceInfo: () => Effect6.tryPromise({
|
|
1363
1709
|
try: async () => {
|
|
1364
1710
|
const size = await client.request(
|
|
1365
1711
|
"GET",
|
|
@@ -1381,7 +1727,7 @@ function createAppiumIOSDriver(client) {
|
|
|
1381
1727
|
// -----------------------------------------------------------------------
|
|
1382
1728
|
// App lifecycle
|
|
1383
1729
|
// -----------------------------------------------------------------------
|
|
1384
|
-
launchApp: (bundleId, opts) =>
|
|
1730
|
+
launchApp: (bundleId, opts) => Effect6.tryPromise({
|
|
1385
1731
|
try: async () => {
|
|
1386
1732
|
if (opts?.clearState) {
|
|
1387
1733
|
try {
|
|
@@ -1419,19 +1765,19 @@ function createAppiumIOSDriver(client) {
|
|
|
1419
1765
|
},
|
|
1420
1766
|
catch: (e) => new DriverError({ message: `Launch app failed: ${e}` })
|
|
1421
1767
|
}),
|
|
1422
|
-
stopApp: (bundleId) =>
|
|
1768
|
+
stopApp: (bundleId) => Effect6.tryPromise({
|
|
1423
1769
|
try: () => client.request("POST", client.sessionPath("/appium/device/terminate_app"), {
|
|
1424
1770
|
appId: bundleId
|
|
1425
1771
|
}),
|
|
1426
1772
|
catch: (e) => new DriverError({ message: `Stop app failed: ${e}` })
|
|
1427
1773
|
}),
|
|
1428
|
-
killApp: (bundleId) =>
|
|
1774
|
+
killApp: (bundleId) => Effect6.tryPromise({
|
|
1429
1775
|
try: () => client.request("POST", client.sessionPath("/appium/device/terminate_app"), {
|
|
1430
1776
|
appId: bundleId
|
|
1431
1777
|
}),
|
|
1432
1778
|
catch: (e) => new DriverError({ message: `Kill app failed: ${e}` })
|
|
1433
1779
|
}),
|
|
1434
|
-
clearAppState: (bundleId) =>
|
|
1780
|
+
clearAppState: (bundleId) => Effect6.tryPromise({
|
|
1435
1781
|
try: async () => {
|
|
1436
1782
|
try {
|
|
1437
1783
|
await client.request("POST", client.sessionPath("/appium/device/terminate_app"), {
|
|
@@ -1450,11 +1796,11 @@ function createAppiumIOSDriver(client) {
|
|
|
1450
1796
|
// -----------------------------------------------------------------------
|
|
1451
1797
|
// Navigation
|
|
1452
1798
|
// -----------------------------------------------------------------------
|
|
1453
|
-
openLink: (url) =>
|
|
1799
|
+
openLink: (url) => Effect6.tryPromise({
|
|
1454
1800
|
try: () => client.request("POST", client.sessionPath("/url"), { url }),
|
|
1455
1801
|
catch: (e) => new DriverError({ message: `Open link failed: ${e}` })
|
|
1456
1802
|
}),
|
|
1457
|
-
back: () =>
|
|
1803
|
+
back: () => Effect6.fail(
|
|
1458
1804
|
new DriverError({
|
|
1459
1805
|
message: "back() is not supported on iOS. Use navigation within the app or swipe gestures."
|
|
1460
1806
|
})
|
|
@@ -1462,7 +1808,7 @@ function createAppiumIOSDriver(client) {
|
|
|
1462
1808
|
// -----------------------------------------------------------------------
|
|
1463
1809
|
// Scripting (works when switched to a WebView context)
|
|
1464
1810
|
// -----------------------------------------------------------------------
|
|
1465
|
-
evaluate: (script, ...args) =>
|
|
1811
|
+
evaluate: (script, ...args) => Effect6.tryPromise({
|
|
1466
1812
|
try: () => client.executeScript(
|
|
1467
1813
|
typeof script === "function" ? `return (${script})(...arguments)` : script,
|
|
1468
1814
|
args
|
|
@@ -1472,20 +1818,20 @@ function createAppiumIOSDriver(client) {
|
|
|
1472
1818
|
// -----------------------------------------------------------------------
|
|
1473
1819
|
// WebView / hybrid context switching
|
|
1474
1820
|
// -----------------------------------------------------------------------
|
|
1475
|
-
getContexts: () =>
|
|
1821
|
+
getContexts: () => Effect6.tryPromise({
|
|
1476
1822
|
try: () => client.getContexts(),
|
|
1477
1823
|
catch: (e) => new DriverError({ message: `getContexts failed: ${e}` })
|
|
1478
1824
|
}),
|
|
1479
|
-
getCurrentContext: () =>
|
|
1825
|
+
getCurrentContext: () => Effect6.tryPromise({
|
|
1480
1826
|
try: () => client.getCurrentContext(),
|
|
1481
1827
|
catch: (e) => new DriverError({ message: `getCurrentContext failed: ${e}` })
|
|
1482
1828
|
}),
|
|
1483
|
-
setContext: (contextId) =>
|
|
1829
|
+
setContext: (contextId) => Effect6.tryPromise({
|
|
1484
1830
|
try: () => client.setContext(contextId),
|
|
1485
1831
|
catch: (e) => new DriverError({ message: `setContext failed: ${e}` })
|
|
1486
1832
|
})
|
|
1487
1833
|
};
|
|
1488
|
-
return
|
|
1834
|
+
return Effect6.succeed(service);
|
|
1489
1835
|
}
|
|
1490
1836
|
|
|
1491
1837
|
// src/runtime/appium.ts
|
|
@@ -1495,7 +1841,8 @@ async function buildAppiumAndroidRuntime(config, appiumUrl, caps) {
|
|
|
1495
1841
|
platformName: "Android",
|
|
1496
1842
|
...caps
|
|
1497
1843
|
});
|
|
1498
|
-
const
|
|
1844
|
+
const rawDriver = await Effect7.runPromise(createAppiumAndroidDriver(client));
|
|
1845
|
+
const driver = withBufferedDriverLogs(rawDriver);
|
|
1499
1846
|
const sessionId = client.getSessionId() ?? void 0;
|
|
1500
1847
|
const sessionCaps = client.getSessionCaps();
|
|
1501
1848
|
const detectedProvider = detectProvider(appiumUrl);
|
|
@@ -1545,7 +1892,8 @@ async function buildAppiumIOSRuntime(config, appiumUrl, caps) {
|
|
|
1545
1892
|
"appium:automationName": "XCUITest",
|
|
1546
1893
|
...caps
|
|
1547
1894
|
});
|
|
1548
|
-
const
|
|
1895
|
+
const rawDriver = await Effect7.runPromise(createAppiumIOSDriver(client));
|
|
1896
|
+
const driver = withBufferedDriverLogs(rawDriver);
|
|
1549
1897
|
const sessionId = client.getSessionId() ?? void 0;
|
|
1550
1898
|
const sessionCaps = client.getSessionCaps();
|
|
1551
1899
|
const detectedProvider = detectProvider(appiumUrl);
|
|
@@ -1589,22 +1937,503 @@ async function buildAppiumIOSRuntime(config, appiumUrl, caps) {
|
|
|
1589
1937
|
};
|
|
1590
1938
|
}
|
|
1591
1939
|
|
|
1940
|
+
// src/cli/iteration.ts
|
|
1941
|
+
import { execFileSync } from "child_process";
|
|
1942
|
+
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
1943
|
+
import { dirname, join as join2, resolve } from "path";
|
|
1944
|
+
var LAST_RUN_STATE_SCHEMA_VERSION = 1;
|
|
1945
|
+
function createLastRunStatePath(outputDir) {
|
|
1946
|
+
return join2(outputDir, ".spana", "last-run.json");
|
|
1947
|
+
}
|
|
1948
|
+
function buildLastRunState(options) {
|
|
1949
|
+
const flows = options.results.map((result) => ({
|
|
1950
|
+
name: result.name,
|
|
1951
|
+
platform: result.platform,
|
|
1952
|
+
status: result.status,
|
|
1953
|
+
sourcePath: options.sourcePathsByFlowName.get(result.name)
|
|
1954
|
+
}));
|
|
1955
|
+
const failedFlowNames = flows.filter((flow) => flow.status === "failed").map((flow) => flow.name);
|
|
1956
|
+
const failedSourcePaths = [
|
|
1957
|
+
...new Set(
|
|
1958
|
+
flows.filter((flow) => flow.status === "failed").map((flow) => flow.sourcePath).filter((value) => Boolean(value))
|
|
1959
|
+
)
|
|
1960
|
+
];
|
|
1961
|
+
return {
|
|
1962
|
+
schemaVersion: LAST_RUN_STATE_SCHEMA_VERSION,
|
|
1963
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1964
|
+
flowDir: resolve(options.flowDir),
|
|
1965
|
+
platforms: [...new Set(options.platforms)],
|
|
1966
|
+
failedFlowNames,
|
|
1967
|
+
failedSourcePaths,
|
|
1968
|
+
flows
|
|
1969
|
+
};
|
|
1970
|
+
}
|
|
1971
|
+
function parseLastRunState(raw, filePath) {
|
|
1972
|
+
const parsed = JSON.parse(raw);
|
|
1973
|
+
if (parsed.schemaVersion !== LAST_RUN_STATE_SCHEMA_VERSION) {
|
|
1974
|
+
throw new Error(
|
|
1975
|
+
`Unsupported last run state schema in ${filePath}. Delete the file and rerun Spana.`
|
|
1976
|
+
);
|
|
1977
|
+
}
|
|
1978
|
+
if (!Array.isArray(parsed.flows) || !Array.isArray(parsed.failedFlowNames)) {
|
|
1979
|
+
throw new Error(`Invalid last run state file at ${filePath}. Delete the file and rerun Spana.`);
|
|
1980
|
+
}
|
|
1981
|
+
return {
|
|
1982
|
+
schemaVersion: LAST_RUN_STATE_SCHEMA_VERSION,
|
|
1983
|
+
updatedAt: typeof parsed.updatedAt === "string" ? parsed.updatedAt : (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
1984
|
+
flowDir: typeof parsed.flowDir === "string" ? parsed.flowDir : "",
|
|
1985
|
+
platforms: Array.isArray(parsed.platforms) ? parsed.platforms : [],
|
|
1986
|
+
failedFlowNames: parsed.failedFlowNames.filter(
|
|
1987
|
+
(value) => typeof value === "string"
|
|
1988
|
+
),
|
|
1989
|
+
failedSourcePaths: Array.isArray(parsed.failedSourcePaths) ? parsed.failedSourcePaths.filter((value) => typeof value === "string") : [],
|
|
1990
|
+
flows: parsed.flows.filter(
|
|
1991
|
+
(value) => typeof value === "object" && value !== null && typeof value.name === "string" && typeof value.platform === "string" && typeof value.status === "string"
|
|
1992
|
+
).map((value) => ({
|
|
1993
|
+
name: value.name,
|
|
1994
|
+
platform: value.platform,
|
|
1995
|
+
status: value.status,
|
|
1996
|
+
sourcePath: typeof value.sourcePath === "string" ? value.sourcePath : void 0
|
|
1997
|
+
}))
|
|
1998
|
+
};
|
|
1999
|
+
}
|
|
2000
|
+
async function readLastRunState(filePath) {
|
|
2001
|
+
try {
|
|
2002
|
+
const raw = await readFile(filePath, "utf8");
|
|
2003
|
+
return parseLastRunState(raw, filePath);
|
|
2004
|
+
} catch (error) {
|
|
2005
|
+
if (error.code === "ENOENT") {
|
|
2006
|
+
return null;
|
|
2007
|
+
}
|
|
2008
|
+
throw error;
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
async function writeLastRunState(filePath, state) {
|
|
2012
|
+
await mkdir(dirname(filePath), { recursive: true });
|
|
2013
|
+
await writeFile(filePath, `${JSON.stringify(state, null, 2)}
|
|
2014
|
+
`, "utf8");
|
|
2015
|
+
}
|
|
2016
|
+
function parseGitPathList(output, cwd) {
|
|
2017
|
+
return output.split(/\r?\n/).map((line) => line.trim()).filter(Boolean).map((line) => resolve(cwd, line));
|
|
2018
|
+
}
|
|
2019
|
+
function getGitChangedFiles(cwd = process.cwd()) {
|
|
2020
|
+
try {
|
|
2021
|
+
const tracked = execFileSync("git", ["diff", "--name-only", "--relative", "HEAD"], {
|
|
2022
|
+
cwd,
|
|
2023
|
+
encoding: "utf8"
|
|
2024
|
+
});
|
|
2025
|
+
const untracked = execFileSync("git", ["ls-files", "--others", "--exclude-standard"], {
|
|
2026
|
+
cwd,
|
|
2027
|
+
encoding: "utf8"
|
|
2028
|
+
});
|
|
2029
|
+
return [.../* @__PURE__ */ new Set([...parseGitPathList(tracked, cwd), ...parseGitPathList(untracked, cwd)])];
|
|
2030
|
+
} catch (error) {
|
|
2031
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2032
|
+
throw new Error(
|
|
2033
|
+
`Failed to read changed files from git. Make sure git is installed and the project is in a git repository. ${message}`,
|
|
2034
|
+
{ cause: error }
|
|
2035
|
+
);
|
|
2036
|
+
}
|
|
2037
|
+
}
|
|
2038
|
+
function selectChangedFlowPaths(options) {
|
|
2039
|
+
const flowPaths = options.flowPaths.map((path) => resolve(path));
|
|
2040
|
+
const changedFiles = new Set(options.changedFiles.map((path) => resolve(path)));
|
|
2041
|
+
const stepPaths = new Set((options.stepPaths ?? []).map((path) => resolve(path)));
|
|
2042
|
+
const configPath = options.configPath ? resolve(options.configPath) : void 0;
|
|
2043
|
+
if (configPath && changedFiles.has(configPath)) {
|
|
2044
|
+
return {
|
|
2045
|
+
mode: "all",
|
|
2046
|
+
reason: "Config changed; running the full filtered flow set.",
|
|
2047
|
+
flowPaths
|
|
2048
|
+
};
|
|
2049
|
+
}
|
|
2050
|
+
const changedFlowPaths = flowPaths.filter((path) => changedFiles.has(path));
|
|
2051
|
+
if (changedFlowPaths.length > 0) {
|
|
2052
|
+
return {
|
|
2053
|
+
mode: "targeted",
|
|
2054
|
+
reason: "Detected changed flow files.",
|
|
2055
|
+
flowPaths: changedFlowPaths
|
|
2056
|
+
};
|
|
2057
|
+
}
|
|
2058
|
+
const hasChangedStepFiles = [...stepPaths].some((path) => changedFiles.has(path));
|
|
2059
|
+
if (hasChangedStepFiles) {
|
|
2060
|
+
const featureFlowPaths = flowPaths.filter((path) => path.endsWith(".feature"));
|
|
2061
|
+
if (featureFlowPaths.length > 0) {
|
|
2062
|
+
return {
|
|
2063
|
+
mode: "targeted",
|
|
2064
|
+
reason: "Detected changed step definition files; rerunning feature files.",
|
|
2065
|
+
flowPaths: featureFlowPaths
|
|
2066
|
+
};
|
|
2067
|
+
}
|
|
2068
|
+
return {
|
|
2069
|
+
mode: "none",
|
|
2070
|
+
reason: "Step definition files changed, but no .feature flows were discovered.",
|
|
2071
|
+
flowPaths: []
|
|
2072
|
+
};
|
|
2073
|
+
}
|
|
2074
|
+
return {
|
|
2075
|
+
mode: "none",
|
|
2076
|
+
reason: "No changed flow files were detected.",
|
|
2077
|
+
flowPaths: []
|
|
2078
|
+
};
|
|
2079
|
+
}
|
|
2080
|
+
|
|
2081
|
+
// src/cli/watch-mode.ts
|
|
2082
|
+
import { readdir, stat } from "fs/promises";
|
|
2083
|
+
import { dirname as dirname2, extname, resolve as resolve2 } from "path";
|
|
2084
|
+
var IGNORED_DIRECTORIES = /* @__PURE__ */ new Set([".git", "node_modules", "spana-output", "dist", "coverage"]);
|
|
2085
|
+
var WATCHABLE_EXTENSIONS = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".json", ".feature"]);
|
|
2086
|
+
var defaultWatchDependencies = {
|
|
2087
|
+
sleep: (ms) => new Promise((resolveDelay) => setTimeout(resolveDelay, ms)),
|
|
2088
|
+
snapshotRoots: snapshotWatchRoots
|
|
2089
|
+
};
|
|
2090
|
+
function collectWatchRoots(flowPathOrDir, configPath) {
|
|
2091
|
+
const roots = /* @__PURE__ */ new Set();
|
|
2092
|
+
const resolvedFlowPath = resolve2(flowPathOrDir);
|
|
2093
|
+
roots.add(resolvedFlowPath);
|
|
2094
|
+
if (configPath) {
|
|
2095
|
+
roots.add(resolve2(configPath));
|
|
2096
|
+
}
|
|
2097
|
+
return [...roots];
|
|
2098
|
+
}
|
|
2099
|
+
function shouldTrackFile(filePath) {
|
|
2100
|
+
return WATCHABLE_EXTENSIONS.has(extname(filePath));
|
|
2101
|
+
}
|
|
2102
|
+
async function snapshotPath(path, snapshot) {
|
|
2103
|
+
const stats = await stat(path).catch(() => null);
|
|
2104
|
+
if (!stats) {
|
|
2105
|
+
return;
|
|
2106
|
+
}
|
|
2107
|
+
if (stats.isDirectory()) {
|
|
2108
|
+
const entries = await readdir(path, { withFileTypes: true });
|
|
2109
|
+
for (const entry of entries) {
|
|
2110
|
+
if (entry.isDirectory() && IGNORED_DIRECTORIES.has(entry.name)) {
|
|
2111
|
+
continue;
|
|
2112
|
+
}
|
|
2113
|
+
await snapshotPath(resolve2(path, entry.name), snapshot);
|
|
2114
|
+
}
|
|
2115
|
+
return;
|
|
2116
|
+
}
|
|
2117
|
+
if (!shouldTrackFile(path)) {
|
|
2118
|
+
return;
|
|
2119
|
+
}
|
|
2120
|
+
snapshot.set(path, `${stats.mtimeMs}:${stats.size}`);
|
|
2121
|
+
}
|
|
2122
|
+
async function snapshotWatchRoots(roots) {
|
|
2123
|
+
const snapshot = /* @__PURE__ */ new Map();
|
|
2124
|
+
for (const root of roots.map((path) => resolve2(path))) {
|
|
2125
|
+
const stats = await stat(root).catch(() => null);
|
|
2126
|
+
if (!stats) {
|
|
2127
|
+
const parent = dirname2(root);
|
|
2128
|
+
const parentStats = await stat(parent).catch(() => null);
|
|
2129
|
+
if (parentStats?.isDirectory()) {
|
|
2130
|
+
await snapshotPath(parent, snapshot);
|
|
2131
|
+
}
|
|
2132
|
+
continue;
|
|
2133
|
+
}
|
|
2134
|
+
await snapshotPath(root, snapshot);
|
|
2135
|
+
}
|
|
2136
|
+
return snapshot;
|
|
2137
|
+
}
|
|
2138
|
+
function diffSnapshots(previous, next) {
|
|
2139
|
+
const changed = /* @__PURE__ */ new Set();
|
|
2140
|
+
for (const [path, signature] of previous) {
|
|
2141
|
+
if (next.get(path) !== signature) {
|
|
2142
|
+
changed.add(path);
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
for (const path of next.keys()) {
|
|
2146
|
+
if (!previous.has(path)) {
|
|
2147
|
+
changed.add(path);
|
|
2148
|
+
}
|
|
2149
|
+
}
|
|
2150
|
+
return [...changed].toSorted();
|
|
2151
|
+
}
|
|
2152
|
+
async function runWatchLoop(options, dependencies = defaultWatchDependencies) {
|
|
2153
|
+
let previousSnapshot = await dependencies.snapshotRoots(options.roots);
|
|
2154
|
+
while (true) {
|
|
2155
|
+
await dependencies.sleep(options.intervalMs ?? 500);
|
|
2156
|
+
const nextSnapshot = await dependencies.snapshotRoots(options.roots);
|
|
2157
|
+
const changedPaths = diffSnapshots(previousSnapshot, nextSnapshot);
|
|
2158
|
+
if (changedPaths.length === 0) {
|
|
2159
|
+
continue;
|
|
2160
|
+
}
|
|
2161
|
+
previousSnapshot = nextSnapshot;
|
|
2162
|
+
await options.onChange(changedPaths);
|
|
2163
|
+
}
|
|
2164
|
+
}
|
|
2165
|
+
|
|
1592
2166
|
// src/cli/test-command.ts
|
|
1593
|
-
|
|
2167
|
+
function validateOptions(opts) {
|
|
1594
2168
|
if (opts.driver && opts.driver !== "local" && opts.driver !== "appium") {
|
|
1595
|
-
|
|
1596
|
-
return false;
|
|
2169
|
+
return `Unknown --driver value "${opts.driver}". Use "local" or "appium".`;
|
|
1597
2170
|
}
|
|
1598
2171
|
if (opts.shard) {
|
|
1599
2172
|
const { current, total } = opts.shard;
|
|
1600
2173
|
if (!Number.isInteger(current) || !Number.isInteger(total) || current < 1 || total < 1 || current > total) {
|
|
1601
|
-
|
|
1602
|
-
return false;
|
|
2174
|
+
return "Invalid shard config. Use { current, total } with 1 <= current <= total.";
|
|
1603
2175
|
}
|
|
1604
2176
|
}
|
|
1605
2177
|
if (opts.bail !== void 0 && (!Number.isInteger(opts.bail) || opts.bail < 1)) {
|
|
1606
|
-
|
|
1607
|
-
|
|
2178
|
+
return "Invalid bail config. Use a positive integer.";
|
|
2179
|
+
}
|
|
2180
|
+
if (opts.parallel && opts.device) {
|
|
2181
|
+
return "Cannot use --parallel with --device. Remove --device to auto-discover all devices.";
|
|
2182
|
+
}
|
|
2183
|
+
if (opts.devices && opts.device) {
|
|
2184
|
+
return "Cannot use --devices with --device. Use --devices for multi-device selection.";
|
|
2185
|
+
}
|
|
2186
|
+
if (opts.device && opts.workers) {
|
|
2187
|
+
return "Cannot use --workers with --device. --device targets a single device.";
|
|
2188
|
+
}
|
|
2189
|
+
if (opts.watch && opts.validateConfigOnly) {
|
|
2190
|
+
return "Cannot use --watch with --validate-config.";
|
|
2191
|
+
}
|
|
2192
|
+
return null;
|
|
2193
|
+
}
|
|
2194
|
+
async function loadFlowsWithSources(flowPaths) {
|
|
2195
|
+
const loadedFlows = [];
|
|
2196
|
+
for (const sourcePath of flowPaths) {
|
|
2197
|
+
const loaded = await loadTestSource(sourcePath);
|
|
2198
|
+
for (const flow of loaded) {
|
|
2199
|
+
loadedFlows.push({ sourcePath, flow });
|
|
2200
|
+
}
|
|
2201
|
+
}
|
|
2202
|
+
return loadedFlows;
|
|
2203
|
+
}
|
|
2204
|
+
function filterLoadedFlows(loadedFlows, options) {
|
|
2205
|
+
const filteredFlows = filterFlows(
|
|
2206
|
+
loadedFlows.map((loaded) => loaded.flow),
|
|
2207
|
+
options
|
|
2208
|
+
);
|
|
2209
|
+
const allowedFlows = new Set(filteredFlows);
|
|
2210
|
+
return loadedFlows.filter((loaded) => allowedFlows.has(loaded.flow));
|
|
2211
|
+
}
|
|
2212
|
+
async function buildParallelPlatformConfigs(platforms, opts, config, runtimes, resolveFromConfig) {
|
|
2213
|
+
const { discoverDevices, findDeviceById } = await import("./discover-KZKXHZZA.js");
|
|
2214
|
+
let allDevices;
|
|
2215
|
+
if (opts.devices) {
|
|
2216
|
+
allDevices = [];
|
|
2217
|
+
for (const id of opts.devices) {
|
|
2218
|
+
const found = findDeviceById(id);
|
|
2219
|
+
if (found) {
|
|
2220
|
+
allDevices.push(found);
|
|
2221
|
+
} else {
|
|
2222
|
+
console.log(`Warning: Device "${id}" not found, skipping.`);
|
|
2223
|
+
}
|
|
2224
|
+
}
|
|
2225
|
+
if (opts.platforms.length === 0) {
|
|
2226
|
+
const inferredPlatforms = [...new Set(allDevices.map((d) => d.platform))];
|
|
2227
|
+
platforms.length = 0;
|
|
2228
|
+
platforms.push(...inferredPlatforms);
|
|
2229
|
+
}
|
|
2230
|
+
} else {
|
|
2231
|
+
allDevices = discoverDevices(platforms);
|
|
2232
|
+
}
|
|
2233
|
+
const maxWorkers = opts.workers ?? config.defaults?.workers;
|
|
2234
|
+
const platformConfigs = [];
|
|
2235
|
+
for (const platform of platforms) {
|
|
2236
|
+
let platformDevices = allDevices.filter((d) => d.platform === platform);
|
|
2237
|
+
if (maxWorkers && platformDevices.length > maxWorkers) {
|
|
2238
|
+
platformDevices = platformDevices.slice(0, maxWorkers);
|
|
2239
|
+
}
|
|
2240
|
+
if (platform === "web") {
|
|
2241
|
+
const webWorkers = maxWorkers ?? 1;
|
|
2242
|
+
if (webWorkers > 1) {
|
|
2243
|
+
const primaryResult = await buildWebRuntime(config);
|
|
2244
|
+
runtimes.push(primaryResult.runtime);
|
|
2245
|
+
const additionalWorkers = [];
|
|
2246
|
+
for (let i = 1; i < webWorkers; i++) {
|
|
2247
|
+
const result = await buildWebRuntime(config);
|
|
2248
|
+
runtimes.push(result.runtime);
|
|
2249
|
+
additionalWorkers.push({
|
|
2250
|
+
id: `web-context-${i + 1}`,
|
|
2251
|
+
name: `Chromium #${i + 1}`,
|
|
2252
|
+
driver: result.runtime.driver,
|
|
2253
|
+
engineConfig: { ...result.engineConfig, debugOnFailure: opts.debugOnFailure }
|
|
2254
|
+
});
|
|
2255
|
+
}
|
|
2256
|
+
platformConfigs.push({
|
|
2257
|
+
platform,
|
|
2258
|
+
driver: primaryResult.runtime.driver,
|
|
2259
|
+
engineConfig: { ...primaryResult.engineConfig, debugOnFailure: opts.debugOnFailure },
|
|
2260
|
+
additionalWorkers: additionalWorkers.length > 0 ? additionalWorkers : void 0
|
|
2261
|
+
});
|
|
2262
|
+
} else {
|
|
2263
|
+
const result = await buildWebRuntime(config);
|
|
2264
|
+
runtimes.push(result.runtime);
|
|
2265
|
+
platformConfigs.push({
|
|
2266
|
+
platform,
|
|
2267
|
+
driver: result.runtime.driver,
|
|
2268
|
+
engineConfig: { ...result.engineConfig, debugOnFailure: opts.debugOnFailure }
|
|
2269
|
+
});
|
|
2270
|
+
}
|
|
2271
|
+
} else if (platformDevices.length === 0) {
|
|
2272
|
+
console.log(`No ${platform} devices found. Skipping ${platform} platform.`);
|
|
2273
|
+
} else {
|
|
2274
|
+
if (platformDevices.length === 1) {
|
|
2275
|
+
console.log(
|
|
2276
|
+
`\u2139 Only 1 ${platform} device found \u2014 connect more devices for parallel execution.`
|
|
2277
|
+
);
|
|
2278
|
+
}
|
|
2279
|
+
const builder = platform === "android" ? buildLocalAndroidRuntime : buildLocalIOSRuntime;
|
|
2280
|
+
const primaryResult = await builder(config, platformDevices[0], resolveFromConfig);
|
|
2281
|
+
if (!primaryResult) continue;
|
|
2282
|
+
runtimes.push(primaryResult.runtime);
|
|
2283
|
+
const additionalWorkers = [];
|
|
2284
|
+
for (const device of platformDevices.slice(1)) {
|
|
2285
|
+
try {
|
|
2286
|
+
const result = await builder(config, device, resolveFromConfig);
|
|
2287
|
+
if (result) {
|
|
2288
|
+
runtimes.push(result.runtime);
|
|
2289
|
+
additionalWorkers.push({
|
|
2290
|
+
id: device.id,
|
|
2291
|
+
name: device.name,
|
|
2292
|
+
driver: result.runtime.driver,
|
|
2293
|
+
engineConfig: { ...result.engineConfig, debugOnFailure: opts.debugOnFailure }
|
|
2294
|
+
});
|
|
2295
|
+
}
|
|
2296
|
+
} catch (err) {
|
|
2297
|
+
console.log(
|
|
2298
|
+
`Warning: Failed to set up ${platform} device ${device.name}: ${err instanceof Error ? err.message : err}`
|
|
2299
|
+
);
|
|
2300
|
+
}
|
|
2301
|
+
}
|
|
2302
|
+
platformConfigs.push({
|
|
2303
|
+
platform,
|
|
2304
|
+
driver: primaryResult.runtime.driver,
|
|
2305
|
+
engineConfig: { ...primaryResult.engineConfig, debugOnFailure: opts.debugOnFailure },
|
|
2306
|
+
additionalWorkers: additionalWorkers.length > 0 ? additionalWorkers : void 0
|
|
2307
|
+
});
|
|
2308
|
+
}
|
|
2309
|
+
}
|
|
2310
|
+
return platformConfigs;
|
|
2311
|
+
}
|
|
2312
|
+
async function buildSerialPlatformConfigs(platforms, opts, config, runtimes, executionMode, appiumUrl, baseAppiumCaps, cloudHelper, targetDevice, resolveFromConfig) {
|
|
2313
|
+
const platformConfigs = [];
|
|
2314
|
+
for (const platform of platforms) {
|
|
2315
|
+
if (executionMode === "appium" && (platform === "android" || platform === "ios")) {
|
|
2316
|
+
const builder = platform === "android" ? buildAppiumAndroidRuntime : buildAppiumIOSRuntime;
|
|
2317
|
+
const preparedCaps = await cloudHelper.prepareCapabilities(
|
|
2318
|
+
platform,
|
|
2319
|
+
{ ...baseAppiumCaps },
|
|
2320
|
+
platform === "android" ? config.apps?.android : config.apps?.ios
|
|
2321
|
+
);
|
|
2322
|
+
const result = await builder(config, appiumUrl, preparedCaps);
|
|
2323
|
+
runtimes.push(result.runtime);
|
|
2324
|
+
platformConfigs.push({
|
|
2325
|
+
platform,
|
|
2326
|
+
driver: result.runtime.driver,
|
|
2327
|
+
engineConfig: { ...result.engineConfig, debugOnFailure: opts.debugOnFailure }
|
|
2328
|
+
});
|
|
2329
|
+
} else if (platform === "web") {
|
|
2330
|
+
const result = await buildWebRuntime(config);
|
|
2331
|
+
runtimes.push(result.runtime);
|
|
2332
|
+
platformConfigs.push({
|
|
2333
|
+
platform,
|
|
2334
|
+
driver: result.runtime.driver,
|
|
2335
|
+
engineConfig: { ...result.engineConfig, debugOnFailure: opts.debugOnFailure }
|
|
2336
|
+
});
|
|
2337
|
+
} else if (platform === "android") {
|
|
2338
|
+
const result = await buildLocalAndroidRuntime(config, targetDevice, resolveFromConfig);
|
|
2339
|
+
if (!result) continue;
|
|
2340
|
+
runtimes.push(result.runtime);
|
|
2341
|
+
platformConfigs.push({
|
|
2342
|
+
platform,
|
|
2343
|
+
driver: result.runtime.driver,
|
|
2344
|
+
engineConfig: { ...result.engineConfig, debugOnFailure: opts.debugOnFailure }
|
|
2345
|
+
});
|
|
2346
|
+
} else if (platform === "ios") {
|
|
2347
|
+
const result = await buildLocalIOSRuntime(config, targetDevice, resolveFromConfig);
|
|
2348
|
+
if (!result) continue;
|
|
2349
|
+
runtimes.push(result.runtime);
|
|
2350
|
+
platformConfigs.push({
|
|
2351
|
+
platform,
|
|
2352
|
+
driver: result.runtime.driver,
|
|
2353
|
+
engineConfig: { ...result.engineConfig, debugOnFailure: opts.debugOnFailure }
|
|
2354
|
+
});
|
|
2355
|
+
}
|
|
2356
|
+
}
|
|
2357
|
+
return platformConfigs;
|
|
2358
|
+
}
|
|
2359
|
+
var BUILTIN_REPORTERS = /* @__PURE__ */ new Set(["console", "json", "junit", "html", "allure"]);
|
|
2360
|
+
async function loadCustomReporter(modulePath, configDir) {
|
|
2361
|
+
const resolvedPath = modulePath.startsWith(".") ? resolve3(configDir, modulePath) : modulePath;
|
|
2362
|
+
let mod;
|
|
2363
|
+
try {
|
|
2364
|
+
mod = await import(resolvedPath);
|
|
2365
|
+
} catch (err) {
|
|
2366
|
+
throw new Error(
|
|
2367
|
+
`Failed to load custom reporter from "${modulePath}" (resolved: ${resolvedPath}): ${err instanceof Error ? err.message : err}`,
|
|
2368
|
+
{ cause: err }
|
|
2369
|
+
);
|
|
2370
|
+
}
|
|
2371
|
+
const exported = mod.default;
|
|
2372
|
+
if (!exported) {
|
|
2373
|
+
throw new Error(
|
|
2374
|
+
`Custom reporter "${modulePath}" has no default export. Export a Reporter object or a (options) => Reporter factory function.`
|
|
2375
|
+
);
|
|
2376
|
+
}
|
|
2377
|
+
if (typeof exported === "function") {
|
|
2378
|
+
return exported({ outputDir: configDir });
|
|
2379
|
+
}
|
|
2380
|
+
if (typeof exported === "object") {
|
|
2381
|
+
return exported;
|
|
2382
|
+
}
|
|
2383
|
+
throw new Error(
|
|
2384
|
+
`Custom reporter "${modulePath}" default export must be a Reporter object or factory function, got ${typeof exported}.`
|
|
2385
|
+
);
|
|
2386
|
+
}
|
|
2387
|
+
async function setupReporters(reporterNames, config, resolveFromConfig, appiumUrl, opts) {
|
|
2388
|
+
const { createRedactor, registerUrlSecrets } = await import("./redact-U72BUBBR.js");
|
|
2389
|
+
const redactor = createRedactor();
|
|
2390
|
+
if (appiumUrl) registerUrlSecrets(redactor, appiumUrl);
|
|
2391
|
+
const { createConsoleReporter } = await import("./console-XWKUTP3D.js");
|
|
2392
|
+
const { createJsonReporter } = await import("./json-KS67BZYU.js");
|
|
2393
|
+
const { createJUnitReporter } = await import("./junit-HLC62MK6.js");
|
|
2394
|
+
const { createHtmlReporter } = await import("./html-GE6Q4DCG.js");
|
|
2395
|
+
const { createAllureReporter } = await import("./allure-PTTVORQ6.js");
|
|
2396
|
+
const resolvedOutputDir = config.artifacts?.outputDir ?? resolveFromConfig("./spana-output");
|
|
2397
|
+
const reporters = [];
|
|
2398
|
+
for (const name of reporterNames.split(",")) {
|
|
2399
|
+
const trimmed = name.trim();
|
|
2400
|
+
if (!trimmed) continue;
|
|
2401
|
+
if (BUILTIN_REPORTERS.has(trimmed)) {
|
|
2402
|
+
switch (trimmed) {
|
|
2403
|
+
case "json":
|
|
2404
|
+
reporters.push(createJsonReporter());
|
|
2405
|
+
break;
|
|
2406
|
+
case "junit":
|
|
2407
|
+
reporters.push(createJUnitReporter(resolvedOutputDir));
|
|
2408
|
+
break;
|
|
2409
|
+
case "html":
|
|
2410
|
+
reporters.push(createHtmlReporter(resolvedOutputDir));
|
|
2411
|
+
break;
|
|
2412
|
+
case "allure":
|
|
2413
|
+
reporters.push(createAllureReporter());
|
|
2414
|
+
break;
|
|
2415
|
+
default:
|
|
2416
|
+
reporters.push(createConsoleReporter({ quiet: opts.quiet }));
|
|
2417
|
+
break;
|
|
2418
|
+
}
|
|
2419
|
+
} else {
|
|
2420
|
+
const configDir = resolve3(resolveFromConfig("."));
|
|
2421
|
+
try {
|
|
2422
|
+
const custom = await loadCustomReporter(trimmed, configDir);
|
|
2423
|
+
reporters.push(custom);
|
|
2424
|
+
} catch (err) {
|
|
2425
|
+
console.log(err instanceof Error ? err.message : String(err));
|
|
2426
|
+
throw err;
|
|
2427
|
+
}
|
|
2428
|
+
}
|
|
2429
|
+
}
|
|
2430
|
+
return { redactor, reporters };
|
|
2431
|
+
}
|
|
2432
|
+
async function runTestCommandOnce(opts) {
|
|
2433
|
+
const validationError = validateOptions(opts);
|
|
2434
|
+
if (validationError) {
|
|
2435
|
+
console.log(validationError);
|
|
2436
|
+
return { success: false, watchRoots: [] };
|
|
1608
2437
|
}
|
|
1609
2438
|
let config = {};
|
|
1610
2439
|
let loadedConfigPath;
|
|
@@ -1614,18 +2443,18 @@ async function runTestCommand(opts) {
|
|
|
1614
2443
|
loadedConfigPath = loaded.configPath;
|
|
1615
2444
|
} catch (error) {
|
|
1616
2445
|
console.log(error instanceof Error ? error.message : String(error));
|
|
1617
|
-
return false;
|
|
2446
|
+
return { success: false, watchRoots: [] };
|
|
1618
2447
|
}
|
|
1619
|
-
const configDir =
|
|
2448
|
+
const configDir = dirname3(loadedConfigPath ?? resolve3("spana.config.ts"));
|
|
1620
2449
|
if (opts.validateConfigOnly) {
|
|
1621
2450
|
if (!loadedConfigPath) {
|
|
1622
2451
|
console.log("No config file found to validate.");
|
|
1623
|
-
return false;
|
|
2452
|
+
return { success: false, watchRoots: [] };
|
|
1624
2453
|
}
|
|
1625
2454
|
console.log(`\u2713 Config valid (${loadedConfigPath})`);
|
|
1626
|
-
return true;
|
|
2455
|
+
return { success: true, watchRoots: [] };
|
|
1627
2456
|
}
|
|
1628
|
-
const resolveFromConfig = (p) =>
|
|
2457
|
+
const resolveFromConfig = (p) => resolve3(configDir, p);
|
|
1629
2458
|
if (config.artifacts?.outputDir) {
|
|
1630
2459
|
config.artifacts.outputDir = resolveFromConfig(config.artifacts.outputDir);
|
|
1631
2460
|
}
|
|
@@ -1635,7 +2464,7 @@ async function runTestCommand(opts) {
|
|
|
1635
2464
|
JSON.parse(opts.capsJson);
|
|
1636
2465
|
} catch {
|
|
1637
2466
|
console.log("Invalid JSON in --caps-json flag.");
|
|
1638
|
-
return false;
|
|
2467
|
+
return { success: false, watchRoots: [] };
|
|
1639
2468
|
}
|
|
1640
2469
|
}
|
|
1641
2470
|
if (executionMode === "appium") {
|
|
@@ -1644,28 +2473,31 @@ async function runTestCommand(opts) {
|
|
|
1644
2473
|
console.log(
|
|
1645
2474
|
"Appium mode requires a server URL. Set --appium-url or execution.appium.serverUrl in config."
|
|
1646
2475
|
);
|
|
1647
|
-
return false;
|
|
2476
|
+
return { success: false, watchRoots: [] };
|
|
1648
2477
|
}
|
|
1649
2478
|
if (opts.device) {
|
|
1650
2479
|
console.log(
|
|
1651
2480
|
"Cannot use --device with appium mode. Use --caps or --caps-json to set device capabilities."
|
|
1652
2481
|
);
|
|
1653
|
-
return false;
|
|
2482
|
+
return { success: false, watchRoots: [] };
|
|
1654
2483
|
}
|
|
1655
2484
|
}
|
|
1656
2485
|
const platforms = opts.platforms.length > 0 ? opts.platforms : config.platforms && config.platforms.length > 0 ? config.platforms : ["web"];
|
|
1657
2486
|
let targetDevice = null;
|
|
1658
2487
|
if (opts.device) {
|
|
1659
|
-
const { findDeviceById } = await import("./discover-
|
|
2488
|
+
const { findDeviceById } = await import("./discover-KZKXHZZA.js");
|
|
1660
2489
|
targetDevice = findDeviceById(opts.device);
|
|
1661
2490
|
if (!targetDevice) {
|
|
1662
|
-
const { discoverDevices } = await import("./discover-
|
|
2491
|
+
const { discoverDevices } = await import("./discover-KZKXHZZA.js");
|
|
1663
2492
|
const available = discoverDevices(["web", "android", "ios"]);
|
|
1664
2493
|
console.log(`Device "${opts.device}" not found. Available devices:`);
|
|
1665
2494
|
for (const d of available) {
|
|
1666
2495
|
console.log(` ${d.id.padEnd(30)} ${d.platform.padEnd(8)} ${d.type}`);
|
|
1667
2496
|
}
|
|
1668
|
-
return
|
|
2497
|
+
return {
|
|
2498
|
+
success: false,
|
|
2499
|
+
watchRoots: collectWatchRoots(resolveFromConfig(config.flowDir ?? "./flows"), loadedConfigPath)
|
|
2500
|
+
};
|
|
1669
2501
|
}
|
|
1670
2502
|
if (opts.platforms.length === 0) {
|
|
1671
2503
|
platforms.length = 0;
|
|
@@ -1675,59 +2507,100 @@ async function runTestCommand(opts) {
|
|
|
1675
2507
|
console.log(
|
|
1676
2508
|
`Device "${opts.device}" is ${targetDevice.platform}, but --platform ${platforms.join(",")} was specified.`
|
|
1677
2509
|
);
|
|
1678
|
-
return
|
|
2510
|
+
return {
|
|
2511
|
+
success: false,
|
|
2512
|
+
watchRoots: collectWatchRoots(resolveFromConfig(config.flowDir ?? "./flows"), loadedConfigPath)
|
|
2513
|
+
};
|
|
1679
2514
|
}
|
|
1680
2515
|
}
|
|
1681
2516
|
const reporterNames = opts.reporter?.trim() ? opts.reporter : config.reporters && config.reporters.length > 0 ? config.reporters.join(",") : "console";
|
|
1682
|
-
const reporterList = reporterNames.split(",").map((name) => name.trim());
|
|
1683
|
-
const validReporters = /* @__PURE__ */ new Set(["console", "json", "junit", "html", "allure"]);
|
|
1684
|
-
for (const reporterName of reporterList) {
|
|
1685
|
-
if (!validReporters.has(reporterName)) {
|
|
1686
|
-
console.log(
|
|
1687
|
-
`Unknown reporter "${reporterName}". Use one of: ${Array.from(validReporters).join(", ")}.`
|
|
1688
|
-
);
|
|
1689
|
-
return false;
|
|
1690
|
-
}
|
|
1691
|
-
}
|
|
1692
2517
|
const flowDir = opts.flowPath ?? resolveFromConfig(config.flowDir ?? "./flows");
|
|
1693
|
-
const
|
|
2518
|
+
const watchRoots = collectWatchRoots(flowDir, loadedConfigPath);
|
|
2519
|
+
let flowPaths = await discoverFlows(flowDir);
|
|
1694
2520
|
if (flowPaths.length === 0) {
|
|
1695
2521
|
console.log("No flow files found.");
|
|
1696
|
-
return true;
|
|
2522
|
+
return { success: true, watchRoots };
|
|
1697
2523
|
}
|
|
2524
|
+
let stepPaths = [];
|
|
1698
2525
|
const hasFeatureFiles = flowPaths.some((p) => p.endsWith(".feature"));
|
|
1699
2526
|
if (hasFeatureFiles) {
|
|
1700
2527
|
const { stat: statPath } = await import("fs/promises");
|
|
1701
|
-
const { dirname:
|
|
2528
|
+
const { dirname: dirnameDyn } = await import("path");
|
|
1702
2529
|
const flowDirStats = await statPath(flowDir).catch(() => null);
|
|
1703
|
-
const stepSearchDir = flowDirStats?.isDirectory() ? flowDir :
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
2530
|
+
const stepSearchDir = flowDirStats?.isDirectory() ? flowDir : dirnameDyn(flowDir);
|
|
2531
|
+
stepPaths = await discoverStepFiles(stepSearchDir);
|
|
2532
|
+
}
|
|
2533
|
+
if (opts.changed) {
|
|
2534
|
+
let changedFiles;
|
|
2535
|
+
try {
|
|
2536
|
+
changedFiles = getGitChangedFiles(process.cwd());
|
|
2537
|
+
} catch (error) {
|
|
2538
|
+
console.log(error instanceof Error ? error.message : String(error));
|
|
2539
|
+
return { success: false, watchRoots };
|
|
2540
|
+
}
|
|
2541
|
+
const selection = selectChangedFlowPaths({
|
|
2542
|
+
flowPaths,
|
|
2543
|
+
changedFiles,
|
|
2544
|
+
stepPaths,
|
|
2545
|
+
configPath: loadedConfigPath
|
|
2546
|
+
});
|
|
2547
|
+
if (selection.mode === "none") {
|
|
2548
|
+
console.log(selection.reason);
|
|
2549
|
+
return { success: true, watchRoots };
|
|
2550
|
+
}
|
|
2551
|
+
if (selection.mode === "targeted") {
|
|
2552
|
+
flowPaths = selection.flowPaths;
|
|
2553
|
+
console.log(selection.reason);
|
|
2554
|
+
} else {
|
|
2555
|
+
console.log(selection.reason);
|
|
1707
2556
|
}
|
|
1708
2557
|
}
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
2558
|
+
if (flowPaths.length === 0) {
|
|
2559
|
+
console.log("No flow files found.");
|
|
2560
|
+
return { success: true, watchRoots };
|
|
2561
|
+
}
|
|
2562
|
+
if (flowPaths.some((path) => path.endsWith(".feature")) && stepPaths.length > 0) {
|
|
2563
|
+
await loadStepFiles(stepPaths);
|
|
1713
2564
|
}
|
|
1714
|
-
const
|
|
2565
|
+
const loadedFlows = await loadFlowsWithSources(flowPaths);
|
|
2566
|
+
let filteredFlows = filterLoadedFlows(loadedFlows, {
|
|
1715
2567
|
tags: opts.tags,
|
|
1716
2568
|
grep: opts.grep,
|
|
1717
2569
|
platforms
|
|
1718
2570
|
});
|
|
1719
|
-
|
|
1720
|
-
|
|
2571
|
+
if (opts.lastFailed) {
|
|
2572
|
+
const outputDir = config.artifacts?.outputDir ?? resolveFromConfig("./spana-output");
|
|
2573
|
+
const lastRunStatePath = createLastRunStatePath(outputDir);
|
|
2574
|
+
const state = await readLastRunState(lastRunStatePath);
|
|
2575
|
+
if (!state) {
|
|
2576
|
+
console.log("No previous Spana run state found. Run `spana test` once before using --last-failed.");
|
|
2577
|
+
return { success: true, watchRoots };
|
|
2578
|
+
}
|
|
2579
|
+
if (state.failedFlowNames.length === 0) {
|
|
2580
|
+
console.log("No failed flows were recorded in the last Spana run.");
|
|
2581
|
+
return { success: true, watchRoots };
|
|
2582
|
+
}
|
|
2583
|
+
const failedFlowNames = new Set(state.failedFlowNames);
|
|
2584
|
+
filteredFlows = filteredFlows.filter((loaded) => failedFlowNames.has(loaded.flow.name));
|
|
2585
|
+
if (filteredFlows.length === 0) {
|
|
2586
|
+
console.log("No last-failed flows match the current filters.");
|
|
2587
|
+
return { success: true, watchRoots };
|
|
2588
|
+
}
|
|
2589
|
+
console.log(`Rerunning ${filteredFlows.length} flow(s) from the last failed run.`);
|
|
2590
|
+
}
|
|
2591
|
+
const selectedLoadedFlows = applyShard(filteredFlows, opts.shard);
|
|
2592
|
+
const selectedFlows = selectedLoadedFlows.map((loaded) => loaded.flow);
|
|
2593
|
+
if (filteredFlows.length === 0) {
|
|
1721
2594
|
console.log("No flows match the given filters.");
|
|
1722
|
-
return true;
|
|
2595
|
+
return { success: true, watchRoots };
|
|
1723
2596
|
}
|
|
1724
2597
|
if (selectedFlows.length === 0) {
|
|
1725
2598
|
console.log(`No flows assigned to shard ${opts.shard.current}/${opts.shard.total}.`);
|
|
1726
|
-
return true;
|
|
2599
|
+
return { success: true, watchRoots };
|
|
1727
2600
|
}
|
|
1728
2601
|
if (opts.shard) {
|
|
1729
2602
|
console.log(
|
|
1730
|
-
`Running shard ${opts.shard.current}/${opts.shard.total} (${selectedFlows.length}/${
|
|
2603
|
+
`Running shard ${opts.shard.current}/${opts.shard.total} (${selectedFlows.length}/${filteredFlows.length} flow(s))...`
|
|
1731
2604
|
);
|
|
1732
2605
|
}
|
|
1733
2606
|
console.log(`Running ${selectedFlows.length} flow(s) on ${platforms.join(", ")}...
|
|
@@ -1756,7 +2629,7 @@ async function runTestCommand(opts) {
|
|
|
1756
2629
|
const appiumUrl = opts.appiumUrl ?? config.execution?.appium?.serverUrl;
|
|
1757
2630
|
const appiumConfig = config.execution?.appium ?? {};
|
|
1758
2631
|
const shouldReportToProvider = !opts.noProviderReporting && appiumConfig.reportToProvider !== false;
|
|
1759
|
-
const cloudHelper = executionMode === "appium" && appiumUrl ? createCloudProviderHelper(appiumUrl, appiumConfig) : void 0;
|
|
2632
|
+
const cloudHelper = executionMode === "appium" && appiumUrl ? await createCloudProviderHelper(appiumUrl, appiumConfig) : void 0;
|
|
1760
2633
|
const baseAppiumCaps = executionMode === "appium" && appiumUrl ? await resolveCapabilities(appiumConfig, {
|
|
1761
2634
|
capsPath: opts.capsPath,
|
|
1762
2635
|
capsJson: opts.capsJson
|
|
@@ -1764,78 +2637,54 @@ async function runTestCommand(opts) {
|
|
|
1764
2637
|
if (cloudHelper) {
|
|
1765
2638
|
runCleanups.push(() => cloudHelper.cleanup());
|
|
1766
2639
|
}
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
if (!result2) continue;
|
|
1793
|
-
runtimes.push(result2.runtime);
|
|
1794
|
-
platformConfigs.push({
|
|
1795
|
-
platform,
|
|
1796
|
-
driver: result2.runtime.driver,
|
|
1797
|
-
engineConfig: { ...result2.engineConfig, debugOnFailure: opts.debugOnFailure }
|
|
1798
|
-
});
|
|
1799
|
-
} else if (platform === "ios") {
|
|
1800
|
-
const result2 = await buildLocalIOSRuntime(config, targetDevice, resolveFromConfig);
|
|
1801
|
-
if (!result2) continue;
|
|
1802
|
-
runtimes.push(result2.runtime);
|
|
1803
|
-
platformConfigs.push({
|
|
1804
|
-
platform,
|
|
1805
|
-
driver: result2.runtime.driver,
|
|
1806
|
-
engineConfig: { ...result2.engineConfig, debugOnFailure: opts.debugOnFailure }
|
|
1807
|
-
});
|
|
1808
|
-
}
|
|
2640
|
+
if (opts.parallel || opts.workers || opts.devices) {
|
|
2641
|
+
platformConfigs.push(
|
|
2642
|
+
...await buildParallelPlatformConfigs(
|
|
2643
|
+
platforms,
|
|
2644
|
+
opts,
|
|
2645
|
+
config,
|
|
2646
|
+
runtimes,
|
|
2647
|
+
resolveFromConfig
|
|
2648
|
+
)
|
|
2649
|
+
);
|
|
2650
|
+
} else {
|
|
2651
|
+
platformConfigs.push(
|
|
2652
|
+
...await buildSerialPlatformConfigs(
|
|
2653
|
+
platforms,
|
|
2654
|
+
opts,
|
|
2655
|
+
config,
|
|
2656
|
+
runtimes,
|
|
2657
|
+
executionMode,
|
|
2658
|
+
appiumUrl,
|
|
2659
|
+
baseAppiumCaps,
|
|
2660
|
+
cloudHelper,
|
|
2661
|
+
targetDevice,
|
|
2662
|
+
resolveFromConfig
|
|
2663
|
+
)
|
|
2664
|
+
);
|
|
1809
2665
|
}
|
|
1810
|
-
const {
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
const { createAllureReporter } = await import("./allure-PTTVORQ6.js");
|
|
1818
|
-
const resolvedOutputDir = config.artifacts?.outputDir ?? resolveFromConfig("./spana-output");
|
|
1819
|
-
const reporters = reporterNames.split(",").map((r) => {
|
|
1820
|
-
switch (r.trim()) {
|
|
1821
|
-
case "json":
|
|
1822
|
-
return createJsonReporter();
|
|
1823
|
-
case "junit":
|
|
1824
|
-
return createJUnitReporter(resolvedOutputDir);
|
|
1825
|
-
case "html":
|
|
1826
|
-
return createHtmlReporter(resolvedOutputDir);
|
|
1827
|
-
case "allure":
|
|
1828
|
-
return createAllureReporter();
|
|
1829
|
-
default:
|
|
1830
|
-
return createConsoleReporter({ quiet: opts.quiet });
|
|
1831
|
-
}
|
|
1832
|
-
});
|
|
2666
|
+
const { redactor, reporters } = await setupReporters(
|
|
2667
|
+
reporterNames,
|
|
2668
|
+
config,
|
|
2669
|
+
resolveFromConfig,
|
|
2670
|
+
appiumUrl,
|
|
2671
|
+
opts
|
|
2672
|
+
);
|
|
1833
2673
|
const totalFlowCount = selectedFlows.length * platforms.length;
|
|
1834
2674
|
for (const reporter of reporters) {
|
|
1835
2675
|
if (reporter.flowCount !== void 0 || "flowCount" in reporter) {
|
|
1836
2676
|
reporter.flowCount = totalFlowCount;
|
|
1837
2677
|
}
|
|
1838
2678
|
}
|
|
2679
|
+
const platformCounts = {};
|
|
2680
|
+
for (const p of platforms) {
|
|
2681
|
+
platformCounts[p] = selectedFlows.length;
|
|
2682
|
+
}
|
|
2683
|
+
for (const reporter of reporters) {
|
|
2684
|
+
if ("platformFlowCounts" in reporter) {
|
|
2685
|
+
reporter.platformFlowCounts = platformCounts;
|
|
2686
|
+
}
|
|
2687
|
+
}
|
|
1839
2688
|
const redactResult = (r) => {
|
|
1840
2689
|
if (!r.error) return r;
|
|
1841
2690
|
return {
|
|
@@ -1849,12 +2698,15 @@ async function runTestCommand(opts) {
|
|
|
1849
2698
|
};
|
|
1850
2699
|
};
|
|
1851
2700
|
const retries = opts.retries ?? config.defaults?.retries ?? 0;
|
|
2701
|
+
const retryDelay = config.defaults?.retryDelay ?? 0;
|
|
1852
2702
|
const result = await orchestrate(selectedFlows, platformConfigs, {
|
|
1853
2703
|
retries,
|
|
2704
|
+
retryDelay,
|
|
1854
2705
|
bail: opts.bail,
|
|
1855
|
-
|
|
2706
|
+
parallelPlatforms: opts.parallel || !!opts.workers || !!opts.devices,
|
|
2707
|
+
onFlowStart(name, platform, workerName) {
|
|
1856
2708
|
for (const reporter of reporters) {
|
|
1857
|
-
reporter.onFlowStart?.(name, platform);
|
|
2709
|
+
reporter.onFlowStart?.(name, platform, workerName);
|
|
1858
2710
|
}
|
|
1859
2711
|
},
|
|
1860
2712
|
onResult(r) {
|
|
@@ -1864,6 +2716,31 @@ async function runTestCommand(opts) {
|
|
|
1864
2716
|
reporter.onFlowPass?.(redacted);
|
|
1865
2717
|
} else if (redacted.status === "failed") {
|
|
1866
2718
|
reporter.onFlowFail?.(redacted);
|
|
2719
|
+
if (opts.verbose && redacted.error) {
|
|
2720
|
+
console.log(
|
|
2721
|
+
`
|
|
2722
|
+
[verbose] Failure details for "${redacted.name}" on ${redacted.platform}:`
|
|
2723
|
+
);
|
|
2724
|
+
console.log(` Category: ${redacted.error.category}`);
|
|
2725
|
+
console.log(` Message: ${redacted.error.message}`);
|
|
2726
|
+
if (redacted.error.suggestion) {
|
|
2727
|
+
console.log(` Suggestion: ${redacted.error.suggestion}`);
|
|
2728
|
+
}
|
|
2729
|
+
for (const section of collectDiagnosticSections(redacted.attachments, {
|
|
2730
|
+
verbose: true
|
|
2731
|
+
})) {
|
|
2732
|
+
console.log(` ${section.title}: ${redactor.redact(section.path)}`);
|
|
2733
|
+
console.log(
|
|
2734
|
+
section.body.split("\n").map((line) => ` ${redactor.redact(line)}`).join("\n")
|
|
2735
|
+
);
|
|
2736
|
+
}
|
|
2737
|
+
if (redacted.error.stack) {
|
|
2738
|
+
console.log(
|
|
2739
|
+
` Stack:
|
|
2740
|
+
${redacted.error.stack.split("\n").map((l) => ` ${l}`).join("\n")}`
|
|
2741
|
+
);
|
|
2742
|
+
}
|
|
2743
|
+
}
|
|
1867
2744
|
}
|
|
1868
2745
|
}
|
|
1869
2746
|
}
|
|
@@ -1880,11 +2757,33 @@ async function runTestCommand(opts) {
|
|
|
1880
2757
|
results: redactedResults,
|
|
1881
2758
|
platforms,
|
|
1882
2759
|
bailedOut: result.bailedOut,
|
|
1883
|
-
bailLimit: result.bailLimit
|
|
2760
|
+
bailLimit: result.bailLimit,
|
|
2761
|
+
workerStats: result.workerStats
|
|
1884
2762
|
});
|
|
1885
2763
|
}
|
|
2764
|
+
const sourcePathsByFlowName = new Map(
|
|
2765
|
+
selectedLoadedFlows.map((loaded) => [loaded.flow.name, loaded.sourcePath])
|
|
2766
|
+
);
|
|
2767
|
+
const iterationStatePath = createLastRunStatePath(
|
|
2768
|
+
config.artifacts?.outputDir ?? resolveFromConfig("./spana-output")
|
|
2769
|
+
);
|
|
2770
|
+
try {
|
|
2771
|
+
await writeLastRunState(
|
|
2772
|
+
iterationStatePath,
|
|
2773
|
+
buildLastRunState({
|
|
2774
|
+
flowDir,
|
|
2775
|
+
platforms,
|
|
2776
|
+
results: result.results,
|
|
2777
|
+
sourcePathsByFlowName
|
|
2778
|
+
})
|
|
2779
|
+
);
|
|
2780
|
+
} catch (error) {
|
|
2781
|
+
console.log(
|
|
2782
|
+
`Warning: Failed to update last run state at ${iterationStatePath}: ${error instanceof Error ? error.message : error}`
|
|
2783
|
+
);
|
|
2784
|
+
}
|
|
1886
2785
|
if (shouldReportToProvider && appiumUrl) {
|
|
1887
|
-
const { detectProvider: detectProvider2 } = await import("./provider-
|
|
2786
|
+
const { detectProvider: detectProvider2 } = await import("./provider-A57C3MU6.js");
|
|
1888
2787
|
for (const rt of runtimes) {
|
|
1889
2788
|
if (rt.metadata.mode === "appium" && rt.metadata.provider) {
|
|
1890
2789
|
const provider = detectProvider2(appiumUrl);
|
|
@@ -1905,7 +2804,7 @@ async function runTestCommand(opts) {
|
|
|
1905
2804
|
}
|
|
1906
2805
|
}
|
|
1907
2806
|
}
|
|
1908
|
-
return result.failed === 0;
|
|
2807
|
+
return { success: result.failed === 0, watchRoots };
|
|
1909
2808
|
} finally {
|
|
1910
2809
|
for (const rt of runtimes) {
|
|
1911
2810
|
try {
|
|
@@ -1923,7 +2822,31 @@ async function runTestCommand(opts) {
|
|
|
1923
2822
|
process.removeListener("SIGTERM", handleSignal);
|
|
1924
2823
|
}
|
|
1925
2824
|
}
|
|
2825
|
+
async function runTestCommand(opts) {
|
|
2826
|
+
if (!opts.watch) {
|
|
2827
|
+
return (await runTestCommandOnce(opts)).success;
|
|
2828
|
+
}
|
|
2829
|
+
let lastResult = await runTestCommandOnce({ ...opts, watch: false });
|
|
2830
|
+
if (lastResult.watchRoots.length === 0) {
|
|
2831
|
+
return lastResult.success;
|
|
2832
|
+
}
|
|
2833
|
+
console.log(
|
|
2834
|
+
`Watching ${lastResult.watchRoots.length} path(s) for changes. Press Ctrl+C to stop.`
|
|
2835
|
+
);
|
|
2836
|
+
await runWatchLoop({
|
|
2837
|
+
roots: lastResult.watchRoots,
|
|
2838
|
+
onChange: async (changedPaths) => {
|
|
2839
|
+
console.log(`
|
|
2840
|
+
Change detected:
|
|
2841
|
+
${changedPaths.map((path) => ` ${path}`).join("\n")}
|
|
2842
|
+
`);
|
|
2843
|
+
lastResult = await runTestCommandOnce({ ...opts, watch: false });
|
|
2844
|
+
}
|
|
2845
|
+
});
|
|
2846
|
+
return lastResult.success;
|
|
2847
|
+
}
|
|
1926
2848
|
export {
|
|
2849
|
+
loadCustomReporter,
|
|
1927
2850
|
runTestCommand
|
|
1928
2851
|
};
|
|
1929
|
-
//# sourceMappingURL=test-command-
|
|
2852
|
+
//# sourceMappingURL=test-command-AHMOZLV4.js.map
|