spana-test 0.2.0 → 0.4.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/README.md +47 -12
- package/dist/accessibility-audit-RS3VIWRT.js +140 -0
- package/dist/accessibility-audit-RS3VIWRT.js.map +1 -0
- package/dist/agent/index.d.ts +8 -26
- package/dist/agent/index.js +12 -15
- package/dist/{allure-PTTVORQ6.js → allure-RNMEYTXS.js} +42 -2
- package/dist/allure-RNMEYTXS.js.map +1 -0
- package/dist/{android-PAPJJWVN.js → android-GFW6OXPQ.js} +16 -2
- package/dist/appium-server-66GVUL24.js +119 -0
- package/dist/appium-server-66GVUL24.js.map +1 -0
- package/dist/baseline-manager-5TIUCNP5.js +38 -0
- package/dist/baseline-manager-5TIUCNP5.js.map +1 -0
- package/dist/chunk-3J4NG7JU.js +80 -0
- package/dist/chunk-3J4NG7JU.js.map +1 -0
- package/dist/{chunk-MRH7SK52.js → chunk-3TRMQCUT.js} +3 -2
- package/dist/chunk-3TRMQCUT.js.map +1 -0
- package/dist/chunk-5245YBLL.js +127 -0
- package/dist/chunk-5245YBLL.js.map +1 -0
- package/dist/{chunk-L7MFJF46.js → chunk-7VOWF42B.js} +29 -5
- package/dist/chunk-7VOWF42B.js.map +1 -0
- package/dist/{chunk-GZK22EIE.js → chunk-EWIR2GVV.js} +54 -1
- package/dist/chunk-EWIR2GVV.js.map +1 -0
- package/dist/{chunk-P7JQRLP4.js → chunk-FJAJ4YNC.js} +14 -2
- package/dist/chunk-FJAJ4YNC.js.map +1 -0
- package/dist/chunk-IHVZKQQW.js +24 -0
- package/dist/chunk-IHVZKQQW.js.map +1 -0
- package/dist/{chunk-S4R4OR7T.js → chunk-KYPLYRKW.js} +67 -72
- package/dist/chunk-KYPLYRKW.js.map +1 -0
- package/dist/{chunk-YBZCOQXJ.js → chunk-LC3QJIHY.js} +196 -67
- package/dist/chunk-LC3QJIHY.js.map +1 -0
- package/dist/{chunk-WQ4GXUUE.js → chunk-MCT4DYDK.js} +353 -84
- package/dist/chunk-MCT4DYDK.js.map +1 -0
- package/dist/chunk-OBCFACUW.js +28 -0
- package/dist/chunk-OBCFACUW.js.map +1 -0
- package/dist/{chunk-AEKDFFPJ.js → chunk-PZYZ4O6D.js} +16 -5
- package/dist/chunk-PZYZ4O6D.js.map +1 -0
- package/dist/{chunk-SFBRFB2N.js → chunk-S5JNNDXS.js} +62 -12
- package/dist/chunk-S5JNNDXS.js.map +1 -0
- package/dist/{chunk-VNYF5BHX.js → chunk-X2TJP7LB.js} +1 -3
- package/dist/{chunk-S2XNAKSO.js → chunk-YAV6KBSW.js} +564 -333
- package/dist/chunk-YAV6KBSW.js.map +1 -0
- package/dist/{chunk-3YR4GUGE.js → chunk-YGHDMA6D.js} +65 -70
- package/dist/chunk-YGHDMA6D.js.map +1 -0
- package/dist/cli.js +40 -25
- package/dist/cli.js.map +1 -1
- package/dist/{compiler-74VGKZO6.js → compiler-X6WTFMYF.js} +15 -7
- package/dist/compiler-X6WTFMYF.js.map +1 -0
- package/dist/config-loader-QM72GKEL.js +9 -0
- package/dist/{console-XWKUTP3D.js → console-7UW7VROK.js} +71 -1
- package/dist/console-7UW7VROK.js.map +1 -0
- package/dist/{discover-KZKXHZZA.js → discover-CAQY6EG6.js} +5 -4
- package/dist/doctor-command-YGQPO7GH.js +71 -0
- package/dist/doctor-command-YGQPO7GH.js.map +1 -0
- package/dist/flow-thjUxXXx.d.ts +168 -0
- package/dist/gherkin/steps.d.ts +2 -2
- package/dist/{html-GE6Q4DCG.js → html-F3X3XPSX.js} +78 -7
- package/dist/html-F3X3XPSX.js.map +1 -0
- package/dist/index.d.ts +4 -8
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/{init-command-GVMRXIMY.js → init-command-U66XCM66.js} +19 -34
- package/dist/init-command-U66XCM66.js.map +1 -0
- package/dist/init-flow-command-PR7J5FBM.js +37 -0
- package/dist/init-flow-command-PR7J5FBM.js.map +1 -0
- package/dist/{installer-YZJ4DV3F.js → installer-PVBSX7UC.js} +3 -4
- package/dist/{ios-ZW6XVNLG.js → ios-JPK43TFZ.js} +11 -4
- package/dist/json-JMRPUVY2.js +20 -0
- package/dist/json-JMRPUVY2.js.map +1 -0
- package/dist/machine-6H25TRTU.js +16 -0
- package/dist/{provider-A57C3MU6.js → provider-YIPU5K42.js} +2 -2
- package/dist/{runner-UXNHVVGG.js → runner-6HK62Q7B.js} +2 -2
- package/dist/screenshot-compare-JFHH2WR4.js +75 -0
- package/dist/screenshot-compare-JFHH2WR4.js.map +1 -0
- package/dist/{server-W7OA3DDN.js → server-PZBRGU7P.js} +362 -55
- package/dist/server-PZBRGU7P.js.map +1 -0
- package/dist/session-2MZVGYAC.js +17 -0
- package/dist/{coordinator-BbUjvvnX.d.ts → storybook-pBOPe_1D.d.ts} +101 -33
- package/dist/{studio-command-6VHTHDUK.js → studio-command-YDWQOMRX.js} +2 -2
- package/dist/{test-command-AHMOZLV4.js → test-command-B2VLWGDK.js} +945 -565
- package/dist/test-command-B2VLWGDK.js.map +1 -0
- package/dist/{validator-35624P7S.js → validator-HZ2A3NEI.js} +3 -6
- package/dist/validator-HZ2A3NEI.js.map +1 -0
- package/package.json +6 -1
- package/studio-dist/assets/index-C-Io44gy.js +193 -0
- package/studio-dist/assets/index-DfM9lK4p.css +1 -0
- package/studio-dist/index.html +2 -2
- package/dist/allure-PTTVORQ6.js.map +0 -1
- package/dist/chunk-3YR4GUGE.js.map +0 -1
- package/dist/chunk-AEKDFFPJ.js.map +0 -1
- package/dist/chunk-BF37W5EG.js +0 -125
- package/dist/chunk-BF37W5EG.js.map +0 -1
- package/dist/chunk-EXLUY7KT.js +0 -21
- package/dist/chunk-EXLUY7KT.js.map +0 -1
- package/dist/chunk-FNDOEMOL.js +0 -62
- package/dist/chunk-FNDOEMOL.js.map +0 -1
- package/dist/chunk-GZK22EIE.js.map +0 -1
- package/dist/chunk-HWFDXIXR.js +0 -183
- package/dist/chunk-HWFDXIXR.js.map +0 -1
- package/dist/chunk-IJIASIX5.js +0 -314
- package/dist/chunk-IJIASIX5.js.map +0 -1
- package/dist/chunk-L7MFJF46.js.map +0 -1
- package/dist/chunk-MRH7SK52.js.map +0 -1
- package/dist/chunk-P7JQRLP4.js.map +0 -1
- package/dist/chunk-S2XNAKSO.js.map +0 -1
- package/dist/chunk-S4R4OR7T.js.map +0 -1
- package/dist/chunk-SFBRFB2N.js.map +0 -1
- package/dist/chunk-WBU34APM.js +0 -38
- package/dist/chunk-WBU34APM.js.map +0 -1
- package/dist/chunk-WQ4GXUUE.js.map +0 -1
- package/dist/chunk-YBZCOQXJ.js.map +0 -1
- package/dist/compiler-74VGKZO6.js.map +0 -1
- package/dist/config-loader-BJJ3IJJ7.js +0 -9
- package/dist/console-XWKUTP3D.js.map +0 -1
- package/dist/doctor-command-T2UX5RV5.js +0 -732
- package/dist/doctor-command-T2UX5RV5.js.map +0 -1
- package/dist/flow-BUC9Mf8W.d.ts +0 -128
- package/dist/html-GE6Q4DCG.js.map +0 -1
- package/dist/init-command-GVMRXIMY.js.map +0 -1
- package/dist/init-flow-command-R76AXF4Z.js +0 -34
- package/dist/init-flow-command-R76AXF4Z.js.map +0 -1
- package/dist/json-KS67BZYU.js +0 -39
- package/dist/json-KS67BZYU.js.map +0 -1
- package/dist/server-W7OA3DDN.js.map +0 -1
- package/dist/session-TMNOKYLG.js +0 -17
- package/dist/test-command-AHMOZLV4.js.map +0 -1
- package/studio-dist/assets/index-DC6DIXfl.js +0 -188
- package/studio-dist/assets/index-DDKsnBwD.css +0 -1
- /package/dist/{android-PAPJJWVN.js.map → android-GFW6OXPQ.js.map} +0 -0
- /package/dist/{chunk-VNYF5BHX.js.map → chunk-X2TJP7LB.js.map} +0 -0
- /package/dist/{config-loader-BJJ3IJJ7.js.map → config-loader-QM72GKEL.js.map} +0 -0
- /package/dist/{discover-KZKXHZZA.js.map → discover-CAQY6EG6.js.map} +0 -0
- /package/dist/{installer-YZJ4DV3F.js.map → installer-PVBSX7UC.js.map} +0 -0
- /package/dist/{ios-ZW6XVNLG.js.map → ios-JPK43TFZ.js.map} +0 -0
- /package/dist/{provider-A57C3MU6.js.map → machine-6H25TRTU.js.map} +0 -0
- /package/dist/{runner-UXNHVVGG.js.map → provider-YIPU5K42.js.map} +0 -0
- /package/dist/{session-TMNOKYLG.js.map → runner-6HK62Q7B.js.map} +0 -0
- /package/dist/{validator-35624P7S.js.map → session-2MZVGYAC.js.map} +0 -0
- /package/dist/{studio-command-6VHTHDUK.js.map → studio-command-YDWQOMRX.js.map} +0 -0
|
@@ -1,28 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
loadConfig
|
|
3
|
+
} from "./chunk-FJAJ4YNC.js";
|
|
1
4
|
import {
|
|
2
5
|
collectDiagnosticSections
|
|
3
6
|
} from "./chunk-KJPHH2TW.js";
|
|
4
7
|
import {
|
|
5
|
-
|
|
6
|
-
} from "./chunk-EXLUY7KT.js";
|
|
7
|
-
import {
|
|
8
|
-
loadConfig
|
|
9
|
-
} from "./chunk-P7JQRLP4.js";
|
|
10
|
-
import {
|
|
8
|
+
SessionManager,
|
|
11
9
|
createPromiseApp,
|
|
12
|
-
createPromiseExpect
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
createPromiseExpect,
|
|
11
|
+
createSessions
|
|
12
|
+
} from "./chunk-LC3QJIHY.js";
|
|
13
|
+
import "./chunk-7VOWF42B.js";
|
|
15
14
|
import {
|
|
16
15
|
createUiAutomator2Driver,
|
|
17
16
|
createWDADriver,
|
|
18
17
|
makePlaywrightDriver,
|
|
19
18
|
parseAndroidHierarchy,
|
|
20
19
|
parseIOSHierarchy,
|
|
21
|
-
|
|
22
|
-
} from "./chunk-WQ4GXUUE.js";
|
|
23
|
-
import {
|
|
20
|
+
resolveNetworkConditions,
|
|
24
21
|
setupUiAutomator2
|
|
25
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-MCT4DYDK.js";
|
|
23
|
+
import {
|
|
24
|
+
setupWDA
|
|
25
|
+
} from "./chunk-YGHDMA6D.js";
|
|
26
|
+
import {
|
|
27
|
+
ensureAndroidDevice
|
|
28
|
+
} from "./chunk-EWIR2GVV.js";
|
|
29
|
+
import {
|
|
30
|
+
connectPhysicalDevice,
|
|
31
|
+
ensureAppInstalled,
|
|
32
|
+
ensureIOSSimulator,
|
|
33
|
+
firstIOSPhysicalDevice
|
|
34
|
+
} from "./chunk-S5JNNDXS.js";
|
|
35
|
+
import {
|
|
36
|
+
allocatePort
|
|
37
|
+
} from "./chunk-OBCFACUW.js";
|
|
26
38
|
import {
|
|
27
39
|
applyShard,
|
|
28
40
|
discoverFlows,
|
|
@@ -30,34 +42,21 @@ import {
|
|
|
30
42
|
filterFlows,
|
|
31
43
|
loadStepFiles,
|
|
32
44
|
loadTestSource
|
|
33
|
-
} from "./chunk-
|
|
45
|
+
} from "./chunk-3TRMQCUT.js";
|
|
34
46
|
import {
|
|
35
47
|
DriverError,
|
|
48
|
+
buildIOSLaunchConfiguration,
|
|
49
|
+
deviceStateToAppiumCapabilities,
|
|
36
50
|
flattenElements,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
failureCategoryToErrorCode
|
|
43
|
-
} from "./chunk-FNDOEMOL.js";
|
|
51
|
+
hasLaunchDeviceState,
|
|
52
|
+
mergeLaunchOptions,
|
|
53
|
+
parseWebHierarchy,
|
|
54
|
+
splitGraphemes
|
|
55
|
+
} from "./chunk-YAV6KBSW.js";
|
|
44
56
|
import {
|
|
45
57
|
createCloudProviderHelper,
|
|
46
58
|
detectProvider
|
|
47
|
-
} from "./chunk-
|
|
48
|
-
import {
|
|
49
|
-
ensureAndroidDevice
|
|
50
|
-
} from "./chunk-GZK22EIE.js";
|
|
51
|
-
import {
|
|
52
|
-
connectPhysicalDevice,
|
|
53
|
-
ensureAppInstalled,
|
|
54
|
-
ensureIOSSimulator,
|
|
55
|
-
firstIOSPhysicalDevice
|
|
56
|
-
} from "./chunk-SFBRFB2N.js";
|
|
57
|
-
import {
|
|
58
|
-
allocatePort,
|
|
59
|
-
setupWDA
|
|
60
|
-
} from "./chunk-3YR4GUGE.js";
|
|
59
|
+
} from "./chunk-X2TJP7LB.js";
|
|
61
60
|
import "./chunk-DGUM43GV.js";
|
|
62
61
|
|
|
63
62
|
// src/cli/test-command.ts
|
|
@@ -610,11 +609,162 @@ function classifyError(error) {
|
|
|
610
609
|
message: error.message,
|
|
611
610
|
stack: error.stack,
|
|
612
611
|
category,
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
612
|
+
suggestion
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
// src/core/engine.ts
|
|
617
|
+
import { join as join3 } from "path";
|
|
618
|
+
|
|
619
|
+
// src/report/failure-bundle.ts
|
|
620
|
+
import { writeFileSync as writeFileSync2, readFileSync, existsSync } from "fs";
|
|
621
|
+
import { join as join2, basename } from "path";
|
|
622
|
+
function levenshtein(a, b) {
|
|
623
|
+
const m = a.length;
|
|
624
|
+
const n = b.length;
|
|
625
|
+
const dp = Array.from({ length: m + 1 }, () => Array(n + 1).fill(0));
|
|
626
|
+
for (let i = 0; i <= m; i++) dp[i][0] = i;
|
|
627
|
+
for (let j = 0; j <= n; j++) dp[0][j] = j;
|
|
628
|
+
for (let i = 1; i <= m; i++) {
|
|
629
|
+
for (let j = 1; j <= n; j++) {
|
|
630
|
+
dp[i][j] = a[i - 1] === b[j - 1] ? dp[i - 1][j - 1] : 1 + Math.min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
return dp[m][n];
|
|
634
|
+
}
|
|
635
|
+
function extractIdentifiers(hierarchyJson) {
|
|
636
|
+
const testIDs = [];
|
|
637
|
+
const texts = [];
|
|
638
|
+
try {
|
|
639
|
+
const root = JSON.parse(hierarchyJson);
|
|
640
|
+
const queue = [root];
|
|
641
|
+
while (queue.length > 0) {
|
|
642
|
+
const node = queue.pop();
|
|
643
|
+
if (!node || typeof node !== "object") continue;
|
|
644
|
+
if (node.testID && typeof node.testID === "string") testIDs.push(node.testID);
|
|
645
|
+
if (node.text && typeof node.text === "string") texts.push(node.text);
|
|
646
|
+
if (Array.isArray(node.children)) {
|
|
647
|
+
for (const child of node.children) queue.push(child);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
} catch {
|
|
651
|
+
}
|
|
652
|
+
return { testIDs, texts };
|
|
653
|
+
}
|
|
654
|
+
function findNearbySelectors(attempted, hierarchyJson) {
|
|
655
|
+
if (!hierarchyJson) return [];
|
|
656
|
+
const { testIDs, texts } = extractIdentifiers(hierarchyJson);
|
|
657
|
+
let target;
|
|
658
|
+
let candidates;
|
|
659
|
+
if (typeof attempted === "string") {
|
|
660
|
+
target = attempted.toLowerCase();
|
|
661
|
+
candidates = [...testIDs, ...texts];
|
|
662
|
+
} else if (attempted && typeof attempted === "object") {
|
|
663
|
+
const sel = attempted;
|
|
664
|
+
if (typeof sel.testID === "string") {
|
|
665
|
+
target = sel.testID.toLowerCase();
|
|
666
|
+
candidates = testIDs;
|
|
667
|
+
} else if (typeof sel.text === "string") {
|
|
668
|
+
target = sel.text.toLowerCase();
|
|
669
|
+
candidates = texts;
|
|
670
|
+
} else if (typeof sel.accessibilityLabel === "string") {
|
|
671
|
+
target = sel.accessibilityLabel.toLowerCase();
|
|
672
|
+
candidates = [...testIDs, ...texts];
|
|
673
|
+
} else {
|
|
674
|
+
return [];
|
|
675
|
+
}
|
|
676
|
+
} else {
|
|
677
|
+
return [];
|
|
678
|
+
}
|
|
679
|
+
const scored = candidates.filter((c) => c !== target).map((c) => {
|
|
680
|
+
const cl = c.toLowerCase();
|
|
681
|
+
const substringMatch = cl.includes(target) || target.includes(cl);
|
|
682
|
+
const dist = levenshtein(target, cl);
|
|
683
|
+
return { value: c, score: substringMatch ? 0 : dist };
|
|
684
|
+
}).filter((s) => s.score <= 5).toSorted((a, b) => a.score - b.score);
|
|
685
|
+
const seen = /* @__PURE__ */ new Set();
|
|
686
|
+
const results = [];
|
|
687
|
+
for (const s of scored) {
|
|
688
|
+
if (!seen.has(s.value)) {
|
|
689
|
+
seen.add(s.value);
|
|
690
|
+
results.push(s.value);
|
|
691
|
+
if (results.length >= 5) break;
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
return results;
|
|
695
|
+
}
|
|
696
|
+
function buildArtifactMap(attachments) {
|
|
697
|
+
const map = {};
|
|
698
|
+
if (!attachments) return map;
|
|
699
|
+
for (const att of attachments) {
|
|
700
|
+
const filename = basename(att.path);
|
|
701
|
+
if (filename === "screenshot.png") map.screenshot = filename;
|
|
702
|
+
else if (filename === "hierarchy.json") map.hierarchy = filename;
|
|
703
|
+
else if (filename === "console-logs.json") map.consoleLogs = filename;
|
|
704
|
+
else if (filename === "js-errors.json") map.jsErrors = filename;
|
|
705
|
+
else if (filename === "network.har") map.har = filename;
|
|
706
|
+
else if (filename === "driver-logs.txt") map.driverLogs = filename;
|
|
707
|
+
}
|
|
708
|
+
return map;
|
|
709
|
+
}
|
|
710
|
+
function createFailureBundle(flowName, platform, steps, error, artifactDir, attachments, flowPath) {
|
|
711
|
+
const failedStepIndex = steps.findLastIndex((s) => s.status === "failed");
|
|
712
|
+
const failedStep = failedStepIndex >= 0 ? {
|
|
713
|
+
index: failedStepIndex,
|
|
714
|
+
command: steps[failedStepIndex].command,
|
|
715
|
+
selector: steps[failedStepIndex].selector ?? null,
|
|
716
|
+
durationMs: steps[failedStepIndex].durationMs,
|
|
717
|
+
error: steps[failedStepIndex].error
|
|
718
|
+
} : null;
|
|
719
|
+
const lastPassedIndex = failedStepIndex > 0 ? steps.findLastIndex((s, i) => i < failedStepIndex && s.status === "passed") : -1;
|
|
720
|
+
const lastPassedStep = lastPassedIndex >= 0 ? {
|
|
721
|
+
index: lastPassedIndex,
|
|
722
|
+
command: steps[lastPassedIndex].command,
|
|
723
|
+
selector: steps[lastPassedIndex].selector ?? null,
|
|
724
|
+
durationMs: steps[lastPassedIndex].durationMs
|
|
725
|
+
} : null;
|
|
726
|
+
let selectorContext;
|
|
727
|
+
if (failedStep?.selector && (error.category === "element-not-found" || error.category === "element-not-visible")) {
|
|
728
|
+
const hierarchyPath = join2(artifactDir, "hierarchy.json");
|
|
729
|
+
let hierarchyJson = null;
|
|
730
|
+
if (existsSync(hierarchyPath)) {
|
|
731
|
+
try {
|
|
732
|
+
hierarchyJson = readFileSync(hierarchyPath, "utf-8");
|
|
733
|
+
} catch {
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
const nearbyAlternatives = findNearbySelectors(failedStep.selector, hierarchyJson);
|
|
737
|
+
selectorContext = {
|
|
738
|
+
attempted: failedStep.selector,
|
|
739
|
+
nearbyAlternatives
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
const flowFile = flowPath ?? `flows/${flowName.replaceAll(" ", "-")}.flow.ts`;
|
|
743
|
+
const reproCommand = `spana test ${flowFile} --platform ${platform} --grep '${flowName}'`;
|
|
744
|
+
const bundle = {
|
|
745
|
+
schemaVersion: 1,
|
|
746
|
+
flow: flowName,
|
|
747
|
+
platform,
|
|
748
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
749
|
+
failedStep,
|
|
750
|
+
lastPassedStep,
|
|
751
|
+
error: {
|
|
752
|
+
message: error.message,
|
|
753
|
+
category: error.category,
|
|
754
|
+
suggestion: error.suggestion,
|
|
755
|
+
errorCode: error.errorCode
|
|
756
|
+
},
|
|
757
|
+
selectorContext,
|
|
758
|
+
artifacts: buildArtifactMap(attachments),
|
|
759
|
+
reproCommand,
|
|
760
|
+
durationMs: steps.reduce((sum, s) => sum + s.durationMs, 0)
|
|
617
761
|
};
|
|
762
|
+
return bundle;
|
|
763
|
+
}
|
|
764
|
+
function writeFailureBundle(bundle, artifactDir) {
|
|
765
|
+
const path = join2(artifactDir, "failure-bundle.json");
|
|
766
|
+
writeFileSync2(path, JSON.stringify(bundle, null, 2), "utf-8");
|
|
767
|
+
return path;
|
|
618
768
|
}
|
|
619
769
|
|
|
620
770
|
// src/core/engine.ts
|
|
@@ -625,6 +775,7 @@ async function executeFlow(flow, driver, config) {
|
|
|
625
775
|
const timeout = flow.config.timeout ?? config.flowTimeout ?? 6e4;
|
|
626
776
|
const artifactConfig = resolveArtifactConfig(config.artifactConfig, flow.config.artifacts);
|
|
627
777
|
const stepRecorder = createStepRecorder(driver, artifactConfig, flow.name, platform);
|
|
778
|
+
const launchOptions = mergeLaunchOptions(config.launchOptions, flow.config.launchOptions);
|
|
628
779
|
const flowDefaults = flow.config.defaults;
|
|
629
780
|
const mergedCoordinatorConfig = flowDefaults ? {
|
|
630
781
|
...coordinatorConfig,
|
|
@@ -639,11 +790,51 @@ async function executeFlow(flow, driver, config) {
|
|
|
639
790
|
typingDelay: flowDefaults.typingDelay ?? coordinatorConfig.typingDelay,
|
|
640
791
|
hierarchyCacheTtl: flowDefaults.hierarchyCacheTtl ?? coordinatorConfig.hierarchyCacheTtl
|
|
641
792
|
} : coordinatorConfig;
|
|
642
|
-
const app = createPromiseApp(driver, appId, mergedCoordinatorConfig, stepRecorder
|
|
643
|
-
|
|
644
|
-
|
|
793
|
+
const app = createPromiseApp(driver, appId, mergedCoordinatorConfig, stepRecorder, {
|
|
794
|
+
platform,
|
|
795
|
+
storybook: config.storybook,
|
|
796
|
+
launchOptions
|
|
797
|
+
});
|
|
798
|
+
const flowMeta = {
|
|
799
|
+
flowFilePath: flow.sourcePath ?? "",
|
|
800
|
+
flowName: flow.name,
|
|
801
|
+
platform,
|
|
802
|
+
updateBaselines: config.updateBaselines ?? false
|
|
803
|
+
};
|
|
804
|
+
const expect = createPromiseExpect(
|
|
805
|
+
driver,
|
|
806
|
+
mergedCoordinatorConfig,
|
|
807
|
+
stepRecorder,
|
|
808
|
+
flowMeta,
|
|
809
|
+
config.visualRegression
|
|
810
|
+
);
|
|
811
|
+
const flowCtx = { app, expect, platform, updateBaselines: flowMeta.updateBaselines };
|
|
812
|
+
const sessionManager = new SessionManager();
|
|
813
|
+
const sessions = createSessions(
|
|
814
|
+
sessionManager,
|
|
815
|
+
async (opts) => {
|
|
816
|
+
const pwDriver = await Effect3.runPromise(
|
|
817
|
+
makePlaywrightDriver({
|
|
818
|
+
browser: opts.browser,
|
|
819
|
+
headless: opts.headless ?? true,
|
|
820
|
+
baseUrl: opts.baseUrl,
|
|
821
|
+
storageState: opts.storageState,
|
|
822
|
+
verboseLogging: opts.verboseLogging
|
|
823
|
+
})
|
|
824
|
+
);
|
|
825
|
+
return pwDriver;
|
|
826
|
+
},
|
|
827
|
+
{ parse: (raw) => parseWebHierarchy(raw) }
|
|
828
|
+
);
|
|
829
|
+
flowCtx.sessions = sessions;
|
|
645
830
|
const buildFailureResult = async (error) => {
|
|
646
|
-
const attachments = await captureArtifacts(
|
|
831
|
+
const attachments = await captureArtifacts(
|
|
832
|
+
driver,
|
|
833
|
+
artifactConfig,
|
|
834
|
+
flow.name,
|
|
835
|
+
platform,
|
|
836
|
+
"failed"
|
|
837
|
+
);
|
|
647
838
|
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
648
839
|
return {
|
|
649
840
|
name: flow.name,
|
|
@@ -673,7 +864,7 @@ async function executeFlow(flow, driver, config) {
|
|
|
673
864
|
let result;
|
|
674
865
|
try {
|
|
675
866
|
if (autoLaunch) {
|
|
676
|
-
await app.launch(
|
|
867
|
+
await app.launch();
|
|
677
868
|
}
|
|
678
869
|
await Promise.race([
|
|
679
870
|
flow.fn(flowCtx),
|
|
@@ -719,6 +910,24 @@ async function executeFlow(flow, driver, config) {
|
|
|
719
910
|
steps: stepRecorder.getSteps(),
|
|
720
911
|
scenarioSteps: flowCtx.__scenarioSteps
|
|
721
912
|
};
|
|
913
|
+
if (artifactConfig.captureOnFailure && result.error) {
|
|
914
|
+
try {
|
|
915
|
+
const artDir = join3(
|
|
916
|
+
artifactConfig.outputDir,
|
|
917
|
+
`${flow.name.replaceAll(/[^a-zA-Z0-9-_]/g, "_").replaceAll(/_+/g, "_").slice(0, 80) || "artifact"}-${platform}`
|
|
918
|
+
);
|
|
919
|
+
const bundle = createFailureBundle(
|
|
920
|
+
flow.name,
|
|
921
|
+
platform,
|
|
922
|
+
stepRecorder.getSteps(),
|
|
923
|
+
result.error,
|
|
924
|
+
artDir,
|
|
925
|
+
attachments
|
|
926
|
+
);
|
|
927
|
+
writeFailureBundle(bundle, artDir);
|
|
928
|
+
} catch {
|
|
929
|
+
}
|
|
930
|
+
}
|
|
722
931
|
if (config.debugOnFailure) {
|
|
723
932
|
await runDebugReplOnce({
|
|
724
933
|
app,
|
|
@@ -731,6 +940,10 @@ async function executeFlow(flow, driver, config) {
|
|
|
731
940
|
});
|
|
732
941
|
}
|
|
733
942
|
}
|
|
943
|
+
try {
|
|
944
|
+
await sessionManager.disconnectAll();
|
|
945
|
+
} catch {
|
|
946
|
+
}
|
|
734
947
|
if (config.hooks?.afterEach) {
|
|
735
948
|
try {
|
|
736
949
|
await config.hooks.afterEach({ app, platform, result });
|
|
@@ -984,6 +1197,30 @@ async function orchestrate(flows, platforms, options) {
|
|
|
984
1197
|
};
|
|
985
1198
|
}
|
|
986
1199
|
|
|
1200
|
+
// src/runtime/capabilities.ts
|
|
1201
|
+
import { readFile } from "fs/promises";
|
|
1202
|
+
async function resolveCapabilities(config, opts) {
|
|
1203
|
+
const configCaps = config.capabilities ?? {};
|
|
1204
|
+
const launchDeviceCaps = opts.platform === "android" || opts.platform === "ios" ? deviceStateToAppiumCapabilities(opts.platform, opts.launchOptions?.deviceState) : {};
|
|
1205
|
+
let platformCaps = {};
|
|
1206
|
+
if (opts.platform === "android" && config.platformCapabilities?.android) {
|
|
1207
|
+
platformCaps = config.platformCapabilities.android;
|
|
1208
|
+
} else if (opts.platform === "ios" && config.platformCapabilities?.ios) {
|
|
1209
|
+
platformCaps = config.platformCapabilities.ios;
|
|
1210
|
+
}
|
|
1211
|
+
let fileCaps = {};
|
|
1212
|
+
const capsFilePath = opts.capsPath ?? config.capabilitiesFile;
|
|
1213
|
+
if (capsFilePath) {
|
|
1214
|
+
const raw = await readFile(capsFilePath, "utf-8");
|
|
1215
|
+
fileCaps = JSON.parse(raw);
|
|
1216
|
+
}
|
|
1217
|
+
let cliCaps = {};
|
|
1218
|
+
if (opts.capsJson) {
|
|
1219
|
+
cliCaps = JSON.parse(opts.capsJson);
|
|
1220
|
+
}
|
|
1221
|
+
return { ...launchDeviceCaps, ...configCaps, ...platformCaps, ...fileCaps, ...cliCaps };
|
|
1222
|
+
}
|
|
1223
|
+
|
|
987
1224
|
// src/runtime/local.ts
|
|
988
1225
|
import { Effect as Effect4 } from "effect";
|
|
989
1226
|
async function safeCleanup(...fns) {
|
|
@@ -994,7 +1231,7 @@ async function safeCleanup(...fns) {
|
|
|
994
1231
|
}
|
|
995
1232
|
}
|
|
996
1233
|
}
|
|
997
|
-
function buildEngineConfig(appId, platform, parseFn, config) {
|
|
1234
|
+
function buildEngineConfig(appId, platform, parseFn, config, screenSize) {
|
|
998
1235
|
return {
|
|
999
1236
|
appId,
|
|
1000
1237
|
platform,
|
|
@@ -1002,22 +1239,29 @@ function buildEngineConfig(appId, platform, parseFn, config) {
|
|
|
1002
1239
|
parse: parseFn,
|
|
1003
1240
|
defaults: {
|
|
1004
1241
|
timeout: config.defaults?.waitTimeout,
|
|
1005
|
-
pollInterval: config.defaults?.pollInterval
|
|
1242
|
+
pollInterval: config.defaults?.pollInterval,
|
|
1243
|
+
settleTimeout: config.defaults?.settleTimeout,
|
|
1244
|
+
initialPollInterval: config.defaults?.initialPollInterval
|
|
1006
1245
|
},
|
|
1007
1246
|
waitForIdleTimeout: config.defaults?.waitForIdleTimeout,
|
|
1008
|
-
typingDelay: config.defaults?.typingDelay
|
|
1247
|
+
typingDelay: config.defaults?.typingDelay,
|
|
1248
|
+
hierarchyCacheTtl: config.defaults?.hierarchyCacheTtl,
|
|
1249
|
+
screenWidth: screenSize?.width,
|
|
1250
|
+
screenHeight: screenSize?.height
|
|
1009
1251
|
},
|
|
1010
1252
|
autoLaunch: true,
|
|
1011
1253
|
flowTimeout: config.defaults?.waitTimeout ? config.defaults.waitTimeout * 10 : 6e4,
|
|
1012
1254
|
artifactConfig: config.artifacts,
|
|
1013
1255
|
launchOptions: config.launchOptions,
|
|
1014
|
-
hooks: config.hooks
|
|
1256
|
+
hooks: config.hooks,
|
|
1257
|
+
storybook: platform === "web" ? config.execution?.web?.storybook : void 0,
|
|
1258
|
+
visualRegression: config.visualRegression
|
|
1015
1259
|
};
|
|
1016
1260
|
}
|
|
1017
1261
|
async function buildWebRuntime(config) {
|
|
1018
1262
|
const webUrl = config.apps?.web?.url ?? "http://localhost:3000";
|
|
1019
1263
|
const webExecution = config.execution?.web;
|
|
1020
|
-
const
|
|
1264
|
+
const driver = await Effect4.runPromise(
|
|
1021
1265
|
makePlaywrightDriver({
|
|
1022
1266
|
browser: webExecution?.browser,
|
|
1023
1267
|
headless: webExecution?.headless ?? true,
|
|
@@ -1026,7 +1270,7 @@ async function buildWebRuntime(config) {
|
|
|
1026
1270
|
verboseLogging: webExecution?.verboseLogging
|
|
1027
1271
|
})
|
|
1028
1272
|
);
|
|
1029
|
-
const
|
|
1273
|
+
const deviceInfo = await Effect4.runPromise(driver.getDeviceInfo());
|
|
1030
1274
|
return {
|
|
1031
1275
|
runtime: {
|
|
1032
1276
|
driver,
|
|
@@ -1036,7 +1280,10 @@ async function buildWebRuntime(config) {
|
|
|
1036
1280
|
mode: "local"
|
|
1037
1281
|
}
|
|
1038
1282
|
},
|
|
1039
|
-
engineConfig: buildEngineConfig(webUrl, "web", parseWebHierarchy, config
|
|
1283
|
+
engineConfig: buildEngineConfig(webUrl, "web", parseWebHierarchy, config, {
|
|
1284
|
+
width: deviceInfo.screenWidth,
|
|
1285
|
+
height: deviceInfo.screenHeight
|
|
1286
|
+
})
|
|
1040
1287
|
};
|
|
1041
1288
|
}
|
|
1042
1289
|
async function buildLocalAndroidRuntime(config, targetDevice, resolveFromConfig) {
|
|
@@ -1053,7 +1300,7 @@ async function buildLocalAndroidRuntime(config, targetDevice, resolveFromConfig)
|
|
|
1053
1300
|
const androidAppPath = config.apps?.android?.appPath;
|
|
1054
1301
|
if (androidAppPath && packageName) {
|
|
1055
1302
|
try {
|
|
1056
|
-
const { adbShell, adbInstall } = await import("./android-
|
|
1303
|
+
const { adbShell, adbInstall } = await import("./android-GFW6OXPQ.js");
|
|
1057
1304
|
const output = adbShell(device.serial, `pm list packages ${packageName}`);
|
|
1058
1305
|
if (!output.includes(packageName)) {
|
|
1059
1306
|
console.log(`Installing ${packageName} on Android device...`);
|
|
@@ -1061,17 +1308,17 @@ async function buildLocalAndroidRuntime(config, targetDevice, resolveFromConfig)
|
|
|
1061
1308
|
}
|
|
1062
1309
|
} catch {
|
|
1063
1310
|
console.log(`Installing ${packageName} on Android device...`);
|
|
1064
|
-
const { adbInstall } = await import("./android-
|
|
1311
|
+
const { adbInstall } = await import("./android-GFW6OXPQ.js");
|
|
1065
1312
|
adbInstall(device.serial, resolveFromConfig(androidAppPath));
|
|
1066
1313
|
}
|
|
1067
1314
|
}
|
|
1068
1315
|
const hostPort = allocatePort(8200);
|
|
1069
1316
|
try {
|
|
1070
1317
|
const conn = await setupUiAutomator2(device.serial, hostPort);
|
|
1071
|
-
const
|
|
1318
|
+
const driver = await Effect4.runPromise(
|
|
1072
1319
|
createUiAutomator2Driver(conn.host, conn.port, device.serial, packageName)
|
|
1073
1320
|
);
|
|
1074
|
-
const
|
|
1321
|
+
const deviceInfo = await Effect4.runPromise(driver.getDeviceInfo());
|
|
1075
1322
|
return {
|
|
1076
1323
|
runtime: {
|
|
1077
1324
|
driver,
|
|
@@ -1085,7 +1332,10 @@ async function buildLocalAndroidRuntime(config, targetDevice, resolveFromConfig)
|
|
|
1085
1332
|
deviceId: device.serial
|
|
1086
1333
|
}
|
|
1087
1334
|
},
|
|
1088
|
-
engineConfig: buildEngineConfig(packageName, "android", parseAndroidHierarchy, config
|
|
1335
|
+
engineConfig: buildEngineConfig(packageName, "android", parseAndroidHierarchy, config, {
|
|
1336
|
+
width: deviceInfo.screenWidth,
|
|
1337
|
+
height: deviceInfo.screenHeight
|
|
1338
|
+
})
|
|
1089
1339
|
};
|
|
1090
1340
|
} catch (e) {
|
|
1091
1341
|
console.log(`Android setup failed on ${device.serial}: ${e instanceof Error ? e.message : e}`);
|
|
@@ -1095,90 +1345,57 @@ async function buildLocalAndroidRuntime(config, targetDevice, resolveFromConfig)
|
|
|
1095
1345
|
async function buildLocalIOSRuntime(config, targetDevice, resolveFromConfig) {
|
|
1096
1346
|
const bundleId = config.apps?.ios?.bundleId ?? "";
|
|
1097
1347
|
const iosAppPath = config.apps?.ios?.appPath;
|
|
1098
|
-
if (targetDevice?.platform === "ios" && targetDevice.type === "simulator") {
|
|
1099
|
-
if (iosAppPath && bundleId) {
|
|
1100
|
-
ensureAppInstalled({
|
|
1101
|
-
udid: targetDevice.id,
|
|
1102
|
-
bundleId,
|
|
1103
|
-
appPath: resolveFromConfig(iosAppPath),
|
|
1104
|
-
isPhysicalDevice: false
|
|
1105
|
-
});
|
|
1106
|
-
}
|
|
1107
|
-
const wdaPort2 = allocatePort(8100);
|
|
1108
|
-
try {
|
|
1109
|
-
const conn = await setupWDA(targetDevice.id, wdaPort2);
|
|
1110
|
-
const rawDriver = await Effect4.runPromise(
|
|
1111
|
-
createWDADriver(conn.host, conn.port, bundleId, targetDevice.id)
|
|
1112
|
-
);
|
|
1113
|
-
const driver = withBufferedDriverLogs(rawDriver);
|
|
1114
|
-
return {
|
|
1115
|
-
runtime: {
|
|
1116
|
-
driver,
|
|
1117
|
-
cleanup: () => safeCleanup(
|
|
1118
|
-
() => Effect4.runPromise(driver.killApp("")),
|
|
1119
|
-
() => conn.cleanup?.() ?? Promise.resolve()
|
|
1120
|
-
),
|
|
1121
|
-
metadata: {
|
|
1122
|
-
platform: "ios",
|
|
1123
|
-
mode: "local",
|
|
1124
|
-
deviceId: targetDevice.id
|
|
1125
|
-
}
|
|
1126
|
-
},
|
|
1127
|
-
engineConfig: buildEngineConfig(bundleId, "ios", parseIOSHierarchy, config)
|
|
1128
|
-
};
|
|
1129
|
-
} catch (e) {
|
|
1130
|
-
console.log(
|
|
1131
|
-
`iOS setup failed for device ${targetDevice.id}: ${e instanceof Error ? e.message : e}`
|
|
1132
|
-
);
|
|
1133
|
-
return null;
|
|
1134
|
-
}
|
|
1135
|
-
}
|
|
1136
|
-
const physicalDevice = firstIOSPhysicalDevice();
|
|
1137
1348
|
const signing = config.apps?.ios?.signing;
|
|
1138
|
-
|
|
1349
|
+
const snapshotMaxDepth = config.defaults?.snapshotMaxDepth ?? 100;
|
|
1350
|
+
const createIOSRuntime = async (deviceId, conn, simulatorUdid) => {
|
|
1351
|
+
const driver = await Effect4.runPromise(
|
|
1352
|
+
createWDADriver(conn.host, conn.port, bundleId, simulatorUdid, snapshotMaxDepth)
|
|
1353
|
+
);
|
|
1354
|
+
const deviceInfo = await Effect4.runPromise(driver.getDeviceInfo());
|
|
1355
|
+
return {
|
|
1356
|
+
runtime: {
|
|
1357
|
+
driver,
|
|
1358
|
+
cleanup: () => safeCleanup(
|
|
1359
|
+
() => Effect4.runPromise(driver.killApp("")),
|
|
1360
|
+
() => conn.cleanup?.() ?? Promise.resolve()
|
|
1361
|
+
),
|
|
1362
|
+
metadata: {
|
|
1363
|
+
platform: "ios",
|
|
1364
|
+
mode: "local",
|
|
1365
|
+
deviceId
|
|
1366
|
+
}
|
|
1367
|
+
},
|
|
1368
|
+
engineConfig: buildEngineConfig(bundleId, "ios", parseIOSHierarchy, config, {
|
|
1369
|
+
width: deviceInfo.screenWidth,
|
|
1370
|
+
height: deviceInfo.screenHeight
|
|
1371
|
+
})
|
|
1372
|
+
};
|
|
1373
|
+
};
|
|
1374
|
+
const connectPhysicalRuntime = async (physicalDevice2, allowSimulatorFallback) => {
|
|
1139
1375
|
let conn;
|
|
1140
1376
|
try {
|
|
1141
|
-
console.log(`Found physical iOS device: ${
|
|
1377
|
+
console.log(`Found physical iOS device: ${physicalDevice2.name} (${physicalDevice2.udid})`);
|
|
1142
1378
|
if (iosAppPath && bundleId) {
|
|
1143
1379
|
ensureAppInstalled({
|
|
1144
|
-
udid:
|
|
1380
|
+
udid: physicalDevice2.udid,
|
|
1145
1381
|
bundleId,
|
|
1146
1382
|
appPath: resolveFromConfig(iosAppPath),
|
|
1147
1383
|
isPhysicalDevice: true
|
|
1148
1384
|
});
|
|
1149
1385
|
}
|
|
1150
1386
|
if (signing?.teamId) {
|
|
1151
|
-
const { setupWDAForDevice } = await import("./installer-
|
|
1387
|
+
const { setupWDAForDevice } = await import("./installer-PVBSX7UC.js");
|
|
1152
1388
|
const wdaPort2 = allocatePort(8100);
|
|
1153
1389
|
conn = await setupWDAForDevice(
|
|
1154
|
-
|
|
1390
|
+
physicalDevice2.udid,
|
|
1155
1391
|
wdaPort2,
|
|
1156
1392
|
signing.teamId,
|
|
1157
1393
|
signing.signingIdentity
|
|
1158
1394
|
);
|
|
1159
1395
|
} else {
|
|
1160
|
-
conn = connectPhysicalDevice(
|
|
1396
|
+
conn = connectPhysicalDevice(physicalDevice2.udid);
|
|
1161
1397
|
}
|
|
1162
|
-
|
|
1163
|
-
const rawDriver = await Effect4.runPromise(
|
|
1164
|
-
createWDADriver(activeConn.host, activeConn.port, bundleId)
|
|
1165
|
-
);
|
|
1166
|
-
const driver = withBufferedDriverLogs(rawDriver);
|
|
1167
|
-
return {
|
|
1168
|
-
runtime: {
|
|
1169
|
-
driver,
|
|
1170
|
-
cleanup: () => safeCleanup(
|
|
1171
|
-
() => Effect4.runPromise(driver.killApp("")),
|
|
1172
|
-
() => activeConn.cleanup?.() ?? Promise.resolve()
|
|
1173
|
-
),
|
|
1174
|
-
metadata: {
|
|
1175
|
-
platform: "ios",
|
|
1176
|
-
mode: "local",
|
|
1177
|
-
deviceId: physicalDevice.udid
|
|
1178
|
-
}
|
|
1179
|
-
},
|
|
1180
|
-
engineConfig: buildEngineConfig(bundleId, "ios", parseIOSHierarchy, config)
|
|
1181
|
-
};
|
|
1398
|
+
return await createIOSRuntime(physicalDevice2.udid, conn);
|
|
1182
1399
|
} catch (e) {
|
|
1183
1400
|
if (conn?.cleanup) {
|
|
1184
1401
|
try {
|
|
@@ -1189,9 +1406,46 @@ async function buildLocalIOSRuntime(config, targetDevice, resolveFromConfig) {
|
|
|
1189
1406
|
);
|
|
1190
1407
|
}
|
|
1191
1408
|
}
|
|
1409
|
+
if (!allowSimulatorFallback) {
|
|
1410
|
+
console.log(
|
|
1411
|
+
`iOS setup failed for device ${physicalDevice2.udid}: ${e instanceof Error ? e.message : e}`
|
|
1412
|
+
);
|
|
1413
|
+
return null;
|
|
1414
|
+
}
|
|
1415
|
+
console.log(
|
|
1416
|
+
`Physical device setup failed (${physicalDevice2.name}): ${e instanceof Error ? e.message : e}. Falling back to simulator.`
|
|
1417
|
+
);
|
|
1418
|
+
return null;
|
|
1419
|
+
}
|
|
1420
|
+
};
|
|
1421
|
+
if (targetDevice?.platform === "ios" && targetDevice.type === "simulator") {
|
|
1422
|
+
if (iosAppPath && bundleId) {
|
|
1423
|
+
ensureAppInstalled({
|
|
1424
|
+
udid: targetDevice.id,
|
|
1425
|
+
bundleId,
|
|
1426
|
+
appPath: resolveFromConfig(iosAppPath),
|
|
1427
|
+
isPhysicalDevice: false
|
|
1428
|
+
});
|
|
1429
|
+
}
|
|
1430
|
+
const wdaPort2 = allocatePort(8100);
|
|
1431
|
+
try {
|
|
1432
|
+
const conn = await setupWDA(targetDevice.id, wdaPort2);
|
|
1433
|
+
return await createIOSRuntime(targetDevice.id, conn, targetDevice.id);
|
|
1434
|
+
} catch (e) {
|
|
1192
1435
|
console.log(
|
|
1193
|
-
`
|
|
1436
|
+
`iOS setup failed for device ${targetDevice.id}: ${e instanceof Error ? e.message : e}`
|
|
1194
1437
|
);
|
|
1438
|
+
return null;
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
if (targetDevice?.platform === "ios" && targetDevice.type === "device") {
|
|
1442
|
+
return connectPhysicalRuntime({ udid: targetDevice.id, name: targetDevice.name }, false);
|
|
1443
|
+
}
|
|
1444
|
+
const physicalDevice = firstIOSPhysicalDevice();
|
|
1445
|
+
if (physicalDevice) {
|
|
1446
|
+
const runtime = await connectPhysicalRuntime(physicalDevice, true);
|
|
1447
|
+
if (runtime) {
|
|
1448
|
+
return runtime;
|
|
1195
1449
|
}
|
|
1196
1450
|
}
|
|
1197
1451
|
const simulator = ensureIOSSimulator(bundleId);
|
|
@@ -1210,25 +1464,7 @@ async function buildLocalIOSRuntime(config, targetDevice, resolveFromConfig) {
|
|
|
1210
1464
|
const wdaPort = allocatePort(8100);
|
|
1211
1465
|
try {
|
|
1212
1466
|
const conn = await setupWDA(simulator.udid, wdaPort);
|
|
1213
|
-
|
|
1214
|
-
createWDADriver(conn.host, conn.port, bundleId, simulator.udid)
|
|
1215
|
-
);
|
|
1216
|
-
const driver = withBufferedDriverLogs(rawDriver);
|
|
1217
|
-
return {
|
|
1218
|
-
runtime: {
|
|
1219
|
-
driver,
|
|
1220
|
-
cleanup: () => safeCleanup(
|
|
1221
|
-
() => Effect4.runPromise(driver.killApp("")),
|
|
1222
|
-
() => conn.cleanup?.() ?? Promise.resolve()
|
|
1223
|
-
),
|
|
1224
|
-
metadata: {
|
|
1225
|
-
platform: "ios",
|
|
1226
|
-
mode: "local",
|
|
1227
|
-
deviceId: simulator.udid
|
|
1228
|
-
}
|
|
1229
|
-
},
|
|
1230
|
-
engineConfig: buildEngineConfig(bundleId, "ios", parseIOSHierarchy, config)
|
|
1231
|
-
};
|
|
1467
|
+
return await createIOSRuntime(simulator.udid, conn, simulator.udid);
|
|
1232
1468
|
} catch (e) {
|
|
1233
1469
|
console.log(`iOS setup failed on ${simulator.name}: ${e instanceof Error ? e.message : e}`);
|
|
1234
1470
|
return null;
|
|
@@ -1241,10 +1477,25 @@ import { Effect as Effect7 } from "effect";
|
|
|
1241
1477
|
// src/drivers/appium/client.ts
|
|
1242
1478
|
var AppiumClient = class {
|
|
1243
1479
|
baseUrl;
|
|
1480
|
+
authHeader = null;
|
|
1244
1481
|
sessionId = null;
|
|
1245
1482
|
sessionCaps = {};
|
|
1246
1483
|
constructor(serverUrl) {
|
|
1247
|
-
|
|
1484
|
+
const parsed = new URL(serverUrl);
|
|
1485
|
+
if (parsed.username || parsed.password) {
|
|
1486
|
+
const username = decodeURIComponent(parsed.username);
|
|
1487
|
+
const password = decodeURIComponent(parsed.password);
|
|
1488
|
+
this.authHeader = `Basic ${Buffer.from(`${username}:${password}`).toString("base64")}`;
|
|
1489
|
+
parsed.username = "";
|
|
1490
|
+
parsed.password = "";
|
|
1491
|
+
}
|
|
1492
|
+
this.baseUrl = parsed.toString().replace(/\/+$/, "");
|
|
1493
|
+
}
|
|
1494
|
+
createHeaders() {
|
|
1495
|
+
return {
|
|
1496
|
+
"Content-Type": "application/json",
|
|
1497
|
+
...this.authHeader ? { Authorization: this.authHeader } : {}
|
|
1498
|
+
};
|
|
1248
1499
|
}
|
|
1249
1500
|
// ---------------------------------------------------------------------------
|
|
1250
1501
|
// HTTP helpers
|
|
@@ -1253,7 +1504,7 @@ var AppiumClient = class {
|
|
|
1253
1504
|
const url = `${this.baseUrl}${path}`;
|
|
1254
1505
|
const init = {
|
|
1255
1506
|
method,
|
|
1256
|
-
headers:
|
|
1507
|
+
headers: this.createHeaders()
|
|
1257
1508
|
};
|
|
1258
1509
|
if (body !== void 0) {
|
|
1259
1510
|
init.body = JSON.stringify(body);
|
|
@@ -1294,7 +1545,7 @@ var AppiumClient = class {
|
|
|
1294
1545
|
};
|
|
1295
1546
|
const res = await fetch(`${this.baseUrl}/session`, {
|
|
1296
1547
|
method: "POST",
|
|
1297
|
-
headers:
|
|
1548
|
+
headers: this.createHeaders(),
|
|
1298
1549
|
body: JSON.stringify(body)
|
|
1299
1550
|
});
|
|
1300
1551
|
const text = await res.text();
|
|
@@ -1311,7 +1562,7 @@ var AppiumClient = class {
|
|
|
1311
1562
|
const value = parsed["value"];
|
|
1312
1563
|
const sessionId = value?.["sessionId"] ?? parsed["sessionId"];
|
|
1313
1564
|
if (!sessionId) {
|
|
1314
|
-
throw new Error(
|
|
1565
|
+
throw new Error(`Appium: no sessionId in session response: ${text}`);
|
|
1315
1566
|
}
|
|
1316
1567
|
this.sessionId = sessionId;
|
|
1317
1568
|
this.sessionCaps = value?.["capabilities"] ?? {};
|
|
@@ -1322,7 +1573,7 @@ var AppiumClient = class {
|
|
|
1322
1573
|
const path = `/session/${this.sessionId}`;
|
|
1323
1574
|
this.sessionId = null;
|
|
1324
1575
|
this.sessionCaps = {};
|
|
1325
|
-
await fetch(`${this.baseUrl}${path}`, { method: "DELETE" });
|
|
1576
|
+
await fetch(`${this.baseUrl}${path}`, { method: "DELETE", headers: this.createHeaders() });
|
|
1326
1577
|
}
|
|
1327
1578
|
getSessionId() {
|
|
1328
1579
|
return this.sessionId;
|
|
@@ -1352,7 +1603,23 @@ var AppiumClient = class {
|
|
|
1352
1603
|
|
|
1353
1604
|
// src/drivers/appium/android.ts
|
|
1354
1605
|
import { Effect as Effect5 } from "effect";
|
|
1355
|
-
|
|
1606
|
+
|
|
1607
|
+
// src/drivers/appium/window-size.ts
|
|
1608
|
+
async function getAppiumWindowSize(client) {
|
|
1609
|
+
try {
|
|
1610
|
+
return await client.request("GET", client.sessionPath("/window/size"));
|
|
1611
|
+
} catch (error) {
|
|
1612
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1613
|
+
if (!message.includes("/window/size") || !message.includes("-> 404:")) {
|
|
1614
|
+
throw error;
|
|
1615
|
+
}
|
|
1616
|
+
const rect = await client.request("GET", client.sessionPath("/window/rect"));
|
|
1617
|
+
return { width: rect.width, height: rect.height };
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1621
|
+
// src/drivers/appium/android.ts
|
|
1622
|
+
function createAppiumAndroidDriver(client, defaultBundleId) {
|
|
1356
1623
|
const service = {
|
|
1357
1624
|
// -----------------------------------------------------------------------
|
|
1358
1625
|
// Hierarchy
|
|
@@ -1365,21 +1632,57 @@ function createAppiumAndroidDriver(client) {
|
|
|
1365
1632
|
// Coordinate-level actions
|
|
1366
1633
|
// -----------------------------------------------------------------------
|
|
1367
1634
|
tapAtCoordinate: (x, y) => Effect5.tryPromise({
|
|
1368
|
-
try: () => client.request("POST", client.sessionPath("/
|
|
1369
|
-
|
|
1635
|
+
try: () => client.request("POST", client.sessionPath("/actions"), {
|
|
1636
|
+
actions: [
|
|
1637
|
+
{
|
|
1638
|
+
type: "pointer",
|
|
1639
|
+
id: "finger1",
|
|
1640
|
+
parameters: { pointerType: "touch" },
|
|
1641
|
+
actions: [
|
|
1642
|
+
{ type: "pointerMove", duration: 0, x, y },
|
|
1643
|
+
{ type: "pointerDown", button: 0 },
|
|
1644
|
+
{ type: "pointerUp", button: 0 }
|
|
1645
|
+
]
|
|
1646
|
+
}
|
|
1647
|
+
]
|
|
1370
1648
|
}),
|
|
1371
1649
|
catch: (e) => new DriverError({ message: `Tap failed: ${e}` })
|
|
1372
1650
|
}),
|
|
1373
1651
|
doubleTapAtCoordinate: (x, y) => Effect5.tryPromise({
|
|
1374
|
-
try: () =>
|
|
1375
|
-
|
|
1376
|
-
|
|
1652
|
+
try: async () => {
|
|
1653
|
+
const tapSequence = [
|
|
1654
|
+
{
|
|
1655
|
+
type: "pointer",
|
|
1656
|
+
id: "finger1",
|
|
1657
|
+
parameters: { pointerType: "touch" },
|
|
1658
|
+
actions: [
|
|
1659
|
+
{ type: "pointerMove", duration: 0, x, y },
|
|
1660
|
+
{ type: "pointerDown", button: 0 },
|
|
1661
|
+
{ type: "pointerUp", button: 0 }
|
|
1662
|
+
]
|
|
1663
|
+
}
|
|
1664
|
+
];
|
|
1665
|
+
await client.request("POST", client.sessionPath("/actions"), { actions: tapSequence });
|
|
1666
|
+
await new Promise((resolve4) => setTimeout(resolve4, 100));
|
|
1667
|
+
await client.request("POST", client.sessionPath("/actions"), { actions: tapSequence });
|
|
1668
|
+
},
|
|
1377
1669
|
catch: (e) => new DriverError({ message: `Double tap failed: ${e}` })
|
|
1378
1670
|
}),
|
|
1379
1671
|
longPressAtCoordinate: (x, y, duration) => Effect5.tryPromise({
|
|
1380
|
-
try: () => client.request("POST", client.sessionPath("/
|
|
1381
|
-
|
|
1382
|
-
|
|
1672
|
+
try: () => client.request("POST", client.sessionPath("/actions"), {
|
|
1673
|
+
actions: [
|
|
1674
|
+
{
|
|
1675
|
+
type: "pointer",
|
|
1676
|
+
id: "finger1",
|
|
1677
|
+
parameters: { pointerType: "touch" },
|
|
1678
|
+
actions: [
|
|
1679
|
+
{ type: "pointerMove", duration: 0, x, y },
|
|
1680
|
+
{ type: "pointerDown", button: 0 },
|
|
1681
|
+
{ type: "pause", duration },
|
|
1682
|
+
{ type: "pointerUp", button: 0 }
|
|
1683
|
+
]
|
|
1684
|
+
}
|
|
1685
|
+
]
|
|
1383
1686
|
}),
|
|
1384
1687
|
catch: (e) => new DriverError({ message: `Long press failed: ${e}` })
|
|
1385
1688
|
}),
|
|
@@ -1445,10 +1748,7 @@ function createAppiumAndroidDriver(client) {
|
|
|
1445
1748
|
}),
|
|
1446
1749
|
getDeviceInfo: () => Effect5.tryPromise({
|
|
1447
1750
|
try: async () => {
|
|
1448
|
-
const size = await client
|
|
1449
|
-
"GET",
|
|
1450
|
-
client.sessionPath("/window/size")
|
|
1451
|
-
);
|
|
1751
|
+
const size = await getAppiumWindowSize(client);
|
|
1452
1752
|
const caps = client.getSessionCaps();
|
|
1453
1753
|
return {
|
|
1454
1754
|
platform: "android",
|
|
@@ -1474,16 +1774,7 @@ function createAppiumAndroidDriver(client) {
|
|
|
1474
1774
|
});
|
|
1475
1775
|
} catch {
|
|
1476
1776
|
}
|
|
1477
|
-
await client.
|
|
1478
|
-
appId: bundleId
|
|
1479
|
-
});
|
|
1480
|
-
await client.request("POST", client.sessionPath("/appium/device/activate_app"), {
|
|
1481
|
-
appId: bundleId
|
|
1482
|
-
});
|
|
1483
|
-
} else {
|
|
1484
|
-
await client.request("POST", client.sessionPath("/appium/device/activate_app"), {
|
|
1485
|
-
appId: bundleId
|
|
1486
|
-
});
|
|
1777
|
+
await client.executeScript("mobile: clearApp", [{ appId: bundleId }]);
|
|
1487
1778
|
}
|
|
1488
1779
|
if (opts?.clearKeychain) {
|
|
1489
1780
|
console.warn("clearKeychain is not supported on Android, skipping.");
|
|
@@ -1493,9 +1784,18 @@ function createAppiumAndroidDriver(client) {
|
|
|
1493
1784
|
message: "launchArguments are not supported in Appium Android mode. Remove launchArguments from your config or use local mode."
|
|
1494
1785
|
});
|
|
1495
1786
|
}
|
|
1787
|
+
if (hasLaunchDeviceState(opts?.deviceState)) {
|
|
1788
|
+
console.warn(
|
|
1789
|
+
"deviceState launch overrides are not supported during Appium Android relaunches. Set launchOptions.deviceState in config to apply Android language/locale/timeZone at session start."
|
|
1790
|
+
);
|
|
1791
|
+
}
|
|
1496
1792
|
if (opts?.deepLink) {
|
|
1497
|
-
await client.
|
|
1498
|
-
url: opts.deepLink
|
|
1793
|
+
await client.executeScript("mobile: deepLink", [
|
|
1794
|
+
{ url: opts.deepLink, package: bundleId }
|
|
1795
|
+
]);
|
|
1796
|
+
} else {
|
|
1797
|
+
await client.request("POST", client.sessionPath("/appium/device/activate_app"), {
|
|
1798
|
+
appId: bundleId
|
|
1499
1799
|
});
|
|
1500
1800
|
}
|
|
1501
1801
|
},
|
|
@@ -1521,9 +1821,7 @@ function createAppiumAndroidDriver(client) {
|
|
|
1521
1821
|
});
|
|
1522
1822
|
} catch {
|
|
1523
1823
|
}
|
|
1524
|
-
await client.
|
|
1525
|
-
appId: bundleId
|
|
1526
|
-
});
|
|
1824
|
+
await client.executeScript("mobile: clearApp", [{ appId: bundleId }]);
|
|
1527
1825
|
},
|
|
1528
1826
|
catch: (e) => new DriverError({ message: `Clear app state failed: ${e}` })
|
|
1529
1827
|
}),
|
|
@@ -1531,7 +1829,11 @@ function createAppiumAndroidDriver(client) {
|
|
|
1531
1829
|
// Navigation
|
|
1532
1830
|
// -----------------------------------------------------------------------
|
|
1533
1831
|
openLink: (url) => Effect5.tryPromise({
|
|
1534
|
-
try: () =>
|
|
1832
|
+
try: () => {
|
|
1833
|
+
const args = { url };
|
|
1834
|
+
if (defaultBundleId) args.package = defaultBundleId;
|
|
1835
|
+
return client.executeScript("mobile: deepLink", [args]);
|
|
1836
|
+
},
|
|
1535
1837
|
catch: (e) => new DriverError({ message: `Open link failed: ${e}` })
|
|
1536
1838
|
}),
|
|
1537
1839
|
back: () => Effect5.tryPromise({
|
|
@@ -1562,6 +1864,29 @@ function createAppiumAndroidDriver(client) {
|
|
|
1562
1864
|
setContext: (contextId) => Effect5.tryPromise({
|
|
1563
1865
|
try: () => client.setContext(contextId),
|
|
1564
1866
|
catch: (e) => new DriverError({ message: `setContext failed: ${e}` })
|
|
1867
|
+
}),
|
|
1868
|
+
// -----------------------------------------------------------------------
|
|
1869
|
+
// Network conditions
|
|
1870
|
+
// -----------------------------------------------------------------------
|
|
1871
|
+
setNetworkConditions: (conditions) => Effect5.tryPromise({
|
|
1872
|
+
try: () => {
|
|
1873
|
+
const resolved = resolveNetworkConditions(conditions);
|
|
1874
|
+
const hasAnyValue = conditions.profile !== void 0 || conditions.offline !== void 0 || conditions.latencyMs !== void 0 || conditions.downloadThroughputKbps !== void 0 || conditions.uploadThroughputKbps !== void 0;
|
|
1875
|
+
if (!hasAnyValue) {
|
|
1876
|
+
return client.executeScript("mobile: setConnectivity", [
|
|
1877
|
+
{ wifi: true, data: true, airplaneMode: false }
|
|
1878
|
+
]);
|
|
1879
|
+
}
|
|
1880
|
+
if (resolved.offline) {
|
|
1881
|
+
return client.executeScript("mobile: setConnectivity", [
|
|
1882
|
+
{ wifi: false, data: false, airplaneMode: true }
|
|
1883
|
+
]);
|
|
1884
|
+
}
|
|
1885
|
+
return client.executeScript("mobile: setConnectivity", [
|
|
1886
|
+
{ wifi: true, data: true, airplaneMode: false }
|
|
1887
|
+
]);
|
|
1888
|
+
},
|
|
1889
|
+
catch: (e) => new DriverError({ message: `setNetworkConditions failed: ${e}` })
|
|
1565
1890
|
})
|
|
1566
1891
|
};
|
|
1567
1892
|
return Effect5.succeed(service);
|
|
@@ -1707,10 +2032,7 @@ function createAppiumIOSDriver(client) {
|
|
|
1707
2032
|
}),
|
|
1708
2033
|
getDeviceInfo: () => Effect6.tryPromise({
|
|
1709
2034
|
try: async () => {
|
|
1710
|
-
const size = await client
|
|
1711
|
-
"GET",
|
|
1712
|
-
client.sessionPath("/window/size")
|
|
1713
|
-
);
|
|
2035
|
+
const size = await getAppiumWindowSize(client);
|
|
1714
2036
|
const caps = client.getSessionCaps();
|
|
1715
2037
|
return {
|
|
1716
2038
|
platform: "ios",
|
|
@@ -1729,6 +2051,7 @@ function createAppiumIOSDriver(client) {
|
|
|
1729
2051
|
// -----------------------------------------------------------------------
|
|
1730
2052
|
launchApp: (bundleId, opts) => Effect6.tryPromise({
|
|
1731
2053
|
try: async () => {
|
|
2054
|
+
const launchConfig = buildIOSLaunchConfiguration(opts);
|
|
1732
2055
|
if (opts?.clearState) {
|
|
1733
2056
|
try {
|
|
1734
2057
|
await client.request("POST", client.sessionPath("/appium/device/terminate_app"), {
|
|
@@ -1736,13 +2059,15 @@ function createAppiumIOSDriver(client) {
|
|
|
1736
2059
|
});
|
|
1737
2060
|
} catch {
|
|
1738
2061
|
}
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
})
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
2062
|
+
try {
|
|
2063
|
+
await client.executeScript("mobile: clearApp", [{ bundleId }]);
|
|
2064
|
+
} catch (e) {
|
|
2065
|
+
console.warn(
|
|
2066
|
+
`mobile: clearApp unavailable on this provider; falling back to terminate-only. In-memory state will still be reset. (${e})`
|
|
2067
|
+
);
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2070
|
+
if (!launchConfig) {
|
|
1746
2071
|
await client.request("POST", client.sessionPath("/appium/device/activate_app"), {
|
|
1747
2072
|
appId: bundleId
|
|
1748
2073
|
});
|
|
@@ -1752,10 +2077,20 @@ function createAppiumIOSDriver(client) {
|
|
|
1752
2077
|
"clearKeychain is not available via Appium on iOS. Use local mode with xcrun simctl for keychain operations."
|
|
1753
2078
|
);
|
|
1754
2079
|
}
|
|
1755
|
-
if (
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
2080
|
+
if (launchConfig) {
|
|
2081
|
+
try {
|
|
2082
|
+
await client.request("POST", client.sessionPath("/appium/device/terminate_app"), {
|
|
2083
|
+
appId: bundleId
|
|
2084
|
+
});
|
|
2085
|
+
} catch {
|
|
2086
|
+
}
|
|
2087
|
+
await client.executeScript("mobile: launchApp", [
|
|
2088
|
+
{
|
|
2089
|
+
bundleId,
|
|
2090
|
+
arguments: launchConfig.arguments,
|
|
2091
|
+
environment: launchConfig.environment
|
|
2092
|
+
}
|
|
2093
|
+
]);
|
|
1759
2094
|
}
|
|
1760
2095
|
if (opts?.deepLink) {
|
|
1761
2096
|
await client.request("POST", client.sessionPath("/url"), {
|
|
@@ -1785,9 +2120,7 @@ function createAppiumIOSDriver(client) {
|
|
|
1785
2120
|
});
|
|
1786
2121
|
} catch {
|
|
1787
2122
|
}
|
|
1788
|
-
await client.
|
|
1789
|
-
appId: bundleId
|
|
1790
|
-
});
|
|
2123
|
+
await client.executeScript("mobile: clearApp", [{ bundleId }]);
|
|
1791
2124
|
},
|
|
1792
2125
|
catch: (e) => new DriverError({
|
|
1793
2126
|
message: `Clear app state failed: ${e}. Note: clearApp may not be available on all iOS Appium providers. If this persists, consider using terminate + uninstall + install instead.`
|
|
@@ -1829,6 +2162,29 @@ function createAppiumIOSDriver(client) {
|
|
|
1829
2162
|
setContext: (contextId) => Effect6.tryPromise({
|
|
1830
2163
|
try: () => client.setContext(contextId),
|
|
1831
2164
|
catch: (e) => new DriverError({ message: `setContext failed: ${e}` })
|
|
2165
|
+
}),
|
|
2166
|
+
// -----------------------------------------------------------------------
|
|
2167
|
+
// Network conditions
|
|
2168
|
+
// -----------------------------------------------------------------------
|
|
2169
|
+
setNetworkConditions: (conditions) => Effect6.tryPromise({
|
|
2170
|
+
try: () => {
|
|
2171
|
+
const resolved = resolveNetworkConditions(conditions);
|
|
2172
|
+
const hasAnyValue = conditions.profile !== void 0 || conditions.offline !== void 0 || conditions.latencyMs !== void 0 || conditions.downloadThroughputKbps !== void 0 || conditions.uploadThroughputKbps !== void 0;
|
|
2173
|
+
if (!hasAnyValue) {
|
|
2174
|
+
return client.executeScript("mobile: setConnectivity", [
|
|
2175
|
+
{ wifi: true, data: true, airplaneMode: false }
|
|
2176
|
+
]);
|
|
2177
|
+
}
|
|
2178
|
+
if (resolved.offline) {
|
|
2179
|
+
return client.executeScript("mobile: setConnectivity", [
|
|
2180
|
+
{ wifi: false, data: false, airplaneMode: true }
|
|
2181
|
+
]);
|
|
2182
|
+
}
|
|
2183
|
+
return client.executeScript("mobile: setConnectivity", [
|
|
2184
|
+
{ wifi: true, data: true, airplaneMode: false }
|
|
2185
|
+
]);
|
|
2186
|
+
},
|
|
2187
|
+
catch: (e) => new DriverError({ message: `setNetworkConditions failed: ${e}` })
|
|
1832
2188
|
})
|
|
1833
2189
|
};
|
|
1834
2190
|
return Effect6.succeed(service);
|
|
@@ -1836,13 +2192,14 @@ function createAppiumIOSDriver(client) {
|
|
|
1836
2192
|
|
|
1837
2193
|
// src/runtime/appium.ts
|
|
1838
2194
|
async function buildAppiumAndroidRuntime(config, appiumUrl, caps) {
|
|
2195
|
+
const appId = caps["appium:appPackage"] ?? config.apps?.android?.packageName ?? "";
|
|
1839
2196
|
const client = new AppiumClient(appiumUrl);
|
|
1840
2197
|
await client.createSession({
|
|
1841
2198
|
platformName: "Android",
|
|
1842
2199
|
...caps
|
|
1843
2200
|
});
|
|
1844
|
-
const
|
|
1845
|
-
const
|
|
2201
|
+
const driver = await Effect7.runPromise(createAppiumAndroidDriver(client, appId || void 0));
|
|
2202
|
+
const deviceInfo = await Effect7.runPromise(driver.getDeviceInfo());
|
|
1846
2203
|
const sessionId = client.getSessionId() ?? void 0;
|
|
1847
2204
|
const sessionCaps = client.getSessionCaps();
|
|
1848
2205
|
const detectedProvider = detectProvider(appiumUrl);
|
|
@@ -1865,35 +2222,50 @@ async function buildAppiumAndroidRuntime(config, appiumUrl, caps) {
|
|
|
1865
2222
|
}
|
|
1866
2223
|
},
|
|
1867
2224
|
engineConfig: {
|
|
1868
|
-
appId
|
|
2225
|
+
appId,
|
|
1869
2226
|
platform: "android",
|
|
1870
2227
|
coordinatorConfig: {
|
|
1871
2228
|
parse: parseAndroidHierarchy,
|
|
1872
2229
|
defaults: {
|
|
1873
2230
|
timeout: config.defaults?.waitTimeout,
|
|
1874
|
-
pollInterval: config.defaults?.pollInterval
|
|
2231
|
+
pollInterval: config.defaults?.pollInterval,
|
|
2232
|
+
settleTimeout: config.defaults?.settleTimeout,
|
|
2233
|
+
initialPollInterval: config.defaults?.initialPollInterval
|
|
1875
2234
|
},
|
|
1876
2235
|
waitForIdleTimeout: config.defaults?.waitForIdleTimeout,
|
|
1877
|
-
typingDelay: config.defaults?.typingDelay
|
|
2236
|
+
typingDelay: config.defaults?.typingDelay,
|
|
2237
|
+
hierarchyCacheTtl: config.defaults?.hierarchyCacheTtl,
|
|
2238
|
+
screenWidth: deviceInfo.screenWidth,
|
|
2239
|
+
screenHeight: deviceInfo.screenHeight
|
|
1878
2240
|
},
|
|
1879
2241
|
autoLaunch: false,
|
|
1880
2242
|
// Appium manages app lifecycle
|
|
1881
2243
|
flowTimeout: config.defaults?.waitTimeout ? config.defaults.waitTimeout * 10 : 6e4,
|
|
1882
2244
|
artifactConfig: config.artifacts,
|
|
1883
2245
|
launchOptions: config.launchOptions,
|
|
1884
|
-
hooks: config.hooks
|
|
2246
|
+
hooks: config.hooks,
|
|
2247
|
+
visualRegression: config.visualRegression
|
|
1885
2248
|
}
|
|
1886
2249
|
};
|
|
1887
2250
|
}
|
|
1888
2251
|
async function buildAppiumIOSRuntime(config, appiumUrl, caps) {
|
|
2252
|
+
const appId = caps["appium:bundleId"] ?? config.apps?.ios?.bundleId ?? "";
|
|
1889
2253
|
const client = new AppiumClient(appiumUrl);
|
|
1890
2254
|
await client.createSession({
|
|
1891
2255
|
platformName: "iOS",
|
|
1892
2256
|
"appium:automationName": "XCUITest",
|
|
1893
2257
|
...caps
|
|
1894
2258
|
});
|
|
1895
|
-
const
|
|
1896
|
-
|
|
2259
|
+
const snapshotMaxDepth = config.defaults?.snapshotMaxDepth ?? 100;
|
|
2260
|
+
try {
|
|
2261
|
+
await client.request("POST", client.sessionPath("/appium/settings"), {
|
|
2262
|
+
settings: { snapshotMaxDepth }
|
|
2263
|
+
});
|
|
2264
|
+
} catch (e) {
|
|
2265
|
+
console.warn(`Failed to set snapshotMaxDepth (continuing): ${e}`);
|
|
2266
|
+
}
|
|
2267
|
+
const driver = await Effect7.runPromise(createAppiumIOSDriver(client));
|
|
2268
|
+
const deviceInfo = await Effect7.runPromise(driver.getDeviceInfo());
|
|
1897
2269
|
const sessionId = client.getSessionId() ?? void 0;
|
|
1898
2270
|
const sessionCaps = client.getSessionCaps();
|
|
1899
2271
|
const detectedProvider = detectProvider(appiumUrl);
|
|
@@ -1916,250 +2288,178 @@ async function buildAppiumIOSRuntime(config, appiumUrl, caps) {
|
|
|
1916
2288
|
}
|
|
1917
2289
|
},
|
|
1918
2290
|
engineConfig: {
|
|
1919
|
-
appId
|
|
2291
|
+
appId,
|
|
1920
2292
|
platform: "ios",
|
|
1921
2293
|
coordinatorConfig: {
|
|
1922
2294
|
parse: parseIOSHierarchy,
|
|
1923
2295
|
defaults: {
|
|
1924
2296
|
timeout: config.defaults?.waitTimeout,
|
|
1925
|
-
pollInterval: config.defaults?.pollInterval
|
|
2297
|
+
pollInterval: config.defaults?.pollInterval,
|
|
2298
|
+
settleTimeout: config.defaults?.settleTimeout,
|
|
2299
|
+
initialPollInterval: config.defaults?.initialPollInterval
|
|
1926
2300
|
},
|
|
1927
2301
|
waitForIdleTimeout: config.defaults?.waitForIdleTimeout,
|
|
1928
|
-
typingDelay: config.defaults?.typingDelay
|
|
2302
|
+
typingDelay: config.defaults?.typingDelay,
|
|
2303
|
+
hierarchyCacheTtl: config.defaults?.hierarchyCacheTtl,
|
|
2304
|
+
screenWidth: deviceInfo.screenWidth,
|
|
2305
|
+
screenHeight: deviceInfo.screenHeight
|
|
1929
2306
|
},
|
|
1930
2307
|
autoLaunch: false,
|
|
1931
2308
|
// Appium manages app lifecycle
|
|
1932
2309
|
flowTimeout: config.defaults?.waitTimeout ? config.defaults.waitTimeout * 10 : 6e4,
|
|
1933
2310
|
artifactConfig: config.artifacts,
|
|
1934
2311
|
launchOptions: config.launchOptions,
|
|
1935
|
-
hooks: config.hooks
|
|
2312
|
+
hooks: config.hooks,
|
|
2313
|
+
visualRegression: config.visualRegression
|
|
1936
2314
|
}
|
|
1937
2315
|
};
|
|
1938
2316
|
}
|
|
1939
2317
|
|
|
1940
2318
|
// src/cli/iteration.ts
|
|
1941
2319
|
import { execFileSync } from "child_process";
|
|
1942
|
-
import {
|
|
1943
|
-
import { dirname, join as
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
return join2(outputDir, ".spana", "last-run.json");
|
|
1947
|
-
}
|
|
2320
|
+
import { readFile as readFile2, writeFile } from "fs/promises";
|
|
2321
|
+
import { dirname, join as join4, resolve } from "path";
|
|
2322
|
+
import { mkdirSync as mkdirSync2, existsSync as existsSync2 } from "fs";
|
|
2323
|
+
var SCHEMA_VERSION = 1;
|
|
1948
2324
|
function buildLastRunState(options) {
|
|
1949
|
-
const
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
2325
|
+
const { flowDir, platforms, results, sourcePathsByFlowName } = options;
|
|
2326
|
+
const failedFlowNames = [];
|
|
2327
|
+
const failedSourcePaths = [];
|
|
2328
|
+
const flows = [];
|
|
2329
|
+
for (const result of results) {
|
|
2330
|
+
const passed = result.status === "passed";
|
|
2331
|
+
const sourcePath = sourcePathsByFlowName.get(result.name);
|
|
2332
|
+
flows.push({ name: result.name, platform: result.platform, passed, sourcePath });
|
|
2333
|
+
if (!passed) {
|
|
2334
|
+
if (!failedFlowNames.includes(result.name)) failedFlowNames.push(result.name);
|
|
2335
|
+
if (sourcePath && !failedSourcePaths.includes(sourcePath)) failedSourcePaths.push(sourcePath);
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
1961
2338
|
return {
|
|
1962
|
-
schemaVersion:
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
platforms: [...new Set(options.platforms)],
|
|
2339
|
+
schemaVersion: SCHEMA_VERSION,
|
|
2340
|
+
flowDir,
|
|
2341
|
+
platforms,
|
|
1966
2342
|
failedFlowNames,
|
|
1967
2343
|
failedSourcePaths,
|
|
1968
2344
|
flows
|
|
1969
2345
|
};
|
|
1970
2346
|
}
|
|
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
2347
|
async function readLastRunState(filePath) {
|
|
2001
2348
|
try {
|
|
2002
|
-
const raw = await
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
throw error;
|
|
2349
|
+
const raw = await readFile2(filePath, "utf8");
|
|
2350
|
+
const parsed = JSON.parse(raw);
|
|
2351
|
+
if (parsed.schemaVersion !== SCHEMA_VERSION) return null;
|
|
2352
|
+
return parsed;
|
|
2353
|
+
} catch {
|
|
2354
|
+
return null;
|
|
2009
2355
|
}
|
|
2010
2356
|
}
|
|
2011
2357
|
async function writeLastRunState(filePath, state) {
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2358
|
+
const dir = dirname(filePath);
|
|
2359
|
+
if (!existsSync2(dir)) mkdirSync2(dir, { recursive: true });
|
|
2360
|
+
await writeFile(filePath, JSON.stringify(state, null, 2), "utf8");
|
|
2015
2361
|
}
|
|
2016
|
-
function
|
|
2017
|
-
|
|
2362
|
+
function getGitChangedFiles(cwd) {
|
|
2363
|
+
const tracked = execFileSync("git", ["diff", "--name-only"], { cwd, encoding: "utf8" });
|
|
2364
|
+
const untracked = execFileSync("git", ["ls-files", "--others", "--exclude-standard"], {
|
|
2365
|
+
cwd,
|
|
2366
|
+
encoding: "utf8"
|
|
2367
|
+
});
|
|
2368
|
+
return [...parseGitPathList(cwd, tracked), ...parseGitPathList(cwd, untracked)];
|
|
2018
2369
|
}
|
|
2019
|
-
function
|
|
2020
|
-
|
|
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
|
-
}
|
|
2370
|
+
function parseGitPathList(cwd, output) {
|
|
2371
|
+
return output.split("\n").map((line) => line.trim()).filter((line) => line.length > 0).map((line) => resolve(cwd, line));
|
|
2037
2372
|
}
|
|
2038
2373
|
function selectChangedFlowPaths(options) {
|
|
2039
|
-
const flowPaths = options
|
|
2040
|
-
const
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
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) {
|
|
2374
|
+
const { flowPaths, changedFiles, stepPaths, configPath } = options;
|
|
2375
|
+
const changedSet = new Set(changedFiles);
|
|
2376
|
+
if (configPath && changedSet.has(resolve(configPath))) {
|
|
2377
|
+
return { mode: "all", reason: "Config changed \u2014 running all flows.", flowPaths };
|
|
2378
|
+
}
|
|
2379
|
+
const stepChanged = stepPaths.some((s) => changedSet.has(s));
|
|
2380
|
+
if (stepChanged) {
|
|
2381
|
+
const featureFlows = flowPaths.filter((p) => p.endsWith(".feature"));
|
|
2382
|
+
if (featureFlows.length > 0) {
|
|
2062
2383
|
return {
|
|
2063
2384
|
mode: "targeted",
|
|
2064
|
-
reason:
|
|
2065
|
-
flowPaths:
|
|
2385
|
+
reason: `Step definitions changed \u2014 running ${featureFlows.length} feature flow(s).`,
|
|
2386
|
+
flowPaths: featureFlows
|
|
2066
2387
|
};
|
|
2067
2388
|
}
|
|
2389
|
+
}
|
|
2390
|
+
const changedFlows = flowPaths.filter((p) => changedSet.has(p));
|
|
2391
|
+
if (changedFlows.length > 0) {
|
|
2068
2392
|
return {
|
|
2069
|
-
mode: "
|
|
2070
|
-
reason:
|
|
2071
|
-
flowPaths:
|
|
2393
|
+
mode: "targeted",
|
|
2394
|
+
reason: `Running ${changedFlows.length} changed flow(s).`,
|
|
2395
|
+
flowPaths: changedFlows
|
|
2072
2396
|
};
|
|
2073
2397
|
}
|
|
2074
|
-
return {
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
};
|
|
2398
|
+
return { mode: "none", reason: "No changed flow files detected.", flowPaths: [] };
|
|
2399
|
+
}
|
|
2400
|
+
function createLastRunStatePath(outputDir) {
|
|
2401
|
+
return join4(outputDir, ".spana", "last-run.json");
|
|
2079
2402
|
}
|
|
2080
2403
|
|
|
2081
2404
|
// src/cli/watch-mode.ts
|
|
2082
2405
|
import { readdir, stat } from "fs/promises";
|
|
2083
2406
|
import { dirname as dirname2, extname, resolve as resolve2 } from "path";
|
|
2084
|
-
var
|
|
2085
|
-
var
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
snapshotRoots: snapshotWatchRoots
|
|
2089
|
-
};
|
|
2090
|
-
function collectWatchRoots(flowPathOrDir, configPath) {
|
|
2091
|
-
const roots = /* @__PURE__ */ new Set();
|
|
2092
|
-
const resolvedFlowPath = resolve2(flowPathOrDir);
|
|
2093
|
-
roots.add(resolvedFlowPath);
|
|
2407
|
+
var WATCH_EXTENSIONS = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".json", ".feature"]);
|
|
2408
|
+
var IGNORE_DIRS = /* @__PURE__ */ new Set([".git", "node_modules", "spana-output", "dist", "coverage"]);
|
|
2409
|
+
function collectWatchRoots(flowDir, configPath) {
|
|
2410
|
+
const roots = [resolve2(flowDir)];
|
|
2094
2411
|
if (configPath) {
|
|
2095
|
-
|
|
2412
|
+
const configDir = dirname2(resolve2(configPath));
|
|
2413
|
+
if (!roots.includes(configDir)) roots.push(configDir);
|
|
2096
2414
|
}
|
|
2097
|
-
return
|
|
2415
|
+
return roots;
|
|
2098
2416
|
}
|
|
2099
|
-
function
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
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 });
|
|
2417
|
+
async function snapshotDir(dir) {
|
|
2418
|
+
const snapshots = [];
|
|
2419
|
+
try {
|
|
2420
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
2109
2421
|
for (const entry of entries) {
|
|
2110
|
-
if (
|
|
2111
|
-
|
|
2422
|
+
if (IGNORE_DIRS.has(entry.name)) continue;
|
|
2423
|
+
const fullPath = resolve2(dir, entry.name);
|
|
2424
|
+
if (entry.isDirectory()) {
|
|
2425
|
+
snapshots.push(...await snapshotDir(fullPath));
|
|
2426
|
+
} else if (WATCH_EXTENSIONS.has(extname(entry.name))) {
|
|
2427
|
+
const info = await stat(fullPath);
|
|
2428
|
+
snapshots.push({ path: fullPath, mtime: info.mtimeMs, size: info.size });
|
|
2112
2429
|
}
|
|
2113
|
-
await snapshotPath(resolve2(path, entry.name), snapshot);
|
|
2114
2430
|
}
|
|
2115
|
-
|
|
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);
|
|
2431
|
+
} catch {
|
|
2135
2432
|
}
|
|
2136
|
-
return
|
|
2433
|
+
return snapshots;
|
|
2137
2434
|
}
|
|
2138
2435
|
function diffSnapshots(previous, next) {
|
|
2139
|
-
const
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2436
|
+
const prevMap = new Map(previous.map((s) => [s.path, s]));
|
|
2437
|
+
const changed = [];
|
|
2438
|
+
for (const snap of next) {
|
|
2439
|
+
const prev = prevMap.get(snap.path);
|
|
2440
|
+
if (!prev || prev.mtime !== snap.mtime || prev.size !== snap.size) {
|
|
2441
|
+
changed.push(snap.path);
|
|
2143
2442
|
}
|
|
2144
2443
|
}
|
|
2145
|
-
|
|
2146
|
-
if (!previous.has(path)) {
|
|
2147
|
-
changed.add(path);
|
|
2148
|
-
}
|
|
2149
|
-
}
|
|
2150
|
-
return [...changed].toSorted();
|
|
2444
|
+
return changed;
|
|
2151
2445
|
}
|
|
2152
|
-
async function runWatchLoop(options
|
|
2153
|
-
|
|
2446
|
+
async function runWatchLoop(options) {
|
|
2447
|
+
const interval = options.interval ?? 500;
|
|
2448
|
+
let previous = [];
|
|
2449
|
+
for (const root of options.roots) {
|
|
2450
|
+
previous.push(...await snapshotDir(root));
|
|
2451
|
+
}
|
|
2154
2452
|
while (true) {
|
|
2155
|
-
await
|
|
2156
|
-
const
|
|
2157
|
-
const
|
|
2158
|
-
|
|
2159
|
-
|
|
2453
|
+
await new Promise((r) => setTimeout(r, interval));
|
|
2454
|
+
const next = [];
|
|
2455
|
+
for (const root of options.roots) {
|
|
2456
|
+
next.push(...await snapshotDir(root));
|
|
2457
|
+
}
|
|
2458
|
+
const changed = diffSnapshots(previous, next);
|
|
2459
|
+
if (changed.length > 0) {
|
|
2460
|
+
await options.onChange(changed);
|
|
2160
2461
|
}
|
|
2161
|
-
|
|
2162
|
-
await options.onChange(changedPaths);
|
|
2462
|
+
previous = next;
|
|
2163
2463
|
}
|
|
2164
2464
|
}
|
|
2165
2465
|
|
|
@@ -2191,26 +2491,8 @@ function validateOptions(opts) {
|
|
|
2191
2491
|
}
|
|
2192
2492
|
return null;
|
|
2193
2493
|
}
|
|
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
2494
|
async function buildParallelPlatformConfigs(platforms, opts, config, runtimes, resolveFromConfig) {
|
|
2213
|
-
const { discoverDevices, findDeviceById } = await import("./discover-
|
|
2495
|
+
const { discoverDevices, findDeviceById } = await import("./discover-CAQY6EG6.js");
|
|
2214
2496
|
let allDevices;
|
|
2215
2497
|
if (opts.devices) {
|
|
2216
2498
|
allDevices = [];
|
|
@@ -2250,13 +2532,21 @@ async function buildParallelPlatformConfigs(platforms, opts, config, runtimes, r
|
|
|
2250
2532
|
id: `web-context-${i + 1}`,
|
|
2251
2533
|
name: `Chromium #${i + 1}`,
|
|
2252
2534
|
driver: result.runtime.driver,
|
|
2253
|
-
engineConfig: {
|
|
2535
|
+
engineConfig: {
|
|
2536
|
+
...result.engineConfig,
|
|
2537
|
+
debugOnFailure: opts.debugOnFailure,
|
|
2538
|
+
updateBaselines: opts.updateBaselines
|
|
2539
|
+
}
|
|
2254
2540
|
});
|
|
2255
2541
|
}
|
|
2256
2542
|
platformConfigs.push({
|
|
2257
2543
|
platform,
|
|
2258
2544
|
driver: primaryResult.runtime.driver,
|
|
2259
|
-
engineConfig: {
|
|
2545
|
+
engineConfig: {
|
|
2546
|
+
...primaryResult.engineConfig,
|
|
2547
|
+
debugOnFailure: opts.debugOnFailure,
|
|
2548
|
+
updateBaselines: opts.updateBaselines
|
|
2549
|
+
},
|
|
2260
2550
|
additionalWorkers: additionalWorkers.length > 0 ? additionalWorkers : void 0
|
|
2261
2551
|
});
|
|
2262
2552
|
} else {
|
|
@@ -2265,7 +2555,11 @@ async function buildParallelPlatformConfigs(platforms, opts, config, runtimes, r
|
|
|
2265
2555
|
platformConfigs.push({
|
|
2266
2556
|
platform,
|
|
2267
2557
|
driver: result.runtime.driver,
|
|
2268
|
-
engineConfig: {
|
|
2558
|
+
engineConfig: {
|
|
2559
|
+
...result.engineConfig,
|
|
2560
|
+
debugOnFailure: opts.debugOnFailure,
|
|
2561
|
+
updateBaselines: opts.updateBaselines
|
|
2562
|
+
}
|
|
2269
2563
|
});
|
|
2270
2564
|
}
|
|
2271
2565
|
} else if (platformDevices.length === 0) {
|
|
@@ -2290,7 +2584,11 @@ async function buildParallelPlatformConfigs(platforms, opts, config, runtimes, r
|
|
|
2290
2584
|
id: device.id,
|
|
2291
2585
|
name: device.name,
|
|
2292
2586
|
driver: result.runtime.driver,
|
|
2293
|
-
engineConfig: {
|
|
2587
|
+
engineConfig: {
|
|
2588
|
+
...result.engineConfig,
|
|
2589
|
+
debugOnFailure: opts.debugOnFailure,
|
|
2590
|
+
updateBaselines: opts.updateBaselines
|
|
2591
|
+
}
|
|
2294
2592
|
});
|
|
2295
2593
|
}
|
|
2296
2594
|
} catch (err) {
|
|
@@ -2302,21 +2600,31 @@ async function buildParallelPlatformConfigs(platforms, opts, config, runtimes, r
|
|
|
2302
2600
|
platformConfigs.push({
|
|
2303
2601
|
platform,
|
|
2304
2602
|
driver: primaryResult.runtime.driver,
|
|
2305
|
-
engineConfig: {
|
|
2603
|
+
engineConfig: {
|
|
2604
|
+
...primaryResult.engineConfig,
|
|
2605
|
+
debugOnFailure: opts.debugOnFailure,
|
|
2606
|
+
updateBaselines: opts.updateBaselines
|
|
2607
|
+
},
|
|
2306
2608
|
additionalWorkers: additionalWorkers.length > 0 ? additionalWorkers : void 0
|
|
2307
2609
|
});
|
|
2308
2610
|
}
|
|
2309
2611
|
}
|
|
2310
2612
|
return platformConfigs;
|
|
2311
2613
|
}
|
|
2312
|
-
async function buildSerialPlatformConfigs(platforms, opts, config, runtimes, executionMode, appiumUrl,
|
|
2614
|
+
async function buildSerialPlatformConfigs(platforms, opts, config, runtimes, executionMode, appiumUrl, appiumConfig, cloudHelper, targetDevice, resolveFromConfig) {
|
|
2313
2615
|
const platformConfigs = [];
|
|
2314
2616
|
for (const platform of platforms) {
|
|
2315
2617
|
if (executionMode === "appium" && (platform === "android" || platform === "ios")) {
|
|
2316
2618
|
const builder = platform === "android" ? buildAppiumAndroidRuntime : buildAppiumIOSRuntime;
|
|
2619
|
+
const resolvedCaps = appiumConfig ? await resolveCapabilities(appiumConfig, {
|
|
2620
|
+
capsPath: opts.capsPath,
|
|
2621
|
+
capsJson: opts.capsJson,
|
|
2622
|
+
platform,
|
|
2623
|
+
launchOptions: config.launchOptions
|
|
2624
|
+
}) : {};
|
|
2317
2625
|
const preparedCaps = await cloudHelper.prepareCapabilities(
|
|
2318
2626
|
platform,
|
|
2319
|
-
{ ...
|
|
2627
|
+
{ ...resolvedCaps },
|
|
2320
2628
|
platform === "android" ? config.apps?.android : config.apps?.ios
|
|
2321
2629
|
);
|
|
2322
2630
|
const result = await builder(config, appiumUrl, preparedCaps);
|
|
@@ -2324,7 +2632,11 @@ async function buildSerialPlatformConfigs(platforms, opts, config, runtimes, exe
|
|
|
2324
2632
|
platformConfigs.push({
|
|
2325
2633
|
platform,
|
|
2326
2634
|
driver: result.runtime.driver,
|
|
2327
|
-
engineConfig: {
|
|
2635
|
+
engineConfig: {
|
|
2636
|
+
...result.engineConfig,
|
|
2637
|
+
debugOnFailure: opts.debugOnFailure,
|
|
2638
|
+
updateBaselines: opts.updateBaselines
|
|
2639
|
+
}
|
|
2328
2640
|
});
|
|
2329
2641
|
} else if (platform === "web") {
|
|
2330
2642
|
const result = await buildWebRuntime(config);
|
|
@@ -2332,7 +2644,11 @@ async function buildSerialPlatformConfigs(platforms, opts, config, runtimes, exe
|
|
|
2332
2644
|
platformConfigs.push({
|
|
2333
2645
|
platform,
|
|
2334
2646
|
driver: result.runtime.driver,
|
|
2335
|
-
engineConfig: {
|
|
2647
|
+
engineConfig: {
|
|
2648
|
+
...result.engineConfig,
|
|
2649
|
+
debugOnFailure: opts.debugOnFailure,
|
|
2650
|
+
updateBaselines: opts.updateBaselines
|
|
2651
|
+
}
|
|
2336
2652
|
});
|
|
2337
2653
|
} else if (platform === "android") {
|
|
2338
2654
|
const result = await buildLocalAndroidRuntime(config, targetDevice, resolveFromConfig);
|
|
@@ -2341,7 +2657,11 @@ async function buildSerialPlatformConfigs(platforms, opts, config, runtimes, exe
|
|
|
2341
2657
|
platformConfigs.push({
|
|
2342
2658
|
platform,
|
|
2343
2659
|
driver: result.runtime.driver,
|
|
2344
|
-
engineConfig: {
|
|
2660
|
+
engineConfig: {
|
|
2661
|
+
...result.engineConfig,
|
|
2662
|
+
debugOnFailure: opts.debugOnFailure,
|
|
2663
|
+
updateBaselines: opts.updateBaselines
|
|
2664
|
+
}
|
|
2345
2665
|
});
|
|
2346
2666
|
} else if (platform === "ios") {
|
|
2347
2667
|
const result = await buildLocalIOSRuntime(config, targetDevice, resolveFromConfig);
|
|
@@ -2350,7 +2670,11 @@ async function buildSerialPlatformConfigs(platforms, opts, config, runtimes, exe
|
|
|
2350
2670
|
platformConfigs.push({
|
|
2351
2671
|
platform,
|
|
2352
2672
|
driver: result.runtime.driver,
|
|
2353
|
-
engineConfig: {
|
|
2673
|
+
engineConfig: {
|
|
2674
|
+
...result.engineConfig,
|
|
2675
|
+
debugOnFailure: opts.debugOnFailure,
|
|
2676
|
+
updateBaselines: opts.updateBaselines
|
|
2677
|
+
}
|
|
2354
2678
|
});
|
|
2355
2679
|
}
|
|
2356
2680
|
}
|
|
@@ -2388,11 +2712,11 @@ async function setupReporters(reporterNames, config, resolveFromConfig, appiumUr
|
|
|
2388
2712
|
const { createRedactor, registerUrlSecrets } = await import("./redact-U72BUBBR.js");
|
|
2389
2713
|
const redactor = createRedactor();
|
|
2390
2714
|
if (appiumUrl) registerUrlSecrets(redactor, appiumUrl);
|
|
2391
|
-
const { createConsoleReporter } = await import("./console-
|
|
2392
|
-
const { createJsonReporter } = await import("./json-
|
|
2715
|
+
const { createConsoleReporter } = await import("./console-7UW7VROK.js");
|
|
2716
|
+
const { createJsonReporter } = await import("./json-JMRPUVY2.js");
|
|
2393
2717
|
const { createJUnitReporter } = await import("./junit-HLC62MK6.js");
|
|
2394
|
-
const { createHtmlReporter } = await import("./html-
|
|
2395
|
-
const { createAllureReporter } = await import("./allure-
|
|
2718
|
+
const { createHtmlReporter } = await import("./html-F3X3XPSX.js");
|
|
2719
|
+
const { createAllureReporter } = await import("./allure-RNMEYTXS.js");
|
|
2396
2720
|
const resolvedOutputDir = config.artifacts?.outputDir ?? resolveFromConfig("./spana-output");
|
|
2397
2721
|
const reporters = [];
|
|
2398
2722
|
for (const name of reporterNames.split(",")) {
|
|
@@ -2429,12 +2753,7 @@ async function setupReporters(reporterNames, config, resolveFromConfig, appiumUr
|
|
|
2429
2753
|
}
|
|
2430
2754
|
return { redactor, reporters };
|
|
2431
2755
|
}
|
|
2432
|
-
async function
|
|
2433
|
-
const validationError = validateOptions(opts);
|
|
2434
|
-
if (validationError) {
|
|
2435
|
-
console.log(validationError);
|
|
2436
|
-
return { success: false, watchRoots: [] };
|
|
2437
|
-
}
|
|
2756
|
+
async function resolveExecutionContext(opts) {
|
|
2438
2757
|
let config = {};
|
|
2439
2758
|
let loadedConfigPath;
|
|
2440
2759
|
try {
|
|
@@ -2443,16 +2762,16 @@ async function runTestCommandOnce(opts) {
|
|
|
2443
2762
|
loadedConfigPath = loaded.configPath;
|
|
2444
2763
|
} catch (error) {
|
|
2445
2764
|
console.log(error instanceof Error ? error.message : String(error));
|
|
2446
|
-
return {
|
|
2765
|
+
return { ok: false, success: false };
|
|
2447
2766
|
}
|
|
2448
2767
|
const configDir = dirname3(loadedConfigPath ?? resolve3("spana.config.ts"));
|
|
2449
2768
|
if (opts.validateConfigOnly) {
|
|
2450
2769
|
if (!loadedConfigPath) {
|
|
2451
2770
|
console.log("No config file found to validate.");
|
|
2452
|
-
return {
|
|
2771
|
+
return { ok: false, success: false };
|
|
2453
2772
|
}
|
|
2454
2773
|
console.log(`\u2713 Config valid (${loadedConfigPath})`);
|
|
2455
|
-
return {
|
|
2774
|
+
return { ok: false, success: true };
|
|
2456
2775
|
}
|
|
2457
2776
|
const resolveFromConfig = (p) => resolve3(configDir, p);
|
|
2458
2777
|
if (config.artifacts?.outputDir) {
|
|
@@ -2464,89 +2783,84 @@ async function runTestCommandOnce(opts) {
|
|
|
2464
2783
|
JSON.parse(opts.capsJson);
|
|
2465
2784
|
} catch {
|
|
2466
2785
|
console.log("Invalid JSON in --caps-json flag.");
|
|
2467
|
-
return {
|
|
2786
|
+
return { ok: false, success: false };
|
|
2468
2787
|
}
|
|
2469
2788
|
}
|
|
2470
2789
|
if (executionMode === "appium") {
|
|
2471
|
-
const appiumUrl = opts.appiumUrl ?? config.execution?.appium?.serverUrl;
|
|
2472
|
-
|
|
2790
|
+
const appiumUrl = opts.appiumUrl ?? process.env.SPANA_APPIUM_URL ?? config.execution?.appium?.serverUrl;
|
|
2791
|
+
const wantAutoStart = opts.appiumAutoStart ?? config.execution?.appium?.autoStart ?? false;
|
|
2792
|
+
if (!appiumUrl && !wantAutoStart) {
|
|
2473
2793
|
console.log(
|
|
2474
|
-
"Appium mode requires a server URL. Set --appium-url
|
|
2794
|
+
"Appium mode requires a server URL. Set --appium-url, SPANA_APPIUM_URL env var, execution.appium.serverUrl in config, or use --appium-auto-start to spawn a local server."
|
|
2475
2795
|
);
|
|
2476
|
-
return {
|
|
2796
|
+
return { ok: false, success: false };
|
|
2477
2797
|
}
|
|
2478
2798
|
if (opts.device) {
|
|
2479
2799
|
console.log(
|
|
2480
2800
|
"Cannot use --device with appium mode. Use --caps or --caps-json to set device capabilities."
|
|
2481
2801
|
);
|
|
2482
|
-
return {
|
|
2802
|
+
return { ok: false, success: false };
|
|
2483
2803
|
}
|
|
2484
2804
|
}
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
`Device "${opts.device}" is ${targetDevice.platform}, but --platform ${platforms.join(",")} was specified.`
|
|
2509
|
-
);
|
|
2510
|
-
return {
|
|
2511
|
-
success: false,
|
|
2512
|
-
watchRoots: collectWatchRoots(resolveFromConfig(config.flowDir ?? "./flows"), loadedConfigPath)
|
|
2513
|
-
};
|
|
2514
|
-
}
|
|
2805
|
+
return {
|
|
2806
|
+
ok: true,
|
|
2807
|
+
context: { config, configPath: loadedConfigPath, configDir, executionMode, resolveFromConfig }
|
|
2808
|
+
};
|
|
2809
|
+
}
|
|
2810
|
+
async function resolveTargetDevice(deviceId, platforms, cliPlatforms) {
|
|
2811
|
+
const { findDeviceById } = await import("./discover-CAQY6EG6.js");
|
|
2812
|
+
const targetDevice = findDeviceById(deviceId);
|
|
2813
|
+
if (!targetDevice) {
|
|
2814
|
+
const { discoverDevices } = await import("./discover-CAQY6EG6.js");
|
|
2815
|
+
const available = discoverDevices(["web", "android", "ios"]);
|
|
2816
|
+
console.log(`Device "${deviceId}" not found. Available devices:`);
|
|
2817
|
+
for (const d of available) {
|
|
2818
|
+
console.log(` ${d.id.padEnd(30)} ${d.platform.padEnd(8)} ${d.type}`);
|
|
2819
|
+
}
|
|
2820
|
+
return { ok: false, success: false };
|
|
2821
|
+
}
|
|
2822
|
+
const updatedPlatforms = cliPlatforms.length === 0 ? [targetDevice.platform] : [...platforms];
|
|
2823
|
+
if (!updatedPlatforms.includes(targetDevice.platform)) {
|
|
2824
|
+
console.log(
|
|
2825
|
+
`Device "${deviceId}" is ${targetDevice.platform}, but --platform ${updatedPlatforms.join(",")} was specified.`
|
|
2826
|
+
);
|
|
2827
|
+
return { ok: false, success: false };
|
|
2515
2828
|
}
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2829
|
+
return { ok: true, device: targetDevice, platforms: updatedPlatforms };
|
|
2830
|
+
}
|
|
2831
|
+
async function discoverAndFilterFlows(input) {
|
|
2832
|
+
const watchRoots = collectWatchRoots(input.flowDir, input.configPath);
|
|
2833
|
+
let flowPaths = await discoverFlows(input.flowDir);
|
|
2520
2834
|
if (flowPaths.length === 0) {
|
|
2521
2835
|
console.log("No flow files found.");
|
|
2522
|
-
return { success: true, watchRoots };
|
|
2836
|
+
return { ok: false, success: true, watchRoots };
|
|
2523
2837
|
}
|
|
2524
2838
|
let stepPaths = [];
|
|
2525
2839
|
const hasFeatureFiles = flowPaths.some((p) => p.endsWith(".feature"));
|
|
2526
2840
|
if (hasFeatureFiles) {
|
|
2527
2841
|
const { stat: statPath } = await import("fs/promises");
|
|
2528
2842
|
const { dirname: dirnameDyn } = await import("path");
|
|
2529
|
-
const flowDirStats = await statPath(flowDir).catch(() => null);
|
|
2530
|
-
const stepSearchDir = flowDirStats?.isDirectory() ? flowDir : dirnameDyn(flowDir);
|
|
2843
|
+
const flowDirStats = await statPath(input.flowDir).catch(() => null);
|
|
2844
|
+
const stepSearchDir = flowDirStats?.isDirectory() ? input.flowDir : dirnameDyn(input.flowDir);
|
|
2531
2845
|
stepPaths = await discoverStepFiles(stepSearchDir);
|
|
2532
2846
|
}
|
|
2533
|
-
if (
|
|
2847
|
+
if (input.changed) {
|
|
2534
2848
|
let changedFiles;
|
|
2535
2849
|
try {
|
|
2536
2850
|
changedFiles = getGitChangedFiles(process.cwd());
|
|
2537
2851
|
} catch (error) {
|
|
2538
2852
|
console.log(error instanceof Error ? error.message : String(error));
|
|
2539
|
-
return { success: false, watchRoots };
|
|
2853
|
+
return { ok: false, success: false, watchRoots };
|
|
2540
2854
|
}
|
|
2541
2855
|
const selection = selectChangedFlowPaths({
|
|
2542
2856
|
flowPaths,
|
|
2543
2857
|
changedFiles,
|
|
2544
2858
|
stepPaths,
|
|
2545
|
-
configPath:
|
|
2859
|
+
configPath: input.configPath
|
|
2546
2860
|
});
|
|
2547
2861
|
if (selection.mode === "none") {
|
|
2548
2862
|
console.log(selection.reason);
|
|
2549
|
-
return { success: true, watchRoots };
|
|
2863
|
+
return { ok: false, success: true, watchRoots };
|
|
2550
2864
|
}
|
|
2551
2865
|
if (selection.mode === "targeted") {
|
|
2552
2866
|
flowPaths = selection.flowPaths;
|
|
@@ -2557,52 +2871,160 @@ async function runTestCommandOnce(opts) {
|
|
|
2557
2871
|
}
|
|
2558
2872
|
if (flowPaths.length === 0) {
|
|
2559
2873
|
console.log("No flow files found.");
|
|
2560
|
-
return { success: true, watchRoots };
|
|
2874
|
+
return { ok: false, success: true, watchRoots };
|
|
2561
2875
|
}
|
|
2562
2876
|
if (flowPaths.some((path) => path.endsWith(".feature")) && stepPaths.length > 0) {
|
|
2563
2877
|
await loadStepFiles(stepPaths);
|
|
2564
2878
|
}
|
|
2565
|
-
const loadedFlows =
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2879
|
+
const loadedFlows = [];
|
|
2880
|
+
for (const sourcePath of flowPaths) {
|
|
2881
|
+
const loaded = await loadTestSource(sourcePath);
|
|
2882
|
+
for (const flow of loaded) {
|
|
2883
|
+
loadedFlows.push({ sourcePath, flow });
|
|
2884
|
+
}
|
|
2885
|
+
}
|
|
2886
|
+
const filteredFlows = filterFlows(
|
|
2887
|
+
loadedFlows.map((l) => l.flow),
|
|
2888
|
+
{ tags: input.tags, grep: input.grep, platforms: input.platforms }
|
|
2889
|
+
);
|
|
2890
|
+
const allowedFlows = new Set(filteredFlows);
|
|
2891
|
+
let filteredLoadedFlows = loadedFlows.filter((l) => allowedFlows.has(l.flow));
|
|
2892
|
+
if (input.lastFailed) {
|
|
2893
|
+
const lastRunStatePath = createLastRunStatePath(input.outputDir);
|
|
2574
2894
|
const state = await readLastRunState(lastRunStatePath);
|
|
2575
2895
|
if (!state) {
|
|
2576
|
-
console.log(
|
|
2577
|
-
|
|
2896
|
+
console.log(
|
|
2897
|
+
"No previous Spana run state found. Run `spana test` once before using --last-failed."
|
|
2898
|
+
);
|
|
2899
|
+
return { ok: false, success: true, watchRoots };
|
|
2578
2900
|
}
|
|
2579
2901
|
if (state.failedFlowNames.length === 0) {
|
|
2580
2902
|
console.log("No failed flows were recorded in the last Spana run.");
|
|
2581
|
-
return { success: true, watchRoots };
|
|
2903
|
+
return { ok: false, success: true, watchRoots };
|
|
2582
2904
|
}
|
|
2583
2905
|
const failedFlowNames = new Set(state.failedFlowNames);
|
|
2584
|
-
|
|
2585
|
-
if (
|
|
2906
|
+
filteredLoadedFlows = filteredLoadedFlows.filter((l) => failedFlowNames.has(l.flow.name));
|
|
2907
|
+
if (filteredLoadedFlows.length === 0) {
|
|
2586
2908
|
console.log("No last-failed flows match the current filters.");
|
|
2587
|
-
return { success: true, watchRoots };
|
|
2909
|
+
return { ok: false, success: true, watchRoots };
|
|
2588
2910
|
}
|
|
2589
|
-
console.log(`Rerunning ${
|
|
2911
|
+
console.log(`Rerunning ${filteredLoadedFlows.length} flow(s) from the last failed run.`);
|
|
2590
2912
|
}
|
|
2591
|
-
const selectedLoadedFlows = applyShard(
|
|
2592
|
-
const selectedFlows = selectedLoadedFlows.map((
|
|
2593
|
-
if (
|
|
2913
|
+
const selectedLoadedFlows = applyShard(filteredLoadedFlows, input.shard);
|
|
2914
|
+
const selectedFlows = selectedLoadedFlows.map((l) => l.flow);
|
|
2915
|
+
if (filteredLoadedFlows.length === 0) {
|
|
2594
2916
|
console.log("No flows match the given filters.");
|
|
2595
|
-
return { success: true, watchRoots };
|
|
2917
|
+
return { ok: false, success: true, watchRoots };
|
|
2596
2918
|
}
|
|
2597
2919
|
if (selectedFlows.length === 0) {
|
|
2598
|
-
console.log(`No flows assigned to shard ${
|
|
2599
|
-
return { success: true, watchRoots };
|
|
2920
|
+
console.log(`No flows assigned to shard ${input.shard.current}/${input.shard.total}.`);
|
|
2921
|
+
return { ok: false, success: true, watchRoots };
|
|
2600
2922
|
}
|
|
2601
|
-
if (
|
|
2923
|
+
if (input.shard) {
|
|
2602
2924
|
console.log(
|
|
2603
|
-
`Running shard ${
|
|
2925
|
+
`Running shard ${input.shard.current}/${input.shard.total} (${selectedFlows.length}/${filteredLoadedFlows.length} flow(s))...`
|
|
2604
2926
|
);
|
|
2605
2927
|
}
|
|
2928
|
+
return { ok: true, selectedLoadedFlows, selectedFlows, watchRoots };
|
|
2929
|
+
}
|
|
2930
|
+
function createResultHandler(reporters, redactResult, redactor, opts) {
|
|
2931
|
+
return (r) => {
|
|
2932
|
+
const redacted = redactResult(r);
|
|
2933
|
+
for (const reporter of reporters) {
|
|
2934
|
+
if (redacted.status === "passed") {
|
|
2935
|
+
reporter.onFlowPass?.(redacted);
|
|
2936
|
+
} else if (redacted.status === "failed") {
|
|
2937
|
+
reporter.onFlowFail?.(redacted);
|
|
2938
|
+
if (opts.verbose && redacted.error) {
|
|
2939
|
+
console.log(
|
|
2940
|
+
`
|
|
2941
|
+
[verbose] Failure details for "${redacted.name}" on ${redacted.platform}:`
|
|
2942
|
+
);
|
|
2943
|
+
console.log(` Category: ${redacted.error.category}`);
|
|
2944
|
+
console.log(` Message: ${redacted.error.message}`);
|
|
2945
|
+
if (redacted.error.suggestion) {
|
|
2946
|
+
console.log(` Suggestion: ${redacted.error.suggestion}`);
|
|
2947
|
+
}
|
|
2948
|
+
for (const section of collectDiagnosticSections(redacted.attachments, {
|
|
2949
|
+
verbose: true
|
|
2950
|
+
})) {
|
|
2951
|
+
console.log(` ${section.title}: ${redactor.redact(section.path)}`);
|
|
2952
|
+
console.log(
|
|
2953
|
+
section.body.split("\n").map((line) => ` ${redactor.redact(line)}`).join("\n")
|
|
2954
|
+
);
|
|
2955
|
+
}
|
|
2956
|
+
if (redacted.error.stack) {
|
|
2957
|
+
console.log(
|
|
2958
|
+
` Stack:
|
|
2959
|
+
${redacted.error.stack.split("\n").map((l) => ` ${l}`).join("\n")}`
|
|
2960
|
+
);
|
|
2961
|
+
}
|
|
2962
|
+
}
|
|
2963
|
+
}
|
|
2964
|
+
}
|
|
2965
|
+
};
|
|
2966
|
+
}
|
|
2967
|
+
async function reportToCloudProvider(runtimes, appiumUrl, result, platforms) {
|
|
2968
|
+
const { detectProvider: detectProvider2 } = await import("./provider-YIPU5K42.js");
|
|
2969
|
+
for (const rt of runtimes) {
|
|
2970
|
+
if (rt.metadata.mode === "appium" && rt.metadata.provider) {
|
|
2971
|
+
const provider = detectProvider2(appiumUrl);
|
|
2972
|
+
if (provider) {
|
|
2973
|
+
try {
|
|
2974
|
+
const meta = {};
|
|
2975
|
+
provider.extractMeta(rt.metadata.sessionId, rt.metadata.sessionCaps ?? {}, meta);
|
|
2976
|
+
await provider.reportResult(appiumUrl, meta, {
|
|
2977
|
+
passed: result.failed === 0,
|
|
2978
|
+
name: `spana ${platforms.join(",")}`
|
|
2979
|
+
});
|
|
2980
|
+
} catch (e) {
|
|
2981
|
+
console.log(
|
|
2982
|
+
`Warning: Failed to report to ${rt.metadata.provider}: ${e instanceof Error ? e.message : e}`
|
|
2983
|
+
);
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2986
|
+
}
|
|
2987
|
+
}
|
|
2988
|
+
}
|
|
2989
|
+
async function runTestCommandOnce(opts) {
|
|
2990
|
+
const validationError = validateOptions(opts);
|
|
2991
|
+
if (validationError) {
|
|
2992
|
+
console.log(validationError);
|
|
2993
|
+
return { success: false, watchRoots: [] };
|
|
2994
|
+
}
|
|
2995
|
+
const ctxResult = await resolveExecutionContext(opts);
|
|
2996
|
+
if (!ctxResult.ok) return { success: ctxResult.success, watchRoots: [] };
|
|
2997
|
+
const { config, configPath, executionMode, resolveFromConfig } = ctxResult.context;
|
|
2998
|
+
const platforms = opts.platforms.length > 0 ? opts.platforms : config.platforms && config.platforms.length > 0 ? config.platforms : ["web"];
|
|
2999
|
+
const flowDir = opts.flowPath ?? resolveFromConfig(config.flowDir ?? "./flows");
|
|
3000
|
+
let targetDevice = null;
|
|
3001
|
+
if (opts.device) {
|
|
3002
|
+
const deviceResult = await resolveTargetDevice(opts.device, platforms, opts.platforms);
|
|
3003
|
+
if (!deviceResult.ok) {
|
|
3004
|
+
return {
|
|
3005
|
+
success: deviceResult.success,
|
|
3006
|
+
watchRoots: collectWatchRoots(flowDir, configPath)
|
|
3007
|
+
};
|
|
3008
|
+
}
|
|
3009
|
+
targetDevice = deviceResult.device;
|
|
3010
|
+
platforms.length = 0;
|
|
3011
|
+
platforms.push(...deviceResult.platforms);
|
|
3012
|
+
}
|
|
3013
|
+
const reporterNames = opts.reporter?.trim() ? opts.reporter : config.reporters && config.reporters.length > 0 ? config.reporters.join(",") : "console";
|
|
3014
|
+
const outputDir = config.artifacts?.outputDir ?? resolveFromConfig("./spana-output");
|
|
3015
|
+
const flowResult = await discoverAndFilterFlows({
|
|
3016
|
+
flowDir,
|
|
3017
|
+
configPath,
|
|
3018
|
+
tags: opts.tags,
|
|
3019
|
+
grep: opts.grep,
|
|
3020
|
+
platforms,
|
|
3021
|
+
shard: opts.shard,
|
|
3022
|
+
lastFailed: opts.lastFailed,
|
|
3023
|
+
changed: opts.changed,
|
|
3024
|
+
outputDir
|
|
3025
|
+
});
|
|
3026
|
+
if (!flowResult.ok) return { success: flowResult.success, watchRoots: flowResult.watchRoots };
|
|
3027
|
+
const { selectedLoadedFlows, selectedFlows, watchRoots } = flowResult;
|
|
2606
3028
|
console.log(`Running ${selectedFlows.length} flow(s) on ${platforms.join(", ")}...
|
|
2607
3029
|
`);
|
|
2608
3030
|
const runtimes = [];
|
|
@@ -2626,14 +3048,26 @@ async function runTestCommandOnce(opts) {
|
|
|
2626
3048
|
process.on("SIGINT", handleSignal);
|
|
2627
3049
|
process.on("SIGTERM", handleSignal);
|
|
2628
3050
|
try {
|
|
2629
|
-
const appiumUrl = opts.appiumUrl ?? config.execution?.appium?.serverUrl;
|
|
2630
3051
|
const appiumConfig = config.execution?.appium ?? {};
|
|
3052
|
+
const wantAutoStart = executionMode === "appium" && (opts.appiumAutoStart ?? appiumConfig.autoStart ?? false);
|
|
3053
|
+
let appiumUrl = opts.appiumUrl ?? process.env.SPANA_APPIUM_URL ?? config.execution?.appium?.serverUrl;
|
|
3054
|
+
if (wantAutoStart) {
|
|
3055
|
+
if (opts.appiumUrl || process.env.SPANA_APPIUM_URL || appiumConfig.serverUrl) {
|
|
3056
|
+
console.log(
|
|
3057
|
+
"Appium auto-start is enabled; ignoring --appium-url / SPANA_APPIUM_URL / execution.appium.serverUrl."
|
|
3058
|
+
);
|
|
3059
|
+
}
|
|
3060
|
+
const { startLocalAppium } = await import("./appium-server-66GVUL24.js");
|
|
3061
|
+
const started = await startLocalAppium({
|
|
3062
|
+
binary: appiumConfig.autoStartBinary,
|
|
3063
|
+
extraArgs: appiumConfig.autoStartArgs,
|
|
3064
|
+
log: (line) => console.log(line)
|
|
3065
|
+
});
|
|
3066
|
+
appiumUrl = started.url;
|
|
3067
|
+
runCleanups.push(() => started.stop());
|
|
3068
|
+
}
|
|
2631
3069
|
const shouldReportToProvider = !opts.noProviderReporting && appiumConfig.reportToProvider !== false;
|
|
2632
3070
|
const cloudHelper = executionMode === "appium" && appiumUrl ? await createCloudProviderHelper(appiumUrl, appiumConfig) : void 0;
|
|
2633
|
-
const baseAppiumCaps = executionMode === "appium" && appiumUrl ? await resolveCapabilities(appiumConfig, {
|
|
2634
|
-
capsPath: opts.capsPath,
|
|
2635
|
-
capsJson: opts.capsJson
|
|
2636
|
-
}) : void 0;
|
|
2637
3071
|
if (cloudHelper) {
|
|
2638
3072
|
runCleanups.push(() => cloudHelper.cleanup());
|
|
2639
3073
|
}
|
|
@@ -2656,7 +3090,7 @@ async function runTestCommandOnce(opts) {
|
|
|
2656
3090
|
runtimes,
|
|
2657
3091
|
executionMode,
|
|
2658
3092
|
appiumUrl,
|
|
2659
|
-
|
|
3093
|
+
appiumConfig,
|
|
2660
3094
|
cloudHelper,
|
|
2661
3095
|
targetDevice,
|
|
2662
3096
|
resolveFromConfig
|
|
@@ -2699,51 +3133,18 @@ async function runTestCommandOnce(opts) {
|
|
|
2699
3133
|
};
|
|
2700
3134
|
const retries = opts.retries ?? config.defaults?.retries ?? 0;
|
|
2701
3135
|
const retryDelay = config.defaults?.retryDelay ?? 0;
|
|
3136
|
+
const onResult = createResultHandler(reporters, redactResult, redactor, opts);
|
|
2702
3137
|
const result = await orchestrate(selectedFlows, platformConfigs, {
|
|
2703
3138
|
retries,
|
|
2704
3139
|
retryDelay,
|
|
2705
3140
|
bail: opts.bail,
|
|
2706
|
-
parallelPlatforms: opts.parallel || !!opts.workers || !!opts.devices,
|
|
3141
|
+
parallelPlatforms: opts.parallel || config.parallelPlatforms || !!opts.workers || !!opts.devices,
|
|
2707
3142
|
onFlowStart(name, platform, workerName) {
|
|
2708
3143
|
for (const reporter of reporters) {
|
|
2709
3144
|
reporter.onFlowStart?.(name, platform, workerName);
|
|
2710
3145
|
}
|
|
2711
3146
|
},
|
|
2712
|
-
onResult
|
|
2713
|
-
const redacted = redactResult(r);
|
|
2714
|
-
for (const reporter of reporters) {
|
|
2715
|
-
if (redacted.status === "passed") {
|
|
2716
|
-
reporter.onFlowPass?.(redacted);
|
|
2717
|
-
} else if (redacted.status === "failed") {
|
|
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
|
-
}
|
|
2744
|
-
}
|
|
2745
|
-
}
|
|
2746
|
-
}
|
|
3147
|
+
onResult
|
|
2747
3148
|
});
|
|
2748
3149
|
const redactedResults = result.results.map(redactResult);
|
|
2749
3150
|
for (const reporter of reporters) {
|
|
@@ -2764,9 +3165,7 @@ ${redacted.error.stack.split("\n").map((l) => ` ${l}`).join("\n")}`
|
|
|
2764
3165
|
const sourcePathsByFlowName = new Map(
|
|
2765
3166
|
selectedLoadedFlows.map((loaded) => [loaded.flow.name, loaded.sourcePath])
|
|
2766
3167
|
);
|
|
2767
|
-
const iterationStatePath = createLastRunStatePath(
|
|
2768
|
-
config.artifacts?.outputDir ?? resolveFromConfig("./spana-output")
|
|
2769
|
-
);
|
|
3168
|
+
const iterationStatePath = createLastRunStatePath(outputDir);
|
|
2770
3169
|
try {
|
|
2771
3170
|
await writeLastRunState(
|
|
2772
3171
|
iterationStatePath,
|
|
@@ -2783,26 +3182,7 @@ ${redacted.error.stack.split("\n").map((l) => ` ${l}`).join("\n")}`
|
|
|
2783
3182
|
);
|
|
2784
3183
|
}
|
|
2785
3184
|
if (shouldReportToProvider && appiumUrl) {
|
|
2786
|
-
|
|
2787
|
-
for (const rt of runtimes) {
|
|
2788
|
-
if (rt.metadata.mode === "appium" && rt.metadata.provider) {
|
|
2789
|
-
const provider = detectProvider2(appiumUrl);
|
|
2790
|
-
if (provider) {
|
|
2791
|
-
try {
|
|
2792
|
-
const meta = {};
|
|
2793
|
-
provider.extractMeta(rt.metadata.sessionId, rt.metadata.sessionCaps ?? {}, meta);
|
|
2794
|
-
await provider.reportResult(appiumUrl, meta, {
|
|
2795
|
-
passed: result.failed === 0,
|
|
2796
|
-
name: `spana ${platforms.join(",")}`
|
|
2797
|
-
});
|
|
2798
|
-
} catch (e) {
|
|
2799
|
-
console.log(
|
|
2800
|
-
`Warning: Failed to report to ${rt.metadata.provider}: ${e instanceof Error ? e.message : e}`
|
|
2801
|
-
);
|
|
2802
|
-
}
|
|
2803
|
-
}
|
|
2804
|
-
}
|
|
2805
|
-
}
|
|
3185
|
+
await reportToCloudProvider(runtimes, appiumUrl, result, platforms);
|
|
2806
3186
|
}
|
|
2807
3187
|
return { success: result.failed === 0, watchRoots };
|
|
2808
3188
|
} finally {
|
|
@@ -2849,4 +3229,4 @@ export {
|
|
|
2849
3229
|
loadCustomReporter,
|
|
2850
3230
|
runTestCommand
|
|
2851
3231
|
};
|
|
2852
|
-
//# sourceMappingURL=test-command-
|
|
3232
|
+
//# sourceMappingURL=test-command-B2VLWGDK.js.map
|