spana-test 0.2.0 → 0.3.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/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-S2XNAKSO.js → chunk-24KSKK2I.js} +536 -334
- package/dist/chunk-24KSKK2I.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-SFBRFB2N.js → chunk-4OHBO7LD.js} +19 -12
- package/dist/chunk-4OHBO7LD.js.map +1 -0
- package/dist/chunk-5245YBLL.js +127 -0
- package/dist/chunk-5245YBLL.js.map +1 -0
- package/dist/{chunk-S4R4OR7T.js → chunk-7IA2XG3G.js} +66 -71
- package/dist/chunk-7IA2XG3G.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-AEKDFFPJ.js → chunk-DSTUWLSW.js} +15 -4
- package/dist/chunk-DSTUWLSW.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-WQ4GXUUE.js → chunk-KAKHFSVA.js} +212 -34
- package/dist/chunk-KAKHFSVA.js.map +1 -0
- package/dist/chunk-OBCFACUW.js +28 -0
- package/dist/chunk-OBCFACUW.js.map +1 -0
- package/dist/{chunk-3YR4GUGE.js → chunk-QPIE3IMG.js} +65 -70
- package/dist/chunk-QPIE3IMG.js.map +1 -0
- package/dist/{chunk-VNYF5BHX.js → chunk-X2TJP7LB.js} +1 -3
- package/dist/{chunk-YBZCOQXJ.js → chunk-YXQEPVEW.js} +127 -66
- package/dist/chunk-YXQEPVEW.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-NPNF6SWQ.js} +4 -3
- package/dist/doctor-command-C3SEQGRQ.js +71 -0
- package/dist/doctor-command-C3SEQGRQ.js.map +1 -0
- package/dist/{flow-BUC9Mf8W.d.ts → flow-CW0_j7tw.d.ts} +47 -29
- 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-W5DITECS.js} +3 -4
- package/dist/{ios-ZW6XVNLG.js → ios-3GRECXAP.js} +3 -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-MZERO364.js} +362 -55
- package/dist/server-MZERO364.js.map +1 -0
- package/dist/session-3UZ5WAAD.js +17 -0
- package/dist/{coordinator-BbUjvvnX.d.ts → storybook-BK2JE4ld.d.ts} +95 -31
- package/dist/{studio-command-6VHTHDUK.js → studio-command-5BUER2RH.js} +2 -2
- package/dist/{test-command-AHMOZLV4.js → test-command-2PXTHASW.js} +871 -562
- package/dist/test-command-2PXTHASW.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-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/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/{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-NPNF6SWQ.js.map} +0 -0
- /package/dist/{installer-YZJ4DV3F.js.map → installer-W5DITECS.js.map} +0 -0
- /package/dist/{ios-ZW6XVNLG.js.map → ios-3GRECXAP.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-3UZ5WAAD.js.map} +0 -0
- /package/dist/{studio-command-6VHTHDUK.js.map → studio-command-5BUER2RH.js.map} +0 -0
|
@@ -1,28 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
loadConfig
|
|
3
|
+
} from "./chunk-FJAJ4YNC.js";
|
|
1
4
|
import {
|
|
2
5
|
collectDiagnosticSections
|
|
3
6
|
} from "./chunk-KJPHH2TW.js";
|
|
4
|
-
import {
|
|
5
|
-
resolveCapabilities
|
|
6
|
-
} from "./chunk-EXLUY7KT.js";
|
|
7
|
-
import {
|
|
8
|
-
loadConfig
|
|
9
|
-
} from "./chunk-P7JQRLP4.js";
|
|
10
7
|
import {
|
|
11
8
|
createPromiseApp,
|
|
12
9
|
createPromiseExpect
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-
|
|
10
|
+
} from "./chunk-YXQEPVEW.js";
|
|
11
|
+
import "./chunk-7VOWF42B.js";
|
|
15
12
|
import {
|
|
16
13
|
createUiAutomator2Driver,
|
|
17
14
|
createWDADriver,
|
|
18
15
|
makePlaywrightDriver,
|
|
19
16
|
parseAndroidHierarchy,
|
|
20
17
|
parseIOSHierarchy,
|
|
21
|
-
parseWebHierarchy
|
|
22
|
-
} from "./chunk-WQ4GXUUE.js";
|
|
23
|
-
import {
|
|
18
|
+
parseWebHierarchy,
|
|
24
19
|
setupUiAutomator2
|
|
25
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-KAKHFSVA.js";
|
|
21
|
+
import {
|
|
22
|
+
setupWDA
|
|
23
|
+
} from "./chunk-QPIE3IMG.js";
|
|
24
|
+
import {
|
|
25
|
+
ensureAndroidDevice
|
|
26
|
+
} from "./chunk-GZK22EIE.js";
|
|
27
|
+
import {
|
|
28
|
+
connectPhysicalDevice,
|
|
29
|
+
ensureAppInstalled,
|
|
30
|
+
ensureIOSSimulator,
|
|
31
|
+
firstIOSPhysicalDevice
|
|
32
|
+
} from "./chunk-4OHBO7LD.js";
|
|
33
|
+
import {
|
|
34
|
+
allocatePort
|
|
35
|
+
} from "./chunk-OBCFACUW.js";
|
|
26
36
|
import {
|
|
27
37
|
applyShard,
|
|
28
38
|
discoverFlows,
|
|
@@ -30,34 +40,20 @@ import {
|
|
|
30
40
|
filterFlows,
|
|
31
41
|
loadStepFiles,
|
|
32
42
|
loadTestSource
|
|
33
|
-
} from "./chunk-
|
|
43
|
+
} from "./chunk-3TRMQCUT.js";
|
|
34
44
|
import {
|
|
35
45
|
DriverError,
|
|
46
|
+
buildIOSLaunchConfiguration,
|
|
47
|
+
deviceStateToAppiumCapabilities,
|
|
36
48
|
flattenElements,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
failureCategoryToDocsUrl,
|
|
42
|
-
failureCategoryToErrorCode
|
|
43
|
-
} from "./chunk-FNDOEMOL.js";
|
|
49
|
+
hasLaunchDeviceState,
|
|
50
|
+
mergeLaunchOptions,
|
|
51
|
+
splitGraphemes
|
|
52
|
+
} from "./chunk-24KSKK2I.js";
|
|
44
53
|
import {
|
|
45
54
|
createCloudProviderHelper,
|
|
46
55
|
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";
|
|
56
|
+
} from "./chunk-X2TJP7LB.js";
|
|
61
57
|
import "./chunk-DGUM43GV.js";
|
|
62
58
|
|
|
63
59
|
// src/cli/test-command.ts
|
|
@@ -610,13 +606,164 @@ function classifyError(error) {
|
|
|
610
606
|
message: error.message,
|
|
611
607
|
stack: error.stack,
|
|
612
608
|
category,
|
|
613
|
-
|
|
614
|
-
suggestion,
|
|
615
|
-
suggestedFix: suggestion,
|
|
616
|
-
docsUrl: failureCategoryToDocsUrl(category)
|
|
609
|
+
suggestion
|
|
617
610
|
};
|
|
618
611
|
}
|
|
619
612
|
|
|
613
|
+
// src/core/engine.ts
|
|
614
|
+
import { join as join3 } from "path";
|
|
615
|
+
|
|
616
|
+
// src/report/failure-bundle.ts
|
|
617
|
+
import { writeFileSync as writeFileSync2, readFileSync, existsSync } from "fs";
|
|
618
|
+
import { join as join2, basename } from "path";
|
|
619
|
+
function levenshtein(a, b) {
|
|
620
|
+
const m = a.length;
|
|
621
|
+
const n = b.length;
|
|
622
|
+
const dp = Array.from({ length: m + 1 }, () => Array(n + 1).fill(0));
|
|
623
|
+
for (let i = 0; i <= m; i++) dp[i][0] = i;
|
|
624
|
+
for (let j = 0; j <= n; j++) dp[0][j] = j;
|
|
625
|
+
for (let i = 1; i <= m; i++) {
|
|
626
|
+
for (let j = 1; j <= n; j++) {
|
|
627
|
+
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]);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
return dp[m][n];
|
|
631
|
+
}
|
|
632
|
+
function extractIdentifiers(hierarchyJson) {
|
|
633
|
+
const testIDs = [];
|
|
634
|
+
const texts = [];
|
|
635
|
+
try {
|
|
636
|
+
const root = JSON.parse(hierarchyJson);
|
|
637
|
+
const queue = [root];
|
|
638
|
+
while (queue.length > 0) {
|
|
639
|
+
const node = queue.pop();
|
|
640
|
+
if (!node || typeof node !== "object") continue;
|
|
641
|
+
if (node.testID && typeof node.testID === "string") testIDs.push(node.testID);
|
|
642
|
+
if (node.text && typeof node.text === "string") texts.push(node.text);
|
|
643
|
+
if (Array.isArray(node.children)) {
|
|
644
|
+
for (const child of node.children) queue.push(child);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
} catch {
|
|
648
|
+
}
|
|
649
|
+
return { testIDs, texts };
|
|
650
|
+
}
|
|
651
|
+
function findNearbySelectors(attempted, hierarchyJson) {
|
|
652
|
+
if (!hierarchyJson) return [];
|
|
653
|
+
const { testIDs, texts } = extractIdentifiers(hierarchyJson);
|
|
654
|
+
let target;
|
|
655
|
+
let candidates;
|
|
656
|
+
if (typeof attempted === "string") {
|
|
657
|
+
target = attempted.toLowerCase();
|
|
658
|
+
candidates = [...testIDs, ...texts];
|
|
659
|
+
} else if (attempted && typeof attempted === "object") {
|
|
660
|
+
const sel = attempted;
|
|
661
|
+
if (typeof sel.testID === "string") {
|
|
662
|
+
target = sel.testID.toLowerCase();
|
|
663
|
+
candidates = testIDs;
|
|
664
|
+
} else if (typeof sel.text === "string") {
|
|
665
|
+
target = sel.text.toLowerCase();
|
|
666
|
+
candidates = texts;
|
|
667
|
+
} else if (typeof sel.accessibilityLabel === "string") {
|
|
668
|
+
target = sel.accessibilityLabel.toLowerCase();
|
|
669
|
+
candidates = [...testIDs, ...texts];
|
|
670
|
+
} else {
|
|
671
|
+
return [];
|
|
672
|
+
}
|
|
673
|
+
} else {
|
|
674
|
+
return [];
|
|
675
|
+
}
|
|
676
|
+
const scored = candidates.filter((c) => c !== target).map((c) => {
|
|
677
|
+
const cl = c.toLowerCase();
|
|
678
|
+
const substringMatch = cl.includes(target) || target.includes(cl);
|
|
679
|
+
const dist = levenshtein(target, cl);
|
|
680
|
+
return { value: c, score: substringMatch ? 0 : dist };
|
|
681
|
+
}).filter((s) => s.score <= 5).toSorted((a, b) => a.score - b.score);
|
|
682
|
+
const seen = /* @__PURE__ */ new Set();
|
|
683
|
+
const results = [];
|
|
684
|
+
for (const s of scored) {
|
|
685
|
+
if (!seen.has(s.value)) {
|
|
686
|
+
seen.add(s.value);
|
|
687
|
+
results.push(s.value);
|
|
688
|
+
if (results.length >= 5) break;
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
return results;
|
|
692
|
+
}
|
|
693
|
+
function buildArtifactMap(attachments) {
|
|
694
|
+
const map = {};
|
|
695
|
+
if (!attachments) return map;
|
|
696
|
+
for (const att of attachments) {
|
|
697
|
+
const filename = basename(att.path);
|
|
698
|
+
if (filename === "screenshot.png") map.screenshot = filename;
|
|
699
|
+
else if (filename === "hierarchy.json") map.hierarchy = filename;
|
|
700
|
+
else if (filename === "console-logs.json") map.consoleLogs = filename;
|
|
701
|
+
else if (filename === "js-errors.json") map.jsErrors = filename;
|
|
702
|
+
else if (filename === "network.har") map.har = filename;
|
|
703
|
+
else if (filename === "driver-logs.txt") map.driverLogs = filename;
|
|
704
|
+
}
|
|
705
|
+
return map;
|
|
706
|
+
}
|
|
707
|
+
function createFailureBundle(flowName, platform, steps, error, artifactDir, attachments, flowPath) {
|
|
708
|
+
const failedStepIndex = steps.findLastIndex((s) => s.status === "failed");
|
|
709
|
+
const failedStep = failedStepIndex >= 0 ? {
|
|
710
|
+
index: failedStepIndex,
|
|
711
|
+
command: steps[failedStepIndex].command,
|
|
712
|
+
selector: steps[failedStepIndex].selector ?? null,
|
|
713
|
+
durationMs: steps[failedStepIndex].durationMs,
|
|
714
|
+
error: steps[failedStepIndex].error
|
|
715
|
+
} : null;
|
|
716
|
+
const lastPassedIndex = failedStepIndex > 0 ? steps.findLastIndex((s, i) => i < failedStepIndex && s.status === "passed") : -1;
|
|
717
|
+
const lastPassedStep = lastPassedIndex >= 0 ? {
|
|
718
|
+
index: lastPassedIndex,
|
|
719
|
+
command: steps[lastPassedIndex].command,
|
|
720
|
+
selector: steps[lastPassedIndex].selector ?? null,
|
|
721
|
+
durationMs: steps[lastPassedIndex].durationMs
|
|
722
|
+
} : null;
|
|
723
|
+
let selectorContext;
|
|
724
|
+
if (failedStep?.selector && (error.category === "element-not-found" || error.category === "element-not-visible")) {
|
|
725
|
+
const hierarchyPath = join2(artifactDir, "hierarchy.json");
|
|
726
|
+
let hierarchyJson = null;
|
|
727
|
+
if (existsSync(hierarchyPath)) {
|
|
728
|
+
try {
|
|
729
|
+
hierarchyJson = readFileSync(hierarchyPath, "utf-8");
|
|
730
|
+
} catch {
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
const nearbyAlternatives = findNearbySelectors(failedStep.selector, hierarchyJson);
|
|
734
|
+
selectorContext = {
|
|
735
|
+
attempted: failedStep.selector,
|
|
736
|
+
nearbyAlternatives
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
const flowFile = flowPath ?? `flows/${flowName.replaceAll(" ", "-")}.flow.ts`;
|
|
740
|
+
const reproCommand = `spana test ${flowFile} --platform ${platform} --grep '${flowName}'`;
|
|
741
|
+
const bundle = {
|
|
742
|
+
schemaVersion: 1,
|
|
743
|
+
flow: flowName,
|
|
744
|
+
platform,
|
|
745
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
746
|
+
failedStep,
|
|
747
|
+
lastPassedStep,
|
|
748
|
+
error: {
|
|
749
|
+
message: error.message,
|
|
750
|
+
category: error.category,
|
|
751
|
+
suggestion: error.suggestion,
|
|
752
|
+
errorCode: error.errorCode
|
|
753
|
+
},
|
|
754
|
+
selectorContext,
|
|
755
|
+
artifacts: buildArtifactMap(attachments),
|
|
756
|
+
reproCommand,
|
|
757
|
+
durationMs: steps.reduce((sum, s) => sum + s.durationMs, 0)
|
|
758
|
+
};
|
|
759
|
+
return bundle;
|
|
760
|
+
}
|
|
761
|
+
function writeFailureBundle(bundle, artifactDir) {
|
|
762
|
+
const path = join2(artifactDir, "failure-bundle.json");
|
|
763
|
+
writeFileSync2(path, JSON.stringify(bundle, null, 2), "utf-8");
|
|
764
|
+
return path;
|
|
765
|
+
}
|
|
766
|
+
|
|
620
767
|
// src/core/engine.ts
|
|
621
768
|
async function executeFlow(flow, driver, config) {
|
|
622
769
|
const start2 = Date.now();
|
|
@@ -625,6 +772,7 @@ async function executeFlow(flow, driver, config) {
|
|
|
625
772
|
const timeout = flow.config.timeout ?? config.flowTimeout ?? 6e4;
|
|
626
773
|
const artifactConfig = resolveArtifactConfig(config.artifactConfig, flow.config.artifacts);
|
|
627
774
|
const stepRecorder = createStepRecorder(driver, artifactConfig, flow.name, platform);
|
|
775
|
+
const launchOptions = mergeLaunchOptions(config.launchOptions, flow.config.launchOptions);
|
|
628
776
|
const flowDefaults = flow.config.defaults;
|
|
629
777
|
const mergedCoordinatorConfig = flowDefaults ? {
|
|
630
778
|
...coordinatorConfig,
|
|
@@ -639,11 +787,33 @@ async function executeFlow(flow, driver, config) {
|
|
|
639
787
|
typingDelay: flowDefaults.typingDelay ?? coordinatorConfig.typingDelay,
|
|
640
788
|
hierarchyCacheTtl: flowDefaults.hierarchyCacheTtl ?? coordinatorConfig.hierarchyCacheTtl
|
|
641
789
|
} : coordinatorConfig;
|
|
642
|
-
const app = createPromiseApp(driver, appId, mergedCoordinatorConfig, stepRecorder
|
|
643
|
-
|
|
644
|
-
|
|
790
|
+
const app = createPromiseApp(driver, appId, mergedCoordinatorConfig, stepRecorder, {
|
|
791
|
+
platform,
|
|
792
|
+
storybook: config.storybook,
|
|
793
|
+
launchOptions
|
|
794
|
+
});
|
|
795
|
+
const flowMeta = {
|
|
796
|
+
flowFilePath: flow.sourcePath ?? "",
|
|
797
|
+
flowName: flow.name,
|
|
798
|
+
platform,
|
|
799
|
+
updateBaselines: config.updateBaselines ?? false
|
|
800
|
+
};
|
|
801
|
+
const expect = createPromiseExpect(
|
|
802
|
+
driver,
|
|
803
|
+
mergedCoordinatorConfig,
|
|
804
|
+
stepRecorder,
|
|
805
|
+
flowMeta,
|
|
806
|
+
config.visualRegression
|
|
807
|
+
);
|
|
808
|
+
const flowCtx = { app, expect, platform, updateBaselines: flowMeta.updateBaselines };
|
|
645
809
|
const buildFailureResult = async (error) => {
|
|
646
|
-
const attachments = await captureArtifacts(
|
|
810
|
+
const attachments = await captureArtifacts(
|
|
811
|
+
driver,
|
|
812
|
+
artifactConfig,
|
|
813
|
+
flow.name,
|
|
814
|
+
platform,
|
|
815
|
+
"failed"
|
|
816
|
+
);
|
|
647
817
|
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
648
818
|
return {
|
|
649
819
|
name: flow.name,
|
|
@@ -673,7 +843,7 @@ async function executeFlow(flow, driver, config) {
|
|
|
673
843
|
let result;
|
|
674
844
|
try {
|
|
675
845
|
if (autoLaunch) {
|
|
676
|
-
await app.launch(
|
|
846
|
+
await app.launch();
|
|
677
847
|
}
|
|
678
848
|
await Promise.race([
|
|
679
849
|
flow.fn(flowCtx),
|
|
@@ -719,6 +889,24 @@ async function executeFlow(flow, driver, config) {
|
|
|
719
889
|
steps: stepRecorder.getSteps(),
|
|
720
890
|
scenarioSteps: flowCtx.__scenarioSteps
|
|
721
891
|
};
|
|
892
|
+
if (artifactConfig.captureOnFailure && result.error) {
|
|
893
|
+
try {
|
|
894
|
+
const artDir = join3(
|
|
895
|
+
artifactConfig.outputDir,
|
|
896
|
+
`${flow.name.replaceAll(/[^a-zA-Z0-9-_]/g, "_").replaceAll(/_+/g, "_").slice(0, 80) || "artifact"}-${platform}`
|
|
897
|
+
);
|
|
898
|
+
const bundle = createFailureBundle(
|
|
899
|
+
flow.name,
|
|
900
|
+
platform,
|
|
901
|
+
stepRecorder.getSteps(),
|
|
902
|
+
result.error,
|
|
903
|
+
artDir,
|
|
904
|
+
attachments
|
|
905
|
+
);
|
|
906
|
+
writeFailureBundle(bundle, artDir);
|
|
907
|
+
} catch {
|
|
908
|
+
}
|
|
909
|
+
}
|
|
722
910
|
if (config.debugOnFailure) {
|
|
723
911
|
await runDebugReplOnce({
|
|
724
912
|
app,
|
|
@@ -984,6 +1172,30 @@ async function orchestrate(flows, platforms, options) {
|
|
|
984
1172
|
};
|
|
985
1173
|
}
|
|
986
1174
|
|
|
1175
|
+
// src/runtime/capabilities.ts
|
|
1176
|
+
import { readFile } from "fs/promises";
|
|
1177
|
+
async function resolveCapabilities(config, opts) {
|
|
1178
|
+
const configCaps = config.capabilities ?? {};
|
|
1179
|
+
const launchDeviceCaps = opts.platform === "android" || opts.platform === "ios" ? deviceStateToAppiumCapabilities(opts.platform, opts.launchOptions?.deviceState) : {};
|
|
1180
|
+
let platformCaps = {};
|
|
1181
|
+
if (opts.platform === "android" && config.platformCapabilities?.android) {
|
|
1182
|
+
platformCaps = config.platformCapabilities.android;
|
|
1183
|
+
} else if (opts.platform === "ios" && config.platformCapabilities?.ios) {
|
|
1184
|
+
platformCaps = config.platformCapabilities.ios;
|
|
1185
|
+
}
|
|
1186
|
+
let fileCaps = {};
|
|
1187
|
+
const capsFilePath = opts.capsPath ?? config.capabilitiesFile;
|
|
1188
|
+
if (capsFilePath) {
|
|
1189
|
+
const raw = await readFile(capsFilePath, "utf-8");
|
|
1190
|
+
fileCaps = JSON.parse(raw);
|
|
1191
|
+
}
|
|
1192
|
+
let cliCaps = {};
|
|
1193
|
+
if (opts.capsJson) {
|
|
1194
|
+
cliCaps = JSON.parse(opts.capsJson);
|
|
1195
|
+
}
|
|
1196
|
+
return { ...launchDeviceCaps, ...configCaps, ...platformCaps, ...fileCaps, ...cliCaps };
|
|
1197
|
+
}
|
|
1198
|
+
|
|
987
1199
|
// src/runtime/local.ts
|
|
988
1200
|
import { Effect as Effect4 } from "effect";
|
|
989
1201
|
async function safeCleanup(...fns) {
|
|
@@ -994,7 +1206,7 @@ async function safeCleanup(...fns) {
|
|
|
994
1206
|
}
|
|
995
1207
|
}
|
|
996
1208
|
}
|
|
997
|
-
function buildEngineConfig(appId, platform, parseFn, config) {
|
|
1209
|
+
function buildEngineConfig(appId, platform, parseFn, config, screenSize) {
|
|
998
1210
|
return {
|
|
999
1211
|
appId,
|
|
1000
1212
|
platform,
|
|
@@ -1002,22 +1214,29 @@ function buildEngineConfig(appId, platform, parseFn, config) {
|
|
|
1002
1214
|
parse: parseFn,
|
|
1003
1215
|
defaults: {
|
|
1004
1216
|
timeout: config.defaults?.waitTimeout,
|
|
1005
|
-
pollInterval: config.defaults?.pollInterval
|
|
1217
|
+
pollInterval: config.defaults?.pollInterval,
|
|
1218
|
+
settleTimeout: config.defaults?.settleTimeout,
|
|
1219
|
+
initialPollInterval: config.defaults?.initialPollInterval
|
|
1006
1220
|
},
|
|
1007
1221
|
waitForIdleTimeout: config.defaults?.waitForIdleTimeout,
|
|
1008
|
-
typingDelay: config.defaults?.typingDelay
|
|
1222
|
+
typingDelay: config.defaults?.typingDelay,
|
|
1223
|
+
hierarchyCacheTtl: config.defaults?.hierarchyCacheTtl,
|
|
1224
|
+
screenWidth: screenSize?.width,
|
|
1225
|
+
screenHeight: screenSize?.height
|
|
1009
1226
|
},
|
|
1010
1227
|
autoLaunch: true,
|
|
1011
1228
|
flowTimeout: config.defaults?.waitTimeout ? config.defaults.waitTimeout * 10 : 6e4,
|
|
1012
1229
|
artifactConfig: config.artifacts,
|
|
1013
1230
|
launchOptions: config.launchOptions,
|
|
1014
|
-
hooks: config.hooks
|
|
1231
|
+
hooks: config.hooks,
|
|
1232
|
+
storybook: platform === "web" ? config.execution?.web?.storybook : void 0,
|
|
1233
|
+
visualRegression: config.visualRegression
|
|
1015
1234
|
};
|
|
1016
1235
|
}
|
|
1017
1236
|
async function buildWebRuntime(config) {
|
|
1018
1237
|
const webUrl = config.apps?.web?.url ?? "http://localhost:3000";
|
|
1019
1238
|
const webExecution = config.execution?.web;
|
|
1020
|
-
const
|
|
1239
|
+
const driver = await Effect4.runPromise(
|
|
1021
1240
|
makePlaywrightDriver({
|
|
1022
1241
|
browser: webExecution?.browser,
|
|
1023
1242
|
headless: webExecution?.headless ?? true,
|
|
@@ -1026,7 +1245,7 @@ async function buildWebRuntime(config) {
|
|
|
1026
1245
|
verboseLogging: webExecution?.verboseLogging
|
|
1027
1246
|
})
|
|
1028
1247
|
);
|
|
1029
|
-
const
|
|
1248
|
+
const deviceInfo = await Effect4.runPromise(driver.getDeviceInfo());
|
|
1030
1249
|
return {
|
|
1031
1250
|
runtime: {
|
|
1032
1251
|
driver,
|
|
@@ -1036,7 +1255,10 @@ async function buildWebRuntime(config) {
|
|
|
1036
1255
|
mode: "local"
|
|
1037
1256
|
}
|
|
1038
1257
|
},
|
|
1039
|
-
engineConfig: buildEngineConfig(webUrl, "web", parseWebHierarchy, config
|
|
1258
|
+
engineConfig: buildEngineConfig(webUrl, "web", parseWebHierarchy, config, {
|
|
1259
|
+
width: deviceInfo.screenWidth,
|
|
1260
|
+
height: deviceInfo.screenHeight
|
|
1261
|
+
})
|
|
1040
1262
|
};
|
|
1041
1263
|
}
|
|
1042
1264
|
async function buildLocalAndroidRuntime(config, targetDevice, resolveFromConfig) {
|
|
@@ -1068,10 +1290,10 @@ async function buildLocalAndroidRuntime(config, targetDevice, resolveFromConfig)
|
|
|
1068
1290
|
const hostPort = allocatePort(8200);
|
|
1069
1291
|
try {
|
|
1070
1292
|
const conn = await setupUiAutomator2(device.serial, hostPort);
|
|
1071
|
-
const
|
|
1293
|
+
const driver = await Effect4.runPromise(
|
|
1072
1294
|
createUiAutomator2Driver(conn.host, conn.port, device.serial, packageName)
|
|
1073
1295
|
);
|
|
1074
|
-
const
|
|
1296
|
+
const deviceInfo = await Effect4.runPromise(driver.getDeviceInfo());
|
|
1075
1297
|
return {
|
|
1076
1298
|
runtime: {
|
|
1077
1299
|
driver,
|
|
@@ -1085,7 +1307,10 @@ async function buildLocalAndroidRuntime(config, targetDevice, resolveFromConfig)
|
|
|
1085
1307
|
deviceId: device.serial
|
|
1086
1308
|
}
|
|
1087
1309
|
},
|
|
1088
|
-
engineConfig: buildEngineConfig(packageName, "android", parseAndroidHierarchy, config
|
|
1310
|
+
engineConfig: buildEngineConfig(packageName, "android", parseAndroidHierarchy, config, {
|
|
1311
|
+
width: deviceInfo.screenWidth,
|
|
1312
|
+
height: deviceInfo.screenHeight
|
|
1313
|
+
})
|
|
1089
1314
|
};
|
|
1090
1315
|
} catch (e) {
|
|
1091
1316
|
console.log(`Android setup failed on ${device.serial}: ${e instanceof Error ? e.message : e}`);
|
|
@@ -1095,90 +1320,57 @@ async function buildLocalAndroidRuntime(config, targetDevice, resolveFromConfig)
|
|
|
1095
1320
|
async function buildLocalIOSRuntime(config, targetDevice, resolveFromConfig) {
|
|
1096
1321
|
const bundleId = config.apps?.ios?.bundleId ?? "";
|
|
1097
1322
|
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
1323
|
const signing = config.apps?.ios?.signing;
|
|
1138
|
-
|
|
1324
|
+
const snapshotMaxDepth = config.defaults?.snapshotMaxDepth ?? 100;
|
|
1325
|
+
const createIOSRuntime = async (deviceId, conn, simulatorUdid) => {
|
|
1326
|
+
const driver = await Effect4.runPromise(
|
|
1327
|
+
createWDADriver(conn.host, conn.port, bundleId, simulatorUdid, snapshotMaxDepth)
|
|
1328
|
+
);
|
|
1329
|
+
const deviceInfo = await Effect4.runPromise(driver.getDeviceInfo());
|
|
1330
|
+
return {
|
|
1331
|
+
runtime: {
|
|
1332
|
+
driver,
|
|
1333
|
+
cleanup: () => safeCleanup(
|
|
1334
|
+
() => Effect4.runPromise(driver.killApp("")),
|
|
1335
|
+
() => conn.cleanup?.() ?? Promise.resolve()
|
|
1336
|
+
),
|
|
1337
|
+
metadata: {
|
|
1338
|
+
platform: "ios",
|
|
1339
|
+
mode: "local",
|
|
1340
|
+
deviceId
|
|
1341
|
+
}
|
|
1342
|
+
},
|
|
1343
|
+
engineConfig: buildEngineConfig(bundleId, "ios", parseIOSHierarchy, config, {
|
|
1344
|
+
width: deviceInfo.screenWidth,
|
|
1345
|
+
height: deviceInfo.screenHeight
|
|
1346
|
+
})
|
|
1347
|
+
};
|
|
1348
|
+
};
|
|
1349
|
+
const connectPhysicalRuntime = async (physicalDevice2, allowSimulatorFallback) => {
|
|
1139
1350
|
let conn;
|
|
1140
1351
|
try {
|
|
1141
|
-
console.log(`Found physical iOS device: ${
|
|
1352
|
+
console.log(`Found physical iOS device: ${physicalDevice2.name} (${physicalDevice2.udid})`);
|
|
1142
1353
|
if (iosAppPath && bundleId) {
|
|
1143
1354
|
ensureAppInstalled({
|
|
1144
|
-
udid:
|
|
1355
|
+
udid: physicalDevice2.udid,
|
|
1145
1356
|
bundleId,
|
|
1146
1357
|
appPath: resolveFromConfig(iosAppPath),
|
|
1147
1358
|
isPhysicalDevice: true
|
|
1148
1359
|
});
|
|
1149
1360
|
}
|
|
1150
1361
|
if (signing?.teamId) {
|
|
1151
|
-
const { setupWDAForDevice } = await import("./installer-
|
|
1362
|
+
const { setupWDAForDevice } = await import("./installer-W5DITECS.js");
|
|
1152
1363
|
const wdaPort2 = allocatePort(8100);
|
|
1153
1364
|
conn = await setupWDAForDevice(
|
|
1154
|
-
|
|
1365
|
+
physicalDevice2.udid,
|
|
1155
1366
|
wdaPort2,
|
|
1156
1367
|
signing.teamId,
|
|
1157
1368
|
signing.signingIdentity
|
|
1158
1369
|
);
|
|
1159
1370
|
} else {
|
|
1160
|
-
conn = connectPhysicalDevice(
|
|
1371
|
+
conn = connectPhysicalDevice(physicalDevice2.udid);
|
|
1161
1372
|
}
|
|
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
|
-
};
|
|
1373
|
+
return await createIOSRuntime(physicalDevice2.udid, conn);
|
|
1182
1374
|
} catch (e) {
|
|
1183
1375
|
if (conn?.cleanup) {
|
|
1184
1376
|
try {
|
|
@@ -1189,9 +1381,46 @@ async function buildLocalIOSRuntime(config, targetDevice, resolveFromConfig) {
|
|
|
1189
1381
|
);
|
|
1190
1382
|
}
|
|
1191
1383
|
}
|
|
1384
|
+
if (!allowSimulatorFallback) {
|
|
1385
|
+
console.log(
|
|
1386
|
+
`iOS setup failed for device ${physicalDevice2.udid}: ${e instanceof Error ? e.message : e}`
|
|
1387
|
+
);
|
|
1388
|
+
return null;
|
|
1389
|
+
}
|
|
1192
1390
|
console.log(
|
|
1193
|
-
`Physical device setup failed (${
|
|
1391
|
+
`Physical device setup failed (${physicalDevice2.name}): ${e instanceof Error ? e.message : e}. Falling back to simulator.`
|
|
1194
1392
|
);
|
|
1393
|
+
return null;
|
|
1394
|
+
}
|
|
1395
|
+
};
|
|
1396
|
+
if (targetDevice?.platform === "ios" && targetDevice.type === "simulator") {
|
|
1397
|
+
if (iosAppPath && bundleId) {
|
|
1398
|
+
ensureAppInstalled({
|
|
1399
|
+
udid: targetDevice.id,
|
|
1400
|
+
bundleId,
|
|
1401
|
+
appPath: resolveFromConfig(iosAppPath),
|
|
1402
|
+
isPhysicalDevice: false
|
|
1403
|
+
});
|
|
1404
|
+
}
|
|
1405
|
+
const wdaPort2 = allocatePort(8100);
|
|
1406
|
+
try {
|
|
1407
|
+
const conn = await setupWDA(targetDevice.id, wdaPort2);
|
|
1408
|
+
return await createIOSRuntime(targetDevice.id, conn, targetDevice.id);
|
|
1409
|
+
} catch (e) {
|
|
1410
|
+
console.log(
|
|
1411
|
+
`iOS setup failed for device ${targetDevice.id}: ${e instanceof Error ? e.message : e}`
|
|
1412
|
+
);
|
|
1413
|
+
return null;
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
if (targetDevice?.platform === "ios" && targetDevice.type === "device") {
|
|
1417
|
+
return connectPhysicalRuntime({ udid: targetDevice.id, name: targetDevice.name }, false);
|
|
1418
|
+
}
|
|
1419
|
+
const physicalDevice = firstIOSPhysicalDevice();
|
|
1420
|
+
if (physicalDevice) {
|
|
1421
|
+
const runtime = await connectPhysicalRuntime(physicalDevice, true);
|
|
1422
|
+
if (runtime) {
|
|
1423
|
+
return runtime;
|
|
1195
1424
|
}
|
|
1196
1425
|
}
|
|
1197
1426
|
const simulator = ensureIOSSimulator(bundleId);
|
|
@@ -1210,25 +1439,7 @@ async function buildLocalIOSRuntime(config, targetDevice, resolveFromConfig) {
|
|
|
1210
1439
|
const wdaPort = allocatePort(8100);
|
|
1211
1440
|
try {
|
|
1212
1441
|
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
|
-
};
|
|
1442
|
+
return await createIOSRuntime(simulator.udid, conn, simulator.udid);
|
|
1232
1443
|
} catch (e) {
|
|
1233
1444
|
console.log(`iOS setup failed on ${simulator.name}: ${e instanceof Error ? e.message : e}`);
|
|
1234
1445
|
return null;
|
|
@@ -1241,10 +1452,25 @@ import { Effect as Effect7 } from "effect";
|
|
|
1241
1452
|
// src/drivers/appium/client.ts
|
|
1242
1453
|
var AppiumClient = class {
|
|
1243
1454
|
baseUrl;
|
|
1455
|
+
authHeader = null;
|
|
1244
1456
|
sessionId = null;
|
|
1245
1457
|
sessionCaps = {};
|
|
1246
1458
|
constructor(serverUrl) {
|
|
1247
|
-
|
|
1459
|
+
const parsed = new URL(serverUrl);
|
|
1460
|
+
if (parsed.username || parsed.password) {
|
|
1461
|
+
const username = decodeURIComponent(parsed.username);
|
|
1462
|
+
const password = decodeURIComponent(parsed.password);
|
|
1463
|
+
this.authHeader = `Basic ${Buffer.from(`${username}:${password}`).toString("base64")}`;
|
|
1464
|
+
parsed.username = "";
|
|
1465
|
+
parsed.password = "";
|
|
1466
|
+
}
|
|
1467
|
+
this.baseUrl = parsed.toString().replace(/\/+$/, "");
|
|
1468
|
+
}
|
|
1469
|
+
createHeaders() {
|
|
1470
|
+
return {
|
|
1471
|
+
"Content-Type": "application/json",
|
|
1472
|
+
...this.authHeader ? { Authorization: this.authHeader } : {}
|
|
1473
|
+
};
|
|
1248
1474
|
}
|
|
1249
1475
|
// ---------------------------------------------------------------------------
|
|
1250
1476
|
// HTTP helpers
|
|
@@ -1253,7 +1479,7 @@ var AppiumClient = class {
|
|
|
1253
1479
|
const url = `${this.baseUrl}${path}`;
|
|
1254
1480
|
const init = {
|
|
1255
1481
|
method,
|
|
1256
|
-
headers:
|
|
1482
|
+
headers: this.createHeaders()
|
|
1257
1483
|
};
|
|
1258
1484
|
if (body !== void 0) {
|
|
1259
1485
|
init.body = JSON.stringify(body);
|
|
@@ -1294,7 +1520,7 @@ var AppiumClient = class {
|
|
|
1294
1520
|
};
|
|
1295
1521
|
const res = await fetch(`${this.baseUrl}/session`, {
|
|
1296
1522
|
method: "POST",
|
|
1297
|
-
headers:
|
|
1523
|
+
headers: this.createHeaders(),
|
|
1298
1524
|
body: JSON.stringify(body)
|
|
1299
1525
|
});
|
|
1300
1526
|
const text = await res.text();
|
|
@@ -1311,7 +1537,7 @@ var AppiumClient = class {
|
|
|
1311
1537
|
const value = parsed["value"];
|
|
1312
1538
|
const sessionId = value?.["sessionId"] ?? parsed["sessionId"];
|
|
1313
1539
|
if (!sessionId) {
|
|
1314
|
-
throw new Error(
|
|
1540
|
+
throw new Error(`Appium: no sessionId in session response: ${text}`);
|
|
1315
1541
|
}
|
|
1316
1542
|
this.sessionId = sessionId;
|
|
1317
1543
|
this.sessionCaps = value?.["capabilities"] ?? {};
|
|
@@ -1322,7 +1548,7 @@ var AppiumClient = class {
|
|
|
1322
1548
|
const path = `/session/${this.sessionId}`;
|
|
1323
1549
|
this.sessionId = null;
|
|
1324
1550
|
this.sessionCaps = {};
|
|
1325
|
-
await fetch(`${this.baseUrl}${path}`, { method: "DELETE" });
|
|
1551
|
+
await fetch(`${this.baseUrl}${path}`, { method: "DELETE", headers: this.createHeaders() });
|
|
1326
1552
|
}
|
|
1327
1553
|
getSessionId() {
|
|
1328
1554
|
return this.sessionId;
|
|
@@ -1352,7 +1578,23 @@ var AppiumClient = class {
|
|
|
1352
1578
|
|
|
1353
1579
|
// src/drivers/appium/android.ts
|
|
1354
1580
|
import { Effect as Effect5 } from "effect";
|
|
1355
|
-
|
|
1581
|
+
|
|
1582
|
+
// src/drivers/appium/window-size.ts
|
|
1583
|
+
async function getAppiumWindowSize(client) {
|
|
1584
|
+
try {
|
|
1585
|
+
return await client.request("GET", client.sessionPath("/window/size"));
|
|
1586
|
+
} catch (error) {
|
|
1587
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1588
|
+
if (!message.includes("/window/size") || !message.includes("-> 404:")) {
|
|
1589
|
+
throw error;
|
|
1590
|
+
}
|
|
1591
|
+
const rect = await client.request("GET", client.sessionPath("/window/rect"));
|
|
1592
|
+
return { width: rect.width, height: rect.height };
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1596
|
+
// src/drivers/appium/android.ts
|
|
1597
|
+
function createAppiumAndroidDriver(client, defaultBundleId) {
|
|
1356
1598
|
const service = {
|
|
1357
1599
|
// -----------------------------------------------------------------------
|
|
1358
1600
|
// Hierarchy
|
|
@@ -1365,21 +1607,57 @@ function createAppiumAndroidDriver(client) {
|
|
|
1365
1607
|
// Coordinate-level actions
|
|
1366
1608
|
// -----------------------------------------------------------------------
|
|
1367
1609
|
tapAtCoordinate: (x, y) => Effect5.tryPromise({
|
|
1368
|
-
try: () => client.request("POST", client.sessionPath("/
|
|
1369
|
-
|
|
1610
|
+
try: () => client.request("POST", client.sessionPath("/actions"), {
|
|
1611
|
+
actions: [
|
|
1612
|
+
{
|
|
1613
|
+
type: "pointer",
|
|
1614
|
+
id: "finger1",
|
|
1615
|
+
parameters: { pointerType: "touch" },
|
|
1616
|
+
actions: [
|
|
1617
|
+
{ type: "pointerMove", duration: 0, x, y },
|
|
1618
|
+
{ type: "pointerDown", button: 0 },
|
|
1619
|
+
{ type: "pointerUp", button: 0 }
|
|
1620
|
+
]
|
|
1621
|
+
}
|
|
1622
|
+
]
|
|
1370
1623
|
}),
|
|
1371
1624
|
catch: (e) => new DriverError({ message: `Tap failed: ${e}` })
|
|
1372
1625
|
}),
|
|
1373
1626
|
doubleTapAtCoordinate: (x, y) => Effect5.tryPromise({
|
|
1374
|
-
try: () =>
|
|
1375
|
-
|
|
1376
|
-
|
|
1627
|
+
try: async () => {
|
|
1628
|
+
const tapSequence = [
|
|
1629
|
+
{
|
|
1630
|
+
type: "pointer",
|
|
1631
|
+
id: "finger1",
|
|
1632
|
+
parameters: { pointerType: "touch" },
|
|
1633
|
+
actions: [
|
|
1634
|
+
{ type: "pointerMove", duration: 0, x, y },
|
|
1635
|
+
{ type: "pointerDown", button: 0 },
|
|
1636
|
+
{ type: "pointerUp", button: 0 }
|
|
1637
|
+
]
|
|
1638
|
+
}
|
|
1639
|
+
];
|
|
1640
|
+
await client.request("POST", client.sessionPath("/actions"), { actions: tapSequence });
|
|
1641
|
+
await new Promise((resolve4) => setTimeout(resolve4, 100));
|
|
1642
|
+
await client.request("POST", client.sessionPath("/actions"), { actions: tapSequence });
|
|
1643
|
+
},
|
|
1377
1644
|
catch: (e) => new DriverError({ message: `Double tap failed: ${e}` })
|
|
1378
1645
|
}),
|
|
1379
1646
|
longPressAtCoordinate: (x, y, duration) => Effect5.tryPromise({
|
|
1380
|
-
try: () => client.request("POST", client.sessionPath("/
|
|
1381
|
-
|
|
1382
|
-
|
|
1647
|
+
try: () => client.request("POST", client.sessionPath("/actions"), {
|
|
1648
|
+
actions: [
|
|
1649
|
+
{
|
|
1650
|
+
type: "pointer",
|
|
1651
|
+
id: "finger1",
|
|
1652
|
+
parameters: { pointerType: "touch" },
|
|
1653
|
+
actions: [
|
|
1654
|
+
{ type: "pointerMove", duration: 0, x, y },
|
|
1655
|
+
{ type: "pointerDown", button: 0 },
|
|
1656
|
+
{ type: "pause", duration },
|
|
1657
|
+
{ type: "pointerUp", button: 0 }
|
|
1658
|
+
]
|
|
1659
|
+
}
|
|
1660
|
+
]
|
|
1383
1661
|
}),
|
|
1384
1662
|
catch: (e) => new DriverError({ message: `Long press failed: ${e}` })
|
|
1385
1663
|
}),
|
|
@@ -1445,10 +1723,7 @@ function createAppiumAndroidDriver(client) {
|
|
|
1445
1723
|
}),
|
|
1446
1724
|
getDeviceInfo: () => Effect5.tryPromise({
|
|
1447
1725
|
try: async () => {
|
|
1448
|
-
const size = await client
|
|
1449
|
-
"GET",
|
|
1450
|
-
client.sessionPath("/window/size")
|
|
1451
|
-
);
|
|
1726
|
+
const size = await getAppiumWindowSize(client);
|
|
1452
1727
|
const caps = client.getSessionCaps();
|
|
1453
1728
|
return {
|
|
1454
1729
|
platform: "android",
|
|
@@ -1474,16 +1749,7 @@ function createAppiumAndroidDriver(client) {
|
|
|
1474
1749
|
});
|
|
1475
1750
|
} catch {
|
|
1476
1751
|
}
|
|
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
|
-
});
|
|
1752
|
+
await client.executeScript("mobile: clearApp", [{ appId: bundleId }]);
|
|
1487
1753
|
}
|
|
1488
1754
|
if (opts?.clearKeychain) {
|
|
1489
1755
|
console.warn("clearKeychain is not supported on Android, skipping.");
|
|
@@ -1493,9 +1759,18 @@ function createAppiumAndroidDriver(client) {
|
|
|
1493
1759
|
message: "launchArguments are not supported in Appium Android mode. Remove launchArguments from your config or use local mode."
|
|
1494
1760
|
});
|
|
1495
1761
|
}
|
|
1762
|
+
if (hasLaunchDeviceState(opts?.deviceState)) {
|
|
1763
|
+
console.warn(
|
|
1764
|
+
"deviceState launch overrides are not supported during Appium Android relaunches. Set launchOptions.deviceState in config to apply Android language/locale/timeZone at session start."
|
|
1765
|
+
);
|
|
1766
|
+
}
|
|
1496
1767
|
if (opts?.deepLink) {
|
|
1497
|
-
await client.
|
|
1498
|
-
url: opts.deepLink
|
|
1768
|
+
await client.executeScript("mobile: deepLink", [
|
|
1769
|
+
{ url: opts.deepLink, package: bundleId }
|
|
1770
|
+
]);
|
|
1771
|
+
} else {
|
|
1772
|
+
await client.request("POST", client.sessionPath("/appium/device/activate_app"), {
|
|
1773
|
+
appId: bundleId
|
|
1499
1774
|
});
|
|
1500
1775
|
}
|
|
1501
1776
|
},
|
|
@@ -1521,9 +1796,7 @@ function createAppiumAndroidDriver(client) {
|
|
|
1521
1796
|
});
|
|
1522
1797
|
} catch {
|
|
1523
1798
|
}
|
|
1524
|
-
await client.
|
|
1525
|
-
appId: bundleId
|
|
1526
|
-
});
|
|
1799
|
+
await client.executeScript("mobile: clearApp", [{ appId: bundleId }]);
|
|
1527
1800
|
},
|
|
1528
1801
|
catch: (e) => new DriverError({ message: `Clear app state failed: ${e}` })
|
|
1529
1802
|
}),
|
|
@@ -1531,7 +1804,11 @@ function createAppiumAndroidDriver(client) {
|
|
|
1531
1804
|
// Navigation
|
|
1532
1805
|
// -----------------------------------------------------------------------
|
|
1533
1806
|
openLink: (url) => Effect5.tryPromise({
|
|
1534
|
-
try: () =>
|
|
1807
|
+
try: () => {
|
|
1808
|
+
const args = { url };
|
|
1809
|
+
if (defaultBundleId) args.package = defaultBundleId;
|
|
1810
|
+
return client.executeScript("mobile: deepLink", [args]);
|
|
1811
|
+
},
|
|
1535
1812
|
catch: (e) => new DriverError({ message: `Open link failed: ${e}` })
|
|
1536
1813
|
}),
|
|
1537
1814
|
back: () => Effect5.tryPromise({
|
|
@@ -1707,10 +1984,7 @@ function createAppiumIOSDriver(client) {
|
|
|
1707
1984
|
}),
|
|
1708
1985
|
getDeviceInfo: () => Effect6.tryPromise({
|
|
1709
1986
|
try: async () => {
|
|
1710
|
-
const size = await client
|
|
1711
|
-
"GET",
|
|
1712
|
-
client.sessionPath("/window/size")
|
|
1713
|
-
);
|
|
1987
|
+
const size = await getAppiumWindowSize(client);
|
|
1714
1988
|
const caps = client.getSessionCaps();
|
|
1715
1989
|
return {
|
|
1716
1990
|
platform: "ios",
|
|
@@ -1729,6 +2003,7 @@ function createAppiumIOSDriver(client) {
|
|
|
1729
2003
|
// -----------------------------------------------------------------------
|
|
1730
2004
|
launchApp: (bundleId, opts) => Effect6.tryPromise({
|
|
1731
2005
|
try: async () => {
|
|
2006
|
+
const launchConfig = buildIOSLaunchConfiguration(opts);
|
|
1732
2007
|
if (opts?.clearState) {
|
|
1733
2008
|
try {
|
|
1734
2009
|
await client.request("POST", client.sessionPath("/appium/device/terminate_app"), {
|
|
@@ -1736,13 +2011,15 @@ function createAppiumIOSDriver(client) {
|
|
|
1736
2011
|
});
|
|
1737
2012
|
} catch {
|
|
1738
2013
|
}
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
})
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
2014
|
+
try {
|
|
2015
|
+
await client.executeScript("mobile: clearApp", [{ bundleId }]);
|
|
2016
|
+
} catch (e) {
|
|
2017
|
+
console.warn(
|
|
2018
|
+
`mobile: clearApp unavailable on this provider; falling back to terminate-only. In-memory state will still be reset. (${e})`
|
|
2019
|
+
);
|
|
2020
|
+
}
|
|
2021
|
+
}
|
|
2022
|
+
if (!launchConfig) {
|
|
1746
2023
|
await client.request("POST", client.sessionPath("/appium/device/activate_app"), {
|
|
1747
2024
|
appId: bundleId
|
|
1748
2025
|
});
|
|
@@ -1752,10 +2029,20 @@ function createAppiumIOSDriver(client) {
|
|
|
1752
2029
|
"clearKeychain is not available via Appium on iOS. Use local mode with xcrun simctl for keychain operations."
|
|
1753
2030
|
);
|
|
1754
2031
|
}
|
|
1755
|
-
if (
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
2032
|
+
if (launchConfig) {
|
|
2033
|
+
try {
|
|
2034
|
+
await client.request("POST", client.sessionPath("/appium/device/terminate_app"), {
|
|
2035
|
+
appId: bundleId
|
|
2036
|
+
});
|
|
2037
|
+
} catch {
|
|
2038
|
+
}
|
|
2039
|
+
await client.executeScript("mobile: launchApp", [
|
|
2040
|
+
{
|
|
2041
|
+
bundleId,
|
|
2042
|
+
arguments: launchConfig.arguments,
|
|
2043
|
+
environment: launchConfig.environment
|
|
2044
|
+
}
|
|
2045
|
+
]);
|
|
1759
2046
|
}
|
|
1760
2047
|
if (opts?.deepLink) {
|
|
1761
2048
|
await client.request("POST", client.sessionPath("/url"), {
|
|
@@ -1785,9 +2072,7 @@ function createAppiumIOSDriver(client) {
|
|
|
1785
2072
|
});
|
|
1786
2073
|
} catch {
|
|
1787
2074
|
}
|
|
1788
|
-
await client.
|
|
1789
|
-
appId: bundleId
|
|
1790
|
-
});
|
|
2075
|
+
await client.executeScript("mobile: clearApp", [{ bundleId }]);
|
|
1791
2076
|
},
|
|
1792
2077
|
catch: (e) => new DriverError({
|
|
1793
2078
|
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.`
|
|
@@ -1836,13 +2121,14 @@ function createAppiumIOSDriver(client) {
|
|
|
1836
2121
|
|
|
1837
2122
|
// src/runtime/appium.ts
|
|
1838
2123
|
async function buildAppiumAndroidRuntime(config, appiumUrl, caps) {
|
|
2124
|
+
const appId = caps["appium:appPackage"] ?? config.apps?.android?.packageName ?? "";
|
|
1839
2125
|
const client = new AppiumClient(appiumUrl);
|
|
1840
2126
|
await client.createSession({
|
|
1841
2127
|
platformName: "Android",
|
|
1842
2128
|
...caps
|
|
1843
2129
|
});
|
|
1844
|
-
const
|
|
1845
|
-
const
|
|
2130
|
+
const driver = await Effect7.runPromise(createAppiumAndroidDriver(client, appId || void 0));
|
|
2131
|
+
const deviceInfo = await Effect7.runPromise(driver.getDeviceInfo());
|
|
1846
2132
|
const sessionId = client.getSessionId() ?? void 0;
|
|
1847
2133
|
const sessionCaps = client.getSessionCaps();
|
|
1848
2134
|
const detectedProvider = detectProvider(appiumUrl);
|
|
@@ -1865,35 +2151,50 @@ async function buildAppiumAndroidRuntime(config, appiumUrl, caps) {
|
|
|
1865
2151
|
}
|
|
1866
2152
|
},
|
|
1867
2153
|
engineConfig: {
|
|
1868
|
-
appId
|
|
2154
|
+
appId,
|
|
1869
2155
|
platform: "android",
|
|
1870
2156
|
coordinatorConfig: {
|
|
1871
2157
|
parse: parseAndroidHierarchy,
|
|
1872
2158
|
defaults: {
|
|
1873
2159
|
timeout: config.defaults?.waitTimeout,
|
|
1874
|
-
pollInterval: config.defaults?.pollInterval
|
|
2160
|
+
pollInterval: config.defaults?.pollInterval,
|
|
2161
|
+
settleTimeout: config.defaults?.settleTimeout,
|
|
2162
|
+
initialPollInterval: config.defaults?.initialPollInterval
|
|
1875
2163
|
},
|
|
1876
2164
|
waitForIdleTimeout: config.defaults?.waitForIdleTimeout,
|
|
1877
|
-
typingDelay: config.defaults?.typingDelay
|
|
2165
|
+
typingDelay: config.defaults?.typingDelay,
|
|
2166
|
+
hierarchyCacheTtl: config.defaults?.hierarchyCacheTtl,
|
|
2167
|
+
screenWidth: deviceInfo.screenWidth,
|
|
2168
|
+
screenHeight: deviceInfo.screenHeight
|
|
1878
2169
|
},
|
|
1879
2170
|
autoLaunch: false,
|
|
1880
2171
|
// Appium manages app lifecycle
|
|
1881
2172
|
flowTimeout: config.defaults?.waitTimeout ? config.defaults.waitTimeout * 10 : 6e4,
|
|
1882
2173
|
artifactConfig: config.artifacts,
|
|
1883
2174
|
launchOptions: config.launchOptions,
|
|
1884
|
-
hooks: config.hooks
|
|
2175
|
+
hooks: config.hooks,
|
|
2176
|
+
visualRegression: config.visualRegression
|
|
1885
2177
|
}
|
|
1886
2178
|
};
|
|
1887
2179
|
}
|
|
1888
2180
|
async function buildAppiumIOSRuntime(config, appiumUrl, caps) {
|
|
2181
|
+
const appId = caps["appium:bundleId"] ?? config.apps?.ios?.bundleId ?? "";
|
|
1889
2182
|
const client = new AppiumClient(appiumUrl);
|
|
1890
2183
|
await client.createSession({
|
|
1891
2184
|
platformName: "iOS",
|
|
1892
2185
|
"appium:automationName": "XCUITest",
|
|
1893
2186
|
...caps
|
|
1894
2187
|
});
|
|
1895
|
-
const
|
|
1896
|
-
|
|
2188
|
+
const snapshotMaxDepth = config.defaults?.snapshotMaxDepth ?? 100;
|
|
2189
|
+
try {
|
|
2190
|
+
await client.request("POST", client.sessionPath("/appium/settings"), {
|
|
2191
|
+
settings: { snapshotMaxDepth }
|
|
2192
|
+
});
|
|
2193
|
+
} catch (e) {
|
|
2194
|
+
console.warn(`Failed to set snapshotMaxDepth (continuing): ${e}`);
|
|
2195
|
+
}
|
|
2196
|
+
const driver = await Effect7.runPromise(createAppiumIOSDriver(client));
|
|
2197
|
+
const deviceInfo = await Effect7.runPromise(driver.getDeviceInfo());
|
|
1897
2198
|
const sessionId = client.getSessionId() ?? void 0;
|
|
1898
2199
|
const sessionCaps = client.getSessionCaps();
|
|
1899
2200
|
const detectedProvider = detectProvider(appiumUrl);
|
|
@@ -1916,250 +2217,178 @@ async function buildAppiumIOSRuntime(config, appiumUrl, caps) {
|
|
|
1916
2217
|
}
|
|
1917
2218
|
},
|
|
1918
2219
|
engineConfig: {
|
|
1919
|
-
appId
|
|
2220
|
+
appId,
|
|
1920
2221
|
platform: "ios",
|
|
1921
2222
|
coordinatorConfig: {
|
|
1922
2223
|
parse: parseIOSHierarchy,
|
|
1923
2224
|
defaults: {
|
|
1924
2225
|
timeout: config.defaults?.waitTimeout,
|
|
1925
|
-
pollInterval: config.defaults?.pollInterval
|
|
2226
|
+
pollInterval: config.defaults?.pollInterval,
|
|
2227
|
+
settleTimeout: config.defaults?.settleTimeout,
|
|
2228
|
+
initialPollInterval: config.defaults?.initialPollInterval
|
|
1926
2229
|
},
|
|
1927
2230
|
waitForIdleTimeout: config.defaults?.waitForIdleTimeout,
|
|
1928
|
-
typingDelay: config.defaults?.typingDelay
|
|
2231
|
+
typingDelay: config.defaults?.typingDelay,
|
|
2232
|
+
hierarchyCacheTtl: config.defaults?.hierarchyCacheTtl,
|
|
2233
|
+
screenWidth: deviceInfo.screenWidth,
|
|
2234
|
+
screenHeight: deviceInfo.screenHeight
|
|
1929
2235
|
},
|
|
1930
2236
|
autoLaunch: false,
|
|
1931
2237
|
// Appium manages app lifecycle
|
|
1932
2238
|
flowTimeout: config.defaults?.waitTimeout ? config.defaults.waitTimeout * 10 : 6e4,
|
|
1933
2239
|
artifactConfig: config.artifacts,
|
|
1934
2240
|
launchOptions: config.launchOptions,
|
|
1935
|
-
hooks: config.hooks
|
|
2241
|
+
hooks: config.hooks,
|
|
2242
|
+
visualRegression: config.visualRegression
|
|
1936
2243
|
}
|
|
1937
2244
|
};
|
|
1938
2245
|
}
|
|
1939
2246
|
|
|
1940
2247
|
// src/cli/iteration.ts
|
|
1941
2248
|
import { execFileSync } from "child_process";
|
|
1942
|
-
import {
|
|
1943
|
-
import { dirname, join as
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
return join2(outputDir, ".spana", "last-run.json");
|
|
1947
|
-
}
|
|
2249
|
+
import { readFile as readFile2, writeFile } from "fs/promises";
|
|
2250
|
+
import { dirname, join as join4, resolve } from "path";
|
|
2251
|
+
import { mkdirSync as mkdirSync2, existsSync as existsSync2 } from "fs";
|
|
2252
|
+
var SCHEMA_VERSION = 1;
|
|
1948
2253
|
function buildLastRunState(options) {
|
|
1949
|
-
const
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
2254
|
+
const { flowDir, platforms, results, sourcePathsByFlowName } = options;
|
|
2255
|
+
const failedFlowNames = [];
|
|
2256
|
+
const failedSourcePaths = [];
|
|
2257
|
+
const flows = [];
|
|
2258
|
+
for (const result of results) {
|
|
2259
|
+
const passed = result.status === "passed";
|
|
2260
|
+
const sourcePath = sourcePathsByFlowName.get(result.name);
|
|
2261
|
+
flows.push({ name: result.name, platform: result.platform, passed, sourcePath });
|
|
2262
|
+
if (!passed) {
|
|
2263
|
+
if (!failedFlowNames.includes(result.name)) failedFlowNames.push(result.name);
|
|
2264
|
+
if (sourcePath && !failedSourcePaths.includes(sourcePath)) failedSourcePaths.push(sourcePath);
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
1961
2267
|
return {
|
|
1962
|
-
schemaVersion:
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
platforms: [...new Set(options.platforms)],
|
|
2268
|
+
schemaVersion: SCHEMA_VERSION,
|
|
2269
|
+
flowDir,
|
|
2270
|
+
platforms,
|
|
1966
2271
|
failedFlowNames,
|
|
1967
2272
|
failedSourcePaths,
|
|
1968
2273
|
flows
|
|
1969
2274
|
};
|
|
1970
2275
|
}
|
|
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
2276
|
async function readLastRunState(filePath) {
|
|
2001
2277
|
try {
|
|
2002
|
-
const raw = await
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
throw error;
|
|
2278
|
+
const raw = await readFile2(filePath, "utf8");
|
|
2279
|
+
const parsed = JSON.parse(raw);
|
|
2280
|
+
if (parsed.schemaVersion !== SCHEMA_VERSION) return null;
|
|
2281
|
+
return parsed;
|
|
2282
|
+
} catch {
|
|
2283
|
+
return null;
|
|
2009
2284
|
}
|
|
2010
2285
|
}
|
|
2011
2286
|
async function writeLastRunState(filePath, state) {
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2287
|
+
const dir = dirname(filePath);
|
|
2288
|
+
if (!existsSync2(dir)) mkdirSync2(dir, { recursive: true });
|
|
2289
|
+
await writeFile(filePath, JSON.stringify(state, null, 2), "utf8");
|
|
2015
2290
|
}
|
|
2016
|
-
function
|
|
2017
|
-
|
|
2291
|
+
function getGitChangedFiles(cwd) {
|
|
2292
|
+
const tracked = execFileSync("git", ["diff", "--name-only"], { cwd, encoding: "utf8" });
|
|
2293
|
+
const untracked = execFileSync("git", ["ls-files", "--others", "--exclude-standard"], {
|
|
2294
|
+
cwd,
|
|
2295
|
+
encoding: "utf8"
|
|
2296
|
+
});
|
|
2297
|
+
return [...parseGitPathList(cwd, tracked), ...parseGitPathList(cwd, untracked)];
|
|
2018
2298
|
}
|
|
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
|
-
}
|
|
2299
|
+
function parseGitPathList(cwd, output) {
|
|
2300
|
+
return output.split("\n").map((line) => line.trim()).filter((line) => line.length > 0).map((line) => resolve(cwd, line));
|
|
2037
2301
|
}
|
|
2038
2302
|
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) {
|
|
2303
|
+
const { flowPaths, changedFiles, stepPaths, configPath } = options;
|
|
2304
|
+
const changedSet = new Set(changedFiles);
|
|
2305
|
+
if (configPath && changedSet.has(resolve(configPath))) {
|
|
2306
|
+
return { mode: "all", reason: "Config changed \u2014 running all flows.", flowPaths };
|
|
2307
|
+
}
|
|
2308
|
+
const stepChanged = stepPaths.some((s) => changedSet.has(s));
|
|
2309
|
+
if (stepChanged) {
|
|
2310
|
+
const featureFlows = flowPaths.filter((p) => p.endsWith(".feature"));
|
|
2311
|
+
if (featureFlows.length > 0) {
|
|
2062
2312
|
return {
|
|
2063
2313
|
mode: "targeted",
|
|
2064
|
-
reason:
|
|
2065
|
-
flowPaths:
|
|
2314
|
+
reason: `Step definitions changed \u2014 running ${featureFlows.length} feature flow(s).`,
|
|
2315
|
+
flowPaths: featureFlows
|
|
2066
2316
|
};
|
|
2067
2317
|
}
|
|
2318
|
+
}
|
|
2319
|
+
const changedFlows = flowPaths.filter((p) => changedSet.has(p));
|
|
2320
|
+
if (changedFlows.length > 0) {
|
|
2068
2321
|
return {
|
|
2069
|
-
mode: "
|
|
2070
|
-
reason:
|
|
2071
|
-
flowPaths:
|
|
2322
|
+
mode: "targeted",
|
|
2323
|
+
reason: `Running ${changedFlows.length} changed flow(s).`,
|
|
2324
|
+
flowPaths: changedFlows
|
|
2072
2325
|
};
|
|
2073
2326
|
}
|
|
2074
|
-
return {
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
};
|
|
2327
|
+
return { mode: "none", reason: "No changed flow files detected.", flowPaths: [] };
|
|
2328
|
+
}
|
|
2329
|
+
function createLastRunStatePath(outputDir) {
|
|
2330
|
+
return join4(outputDir, ".spana", "last-run.json");
|
|
2079
2331
|
}
|
|
2080
2332
|
|
|
2081
2333
|
// src/cli/watch-mode.ts
|
|
2082
2334
|
import { readdir, stat } from "fs/promises";
|
|
2083
2335
|
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);
|
|
2336
|
+
var WATCH_EXTENSIONS = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".json", ".feature"]);
|
|
2337
|
+
var IGNORE_DIRS = /* @__PURE__ */ new Set([".git", "node_modules", "spana-output", "dist", "coverage"]);
|
|
2338
|
+
function collectWatchRoots(flowDir, configPath) {
|
|
2339
|
+
const roots = [resolve2(flowDir)];
|
|
2094
2340
|
if (configPath) {
|
|
2095
|
-
|
|
2341
|
+
const configDir = dirname2(resolve2(configPath));
|
|
2342
|
+
if (!roots.includes(configDir)) roots.push(configDir);
|
|
2096
2343
|
}
|
|
2097
|
-
return
|
|
2098
|
-
}
|
|
2099
|
-
function shouldTrackFile(filePath) {
|
|
2100
|
-
return WATCHABLE_EXTENSIONS.has(extname(filePath));
|
|
2344
|
+
return roots;
|
|
2101
2345
|
}
|
|
2102
|
-
async function
|
|
2103
|
-
const
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
}
|
|
2107
|
-
if (stats.isDirectory()) {
|
|
2108
|
-
const entries = await readdir(path, { withFileTypes: true });
|
|
2346
|
+
async function snapshotDir(dir) {
|
|
2347
|
+
const snapshots = [];
|
|
2348
|
+
try {
|
|
2349
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
2109
2350
|
for (const entry of entries) {
|
|
2110
|
-
if (
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
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);
|
|
2351
|
+
if (IGNORE_DIRS.has(entry.name)) continue;
|
|
2352
|
+
const fullPath = resolve2(dir, entry.name);
|
|
2353
|
+
if (entry.isDirectory()) {
|
|
2354
|
+
snapshots.push(...await snapshotDir(fullPath));
|
|
2355
|
+
} else if (WATCH_EXTENSIONS.has(extname(entry.name))) {
|
|
2356
|
+
const info = await stat(fullPath);
|
|
2357
|
+
snapshots.push({ path: fullPath, mtime: info.mtimeMs, size: info.size });
|
|
2131
2358
|
}
|
|
2132
|
-
continue;
|
|
2133
2359
|
}
|
|
2134
|
-
|
|
2360
|
+
} catch {
|
|
2135
2361
|
}
|
|
2136
|
-
return
|
|
2362
|
+
return snapshots;
|
|
2137
2363
|
}
|
|
2138
2364
|
function diffSnapshots(previous, next) {
|
|
2139
|
-
const
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2365
|
+
const prevMap = new Map(previous.map((s) => [s.path, s]));
|
|
2366
|
+
const changed = [];
|
|
2367
|
+
for (const snap of next) {
|
|
2368
|
+
const prev = prevMap.get(snap.path);
|
|
2369
|
+
if (!prev || prev.mtime !== snap.mtime || prev.size !== snap.size) {
|
|
2370
|
+
changed.push(snap.path);
|
|
2143
2371
|
}
|
|
2144
2372
|
}
|
|
2145
|
-
|
|
2146
|
-
if (!previous.has(path)) {
|
|
2147
|
-
changed.add(path);
|
|
2148
|
-
}
|
|
2149
|
-
}
|
|
2150
|
-
return [...changed].toSorted();
|
|
2373
|
+
return changed;
|
|
2151
2374
|
}
|
|
2152
|
-
async function runWatchLoop(options
|
|
2153
|
-
|
|
2375
|
+
async function runWatchLoop(options) {
|
|
2376
|
+
const interval = options.interval ?? 500;
|
|
2377
|
+
let previous = [];
|
|
2378
|
+
for (const root of options.roots) {
|
|
2379
|
+
previous.push(...await snapshotDir(root));
|
|
2380
|
+
}
|
|
2154
2381
|
while (true) {
|
|
2155
|
-
await
|
|
2156
|
-
const
|
|
2157
|
-
const
|
|
2158
|
-
|
|
2159
|
-
|
|
2382
|
+
await new Promise((r) => setTimeout(r, interval));
|
|
2383
|
+
const next = [];
|
|
2384
|
+
for (const root of options.roots) {
|
|
2385
|
+
next.push(...await snapshotDir(root));
|
|
2386
|
+
}
|
|
2387
|
+
const changed = diffSnapshots(previous, next);
|
|
2388
|
+
if (changed.length > 0) {
|
|
2389
|
+
await options.onChange(changed);
|
|
2160
2390
|
}
|
|
2161
|
-
|
|
2162
|
-
await options.onChange(changedPaths);
|
|
2391
|
+
previous = next;
|
|
2163
2392
|
}
|
|
2164
2393
|
}
|
|
2165
2394
|
|
|
@@ -2191,26 +2420,8 @@ function validateOptions(opts) {
|
|
|
2191
2420
|
}
|
|
2192
2421
|
return null;
|
|
2193
2422
|
}
|
|
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
2423
|
async function buildParallelPlatformConfigs(platforms, opts, config, runtimes, resolveFromConfig) {
|
|
2213
|
-
const { discoverDevices, findDeviceById } = await import("./discover-
|
|
2424
|
+
const { discoverDevices, findDeviceById } = await import("./discover-NPNF6SWQ.js");
|
|
2214
2425
|
let allDevices;
|
|
2215
2426
|
if (opts.devices) {
|
|
2216
2427
|
allDevices = [];
|
|
@@ -2250,13 +2461,21 @@ async function buildParallelPlatformConfigs(platforms, opts, config, runtimes, r
|
|
|
2250
2461
|
id: `web-context-${i + 1}`,
|
|
2251
2462
|
name: `Chromium #${i + 1}`,
|
|
2252
2463
|
driver: result.runtime.driver,
|
|
2253
|
-
engineConfig: {
|
|
2464
|
+
engineConfig: {
|
|
2465
|
+
...result.engineConfig,
|
|
2466
|
+
debugOnFailure: opts.debugOnFailure,
|
|
2467
|
+
updateBaselines: opts.updateBaselines
|
|
2468
|
+
}
|
|
2254
2469
|
});
|
|
2255
2470
|
}
|
|
2256
2471
|
platformConfigs.push({
|
|
2257
2472
|
platform,
|
|
2258
2473
|
driver: primaryResult.runtime.driver,
|
|
2259
|
-
engineConfig: {
|
|
2474
|
+
engineConfig: {
|
|
2475
|
+
...primaryResult.engineConfig,
|
|
2476
|
+
debugOnFailure: opts.debugOnFailure,
|
|
2477
|
+
updateBaselines: opts.updateBaselines
|
|
2478
|
+
},
|
|
2260
2479
|
additionalWorkers: additionalWorkers.length > 0 ? additionalWorkers : void 0
|
|
2261
2480
|
});
|
|
2262
2481
|
} else {
|
|
@@ -2265,7 +2484,11 @@ async function buildParallelPlatformConfigs(platforms, opts, config, runtimes, r
|
|
|
2265
2484
|
platformConfigs.push({
|
|
2266
2485
|
platform,
|
|
2267
2486
|
driver: result.runtime.driver,
|
|
2268
|
-
engineConfig: {
|
|
2487
|
+
engineConfig: {
|
|
2488
|
+
...result.engineConfig,
|
|
2489
|
+
debugOnFailure: opts.debugOnFailure,
|
|
2490
|
+
updateBaselines: opts.updateBaselines
|
|
2491
|
+
}
|
|
2269
2492
|
});
|
|
2270
2493
|
}
|
|
2271
2494
|
} else if (platformDevices.length === 0) {
|
|
@@ -2290,7 +2513,11 @@ async function buildParallelPlatformConfigs(platforms, opts, config, runtimes, r
|
|
|
2290
2513
|
id: device.id,
|
|
2291
2514
|
name: device.name,
|
|
2292
2515
|
driver: result.runtime.driver,
|
|
2293
|
-
engineConfig: {
|
|
2516
|
+
engineConfig: {
|
|
2517
|
+
...result.engineConfig,
|
|
2518
|
+
debugOnFailure: opts.debugOnFailure,
|
|
2519
|
+
updateBaselines: opts.updateBaselines
|
|
2520
|
+
}
|
|
2294
2521
|
});
|
|
2295
2522
|
}
|
|
2296
2523
|
} catch (err) {
|
|
@@ -2302,21 +2529,31 @@ async function buildParallelPlatformConfigs(platforms, opts, config, runtimes, r
|
|
|
2302
2529
|
platformConfigs.push({
|
|
2303
2530
|
platform,
|
|
2304
2531
|
driver: primaryResult.runtime.driver,
|
|
2305
|
-
engineConfig: {
|
|
2532
|
+
engineConfig: {
|
|
2533
|
+
...primaryResult.engineConfig,
|
|
2534
|
+
debugOnFailure: opts.debugOnFailure,
|
|
2535
|
+
updateBaselines: opts.updateBaselines
|
|
2536
|
+
},
|
|
2306
2537
|
additionalWorkers: additionalWorkers.length > 0 ? additionalWorkers : void 0
|
|
2307
2538
|
});
|
|
2308
2539
|
}
|
|
2309
2540
|
}
|
|
2310
2541
|
return platformConfigs;
|
|
2311
2542
|
}
|
|
2312
|
-
async function buildSerialPlatformConfigs(platforms, opts, config, runtimes, executionMode, appiumUrl,
|
|
2543
|
+
async function buildSerialPlatformConfigs(platforms, opts, config, runtimes, executionMode, appiumUrl, appiumConfig, cloudHelper, targetDevice, resolveFromConfig) {
|
|
2313
2544
|
const platformConfigs = [];
|
|
2314
2545
|
for (const platform of platforms) {
|
|
2315
2546
|
if (executionMode === "appium" && (platform === "android" || platform === "ios")) {
|
|
2316
2547
|
const builder = platform === "android" ? buildAppiumAndroidRuntime : buildAppiumIOSRuntime;
|
|
2548
|
+
const resolvedCaps = appiumConfig ? await resolveCapabilities(appiumConfig, {
|
|
2549
|
+
capsPath: opts.capsPath,
|
|
2550
|
+
capsJson: opts.capsJson,
|
|
2551
|
+
platform,
|
|
2552
|
+
launchOptions: config.launchOptions
|
|
2553
|
+
}) : {};
|
|
2317
2554
|
const preparedCaps = await cloudHelper.prepareCapabilities(
|
|
2318
2555
|
platform,
|
|
2319
|
-
{ ...
|
|
2556
|
+
{ ...resolvedCaps },
|
|
2320
2557
|
platform === "android" ? config.apps?.android : config.apps?.ios
|
|
2321
2558
|
);
|
|
2322
2559
|
const result = await builder(config, appiumUrl, preparedCaps);
|
|
@@ -2324,7 +2561,11 @@ async function buildSerialPlatformConfigs(platforms, opts, config, runtimes, exe
|
|
|
2324
2561
|
platformConfigs.push({
|
|
2325
2562
|
platform,
|
|
2326
2563
|
driver: result.runtime.driver,
|
|
2327
|
-
engineConfig: {
|
|
2564
|
+
engineConfig: {
|
|
2565
|
+
...result.engineConfig,
|
|
2566
|
+
debugOnFailure: opts.debugOnFailure,
|
|
2567
|
+
updateBaselines: opts.updateBaselines
|
|
2568
|
+
}
|
|
2328
2569
|
});
|
|
2329
2570
|
} else if (platform === "web") {
|
|
2330
2571
|
const result = await buildWebRuntime(config);
|
|
@@ -2332,7 +2573,11 @@ async function buildSerialPlatformConfigs(platforms, opts, config, runtimes, exe
|
|
|
2332
2573
|
platformConfigs.push({
|
|
2333
2574
|
platform,
|
|
2334
2575
|
driver: result.runtime.driver,
|
|
2335
|
-
engineConfig: {
|
|
2576
|
+
engineConfig: {
|
|
2577
|
+
...result.engineConfig,
|
|
2578
|
+
debugOnFailure: opts.debugOnFailure,
|
|
2579
|
+
updateBaselines: opts.updateBaselines
|
|
2580
|
+
}
|
|
2336
2581
|
});
|
|
2337
2582
|
} else if (platform === "android") {
|
|
2338
2583
|
const result = await buildLocalAndroidRuntime(config, targetDevice, resolveFromConfig);
|
|
@@ -2341,7 +2586,11 @@ async function buildSerialPlatformConfigs(platforms, opts, config, runtimes, exe
|
|
|
2341
2586
|
platformConfigs.push({
|
|
2342
2587
|
platform,
|
|
2343
2588
|
driver: result.runtime.driver,
|
|
2344
|
-
engineConfig: {
|
|
2589
|
+
engineConfig: {
|
|
2590
|
+
...result.engineConfig,
|
|
2591
|
+
debugOnFailure: opts.debugOnFailure,
|
|
2592
|
+
updateBaselines: opts.updateBaselines
|
|
2593
|
+
}
|
|
2345
2594
|
});
|
|
2346
2595
|
} else if (platform === "ios") {
|
|
2347
2596
|
const result = await buildLocalIOSRuntime(config, targetDevice, resolveFromConfig);
|
|
@@ -2350,7 +2599,11 @@ async function buildSerialPlatformConfigs(platforms, opts, config, runtimes, exe
|
|
|
2350
2599
|
platformConfigs.push({
|
|
2351
2600
|
platform,
|
|
2352
2601
|
driver: result.runtime.driver,
|
|
2353
|
-
engineConfig: {
|
|
2602
|
+
engineConfig: {
|
|
2603
|
+
...result.engineConfig,
|
|
2604
|
+
debugOnFailure: opts.debugOnFailure,
|
|
2605
|
+
updateBaselines: opts.updateBaselines
|
|
2606
|
+
}
|
|
2354
2607
|
});
|
|
2355
2608
|
}
|
|
2356
2609
|
}
|
|
@@ -2388,11 +2641,11 @@ async function setupReporters(reporterNames, config, resolveFromConfig, appiumUr
|
|
|
2388
2641
|
const { createRedactor, registerUrlSecrets } = await import("./redact-U72BUBBR.js");
|
|
2389
2642
|
const redactor = createRedactor();
|
|
2390
2643
|
if (appiumUrl) registerUrlSecrets(redactor, appiumUrl);
|
|
2391
|
-
const { createConsoleReporter } = await import("./console-
|
|
2392
|
-
const { createJsonReporter } = await import("./json-
|
|
2644
|
+
const { createConsoleReporter } = await import("./console-7UW7VROK.js");
|
|
2645
|
+
const { createJsonReporter } = await import("./json-JMRPUVY2.js");
|
|
2393
2646
|
const { createJUnitReporter } = await import("./junit-HLC62MK6.js");
|
|
2394
|
-
const { createHtmlReporter } = await import("./html-
|
|
2395
|
-
const { createAllureReporter } = await import("./allure-
|
|
2647
|
+
const { createHtmlReporter } = await import("./html-F3X3XPSX.js");
|
|
2648
|
+
const { createAllureReporter } = await import("./allure-RNMEYTXS.js");
|
|
2396
2649
|
const resolvedOutputDir = config.artifacts?.outputDir ?? resolveFromConfig("./spana-output");
|
|
2397
2650
|
const reporters = [];
|
|
2398
2651
|
for (const name of reporterNames.split(",")) {
|
|
@@ -2429,12 +2682,7 @@ async function setupReporters(reporterNames, config, resolveFromConfig, appiumUr
|
|
|
2429
2682
|
}
|
|
2430
2683
|
return { redactor, reporters };
|
|
2431
2684
|
}
|
|
2432
|
-
async function
|
|
2433
|
-
const validationError = validateOptions(opts);
|
|
2434
|
-
if (validationError) {
|
|
2435
|
-
console.log(validationError);
|
|
2436
|
-
return { success: false, watchRoots: [] };
|
|
2437
|
-
}
|
|
2685
|
+
async function resolveExecutionContext(opts) {
|
|
2438
2686
|
let config = {};
|
|
2439
2687
|
let loadedConfigPath;
|
|
2440
2688
|
try {
|
|
@@ -2443,16 +2691,16 @@ async function runTestCommandOnce(opts) {
|
|
|
2443
2691
|
loadedConfigPath = loaded.configPath;
|
|
2444
2692
|
} catch (error) {
|
|
2445
2693
|
console.log(error instanceof Error ? error.message : String(error));
|
|
2446
|
-
return {
|
|
2694
|
+
return { ok: false, success: false };
|
|
2447
2695
|
}
|
|
2448
2696
|
const configDir = dirname3(loadedConfigPath ?? resolve3("spana.config.ts"));
|
|
2449
2697
|
if (opts.validateConfigOnly) {
|
|
2450
2698
|
if (!loadedConfigPath) {
|
|
2451
2699
|
console.log("No config file found to validate.");
|
|
2452
|
-
return {
|
|
2700
|
+
return { ok: false, success: false };
|
|
2453
2701
|
}
|
|
2454
2702
|
console.log(`\u2713 Config valid (${loadedConfigPath})`);
|
|
2455
|
-
return {
|
|
2703
|
+
return { ok: false, success: true };
|
|
2456
2704
|
}
|
|
2457
2705
|
const resolveFromConfig = (p) => resolve3(configDir, p);
|
|
2458
2706
|
if (config.artifacts?.outputDir) {
|
|
@@ -2464,89 +2712,84 @@ async function runTestCommandOnce(opts) {
|
|
|
2464
2712
|
JSON.parse(opts.capsJson);
|
|
2465
2713
|
} catch {
|
|
2466
2714
|
console.log("Invalid JSON in --caps-json flag.");
|
|
2467
|
-
return {
|
|
2715
|
+
return { ok: false, success: false };
|
|
2468
2716
|
}
|
|
2469
2717
|
}
|
|
2470
2718
|
if (executionMode === "appium") {
|
|
2471
|
-
const appiumUrl = opts.appiumUrl ?? config.execution?.appium?.serverUrl;
|
|
2472
|
-
|
|
2719
|
+
const appiumUrl = opts.appiumUrl ?? process.env.SPANA_APPIUM_URL ?? config.execution?.appium?.serverUrl;
|
|
2720
|
+
const wantAutoStart = opts.appiumAutoStart ?? config.execution?.appium?.autoStart ?? false;
|
|
2721
|
+
if (!appiumUrl && !wantAutoStart) {
|
|
2473
2722
|
console.log(
|
|
2474
|
-
"Appium mode requires a server URL. Set --appium-url
|
|
2723
|
+
"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
2724
|
);
|
|
2476
|
-
return {
|
|
2725
|
+
return { ok: false, success: false };
|
|
2477
2726
|
}
|
|
2478
2727
|
if (opts.device) {
|
|
2479
2728
|
console.log(
|
|
2480
2729
|
"Cannot use --device with appium mode. Use --caps or --caps-json to set device capabilities."
|
|
2481
2730
|
);
|
|
2482
|
-
return {
|
|
2731
|
+
return { ok: false, success: false };
|
|
2483
2732
|
}
|
|
2484
2733
|
}
|
|
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
|
-
}
|
|
2734
|
+
return {
|
|
2735
|
+
ok: true,
|
|
2736
|
+
context: { config, configPath: loadedConfigPath, configDir, executionMode, resolveFromConfig }
|
|
2737
|
+
};
|
|
2738
|
+
}
|
|
2739
|
+
async function resolveTargetDevice(deviceId, platforms, cliPlatforms) {
|
|
2740
|
+
const { findDeviceById } = await import("./discover-NPNF6SWQ.js");
|
|
2741
|
+
const targetDevice = findDeviceById(deviceId);
|
|
2742
|
+
if (!targetDevice) {
|
|
2743
|
+
const { discoverDevices } = await import("./discover-NPNF6SWQ.js");
|
|
2744
|
+
const available = discoverDevices(["web", "android", "ios"]);
|
|
2745
|
+
console.log(`Device "${deviceId}" not found. Available devices:`);
|
|
2746
|
+
for (const d of available) {
|
|
2747
|
+
console.log(` ${d.id.padEnd(30)} ${d.platform.padEnd(8)} ${d.type}`);
|
|
2748
|
+
}
|
|
2749
|
+
return { ok: false, success: false };
|
|
2750
|
+
}
|
|
2751
|
+
const updatedPlatforms = cliPlatforms.length === 0 ? [targetDevice.platform] : [...platforms];
|
|
2752
|
+
if (!updatedPlatforms.includes(targetDevice.platform)) {
|
|
2753
|
+
console.log(
|
|
2754
|
+
`Device "${deviceId}" is ${targetDevice.platform}, but --platform ${updatedPlatforms.join(",")} was specified.`
|
|
2755
|
+
);
|
|
2756
|
+
return { ok: false, success: false };
|
|
2515
2757
|
}
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2758
|
+
return { ok: true, device: targetDevice, platforms: updatedPlatforms };
|
|
2759
|
+
}
|
|
2760
|
+
async function discoverAndFilterFlows(input) {
|
|
2761
|
+
const watchRoots = collectWatchRoots(input.flowDir, input.configPath);
|
|
2762
|
+
let flowPaths = await discoverFlows(input.flowDir);
|
|
2520
2763
|
if (flowPaths.length === 0) {
|
|
2521
2764
|
console.log("No flow files found.");
|
|
2522
|
-
return { success: true, watchRoots };
|
|
2765
|
+
return { ok: false, success: true, watchRoots };
|
|
2523
2766
|
}
|
|
2524
2767
|
let stepPaths = [];
|
|
2525
2768
|
const hasFeatureFiles = flowPaths.some((p) => p.endsWith(".feature"));
|
|
2526
2769
|
if (hasFeatureFiles) {
|
|
2527
2770
|
const { stat: statPath } = await import("fs/promises");
|
|
2528
2771
|
const { dirname: dirnameDyn } = await import("path");
|
|
2529
|
-
const flowDirStats = await statPath(flowDir).catch(() => null);
|
|
2530
|
-
const stepSearchDir = flowDirStats?.isDirectory() ? flowDir : dirnameDyn(flowDir);
|
|
2772
|
+
const flowDirStats = await statPath(input.flowDir).catch(() => null);
|
|
2773
|
+
const stepSearchDir = flowDirStats?.isDirectory() ? input.flowDir : dirnameDyn(input.flowDir);
|
|
2531
2774
|
stepPaths = await discoverStepFiles(stepSearchDir);
|
|
2532
2775
|
}
|
|
2533
|
-
if (
|
|
2776
|
+
if (input.changed) {
|
|
2534
2777
|
let changedFiles;
|
|
2535
2778
|
try {
|
|
2536
2779
|
changedFiles = getGitChangedFiles(process.cwd());
|
|
2537
2780
|
} catch (error) {
|
|
2538
2781
|
console.log(error instanceof Error ? error.message : String(error));
|
|
2539
|
-
return { success: false, watchRoots };
|
|
2782
|
+
return { ok: false, success: false, watchRoots };
|
|
2540
2783
|
}
|
|
2541
2784
|
const selection = selectChangedFlowPaths({
|
|
2542
2785
|
flowPaths,
|
|
2543
2786
|
changedFiles,
|
|
2544
2787
|
stepPaths,
|
|
2545
|
-
configPath:
|
|
2788
|
+
configPath: input.configPath
|
|
2546
2789
|
});
|
|
2547
2790
|
if (selection.mode === "none") {
|
|
2548
2791
|
console.log(selection.reason);
|
|
2549
|
-
return { success: true, watchRoots };
|
|
2792
|
+
return { ok: false, success: true, watchRoots };
|
|
2550
2793
|
}
|
|
2551
2794
|
if (selection.mode === "targeted") {
|
|
2552
2795
|
flowPaths = selection.flowPaths;
|
|
@@ -2557,52 +2800,160 @@ async function runTestCommandOnce(opts) {
|
|
|
2557
2800
|
}
|
|
2558
2801
|
if (flowPaths.length === 0) {
|
|
2559
2802
|
console.log("No flow files found.");
|
|
2560
|
-
return { success: true, watchRoots };
|
|
2803
|
+
return { ok: false, success: true, watchRoots };
|
|
2561
2804
|
}
|
|
2562
2805
|
if (flowPaths.some((path) => path.endsWith(".feature")) && stepPaths.length > 0) {
|
|
2563
2806
|
await loadStepFiles(stepPaths);
|
|
2564
2807
|
}
|
|
2565
|
-
const loadedFlows =
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2808
|
+
const loadedFlows = [];
|
|
2809
|
+
for (const sourcePath of flowPaths) {
|
|
2810
|
+
const loaded = await loadTestSource(sourcePath);
|
|
2811
|
+
for (const flow of loaded) {
|
|
2812
|
+
loadedFlows.push({ sourcePath, flow });
|
|
2813
|
+
}
|
|
2814
|
+
}
|
|
2815
|
+
const filteredFlows = filterFlows(
|
|
2816
|
+
loadedFlows.map((l) => l.flow),
|
|
2817
|
+
{ tags: input.tags, grep: input.grep, platforms: input.platforms }
|
|
2818
|
+
);
|
|
2819
|
+
const allowedFlows = new Set(filteredFlows);
|
|
2820
|
+
let filteredLoadedFlows = loadedFlows.filter((l) => allowedFlows.has(l.flow));
|
|
2821
|
+
if (input.lastFailed) {
|
|
2822
|
+
const lastRunStatePath = createLastRunStatePath(input.outputDir);
|
|
2574
2823
|
const state = await readLastRunState(lastRunStatePath);
|
|
2575
2824
|
if (!state) {
|
|
2576
|
-
console.log(
|
|
2577
|
-
|
|
2825
|
+
console.log(
|
|
2826
|
+
"No previous Spana run state found. Run `spana test` once before using --last-failed."
|
|
2827
|
+
);
|
|
2828
|
+
return { ok: false, success: true, watchRoots };
|
|
2578
2829
|
}
|
|
2579
2830
|
if (state.failedFlowNames.length === 0) {
|
|
2580
2831
|
console.log("No failed flows were recorded in the last Spana run.");
|
|
2581
|
-
return { success: true, watchRoots };
|
|
2832
|
+
return { ok: false, success: true, watchRoots };
|
|
2582
2833
|
}
|
|
2583
2834
|
const failedFlowNames = new Set(state.failedFlowNames);
|
|
2584
|
-
|
|
2585
|
-
if (
|
|
2835
|
+
filteredLoadedFlows = filteredLoadedFlows.filter((l) => failedFlowNames.has(l.flow.name));
|
|
2836
|
+
if (filteredLoadedFlows.length === 0) {
|
|
2586
2837
|
console.log("No last-failed flows match the current filters.");
|
|
2587
|
-
return { success: true, watchRoots };
|
|
2838
|
+
return { ok: false, success: true, watchRoots };
|
|
2588
2839
|
}
|
|
2589
|
-
console.log(`Rerunning ${
|
|
2840
|
+
console.log(`Rerunning ${filteredLoadedFlows.length} flow(s) from the last failed run.`);
|
|
2590
2841
|
}
|
|
2591
|
-
const selectedLoadedFlows = applyShard(
|
|
2592
|
-
const selectedFlows = selectedLoadedFlows.map((
|
|
2593
|
-
if (
|
|
2842
|
+
const selectedLoadedFlows = applyShard(filteredLoadedFlows, input.shard);
|
|
2843
|
+
const selectedFlows = selectedLoadedFlows.map((l) => l.flow);
|
|
2844
|
+
if (filteredLoadedFlows.length === 0) {
|
|
2594
2845
|
console.log("No flows match the given filters.");
|
|
2595
|
-
return { success: true, watchRoots };
|
|
2846
|
+
return { ok: false, success: true, watchRoots };
|
|
2596
2847
|
}
|
|
2597
2848
|
if (selectedFlows.length === 0) {
|
|
2598
|
-
console.log(`No flows assigned to shard ${
|
|
2599
|
-
return { success: true, watchRoots };
|
|
2849
|
+
console.log(`No flows assigned to shard ${input.shard.current}/${input.shard.total}.`);
|
|
2850
|
+
return { ok: false, success: true, watchRoots };
|
|
2600
2851
|
}
|
|
2601
|
-
if (
|
|
2852
|
+
if (input.shard) {
|
|
2602
2853
|
console.log(
|
|
2603
|
-
`Running shard ${
|
|
2854
|
+
`Running shard ${input.shard.current}/${input.shard.total} (${selectedFlows.length}/${filteredLoadedFlows.length} flow(s))...`
|
|
2604
2855
|
);
|
|
2605
2856
|
}
|
|
2857
|
+
return { ok: true, selectedLoadedFlows, selectedFlows, watchRoots };
|
|
2858
|
+
}
|
|
2859
|
+
function createResultHandler(reporters, redactResult, redactor, opts) {
|
|
2860
|
+
return (r) => {
|
|
2861
|
+
const redacted = redactResult(r);
|
|
2862
|
+
for (const reporter of reporters) {
|
|
2863
|
+
if (redacted.status === "passed") {
|
|
2864
|
+
reporter.onFlowPass?.(redacted);
|
|
2865
|
+
} else if (redacted.status === "failed") {
|
|
2866
|
+
reporter.onFlowFail?.(redacted);
|
|
2867
|
+
if (opts.verbose && redacted.error) {
|
|
2868
|
+
console.log(
|
|
2869
|
+
`
|
|
2870
|
+
[verbose] Failure details for "${redacted.name}" on ${redacted.platform}:`
|
|
2871
|
+
);
|
|
2872
|
+
console.log(` Category: ${redacted.error.category}`);
|
|
2873
|
+
console.log(` Message: ${redacted.error.message}`);
|
|
2874
|
+
if (redacted.error.suggestion) {
|
|
2875
|
+
console.log(` Suggestion: ${redacted.error.suggestion}`);
|
|
2876
|
+
}
|
|
2877
|
+
for (const section of collectDiagnosticSections(redacted.attachments, {
|
|
2878
|
+
verbose: true
|
|
2879
|
+
})) {
|
|
2880
|
+
console.log(` ${section.title}: ${redactor.redact(section.path)}`);
|
|
2881
|
+
console.log(
|
|
2882
|
+
section.body.split("\n").map((line) => ` ${redactor.redact(line)}`).join("\n")
|
|
2883
|
+
);
|
|
2884
|
+
}
|
|
2885
|
+
if (redacted.error.stack) {
|
|
2886
|
+
console.log(
|
|
2887
|
+
` Stack:
|
|
2888
|
+
${redacted.error.stack.split("\n").map((l) => ` ${l}`).join("\n")}`
|
|
2889
|
+
);
|
|
2890
|
+
}
|
|
2891
|
+
}
|
|
2892
|
+
}
|
|
2893
|
+
}
|
|
2894
|
+
};
|
|
2895
|
+
}
|
|
2896
|
+
async function reportToCloudProvider(runtimes, appiumUrl, result, platforms) {
|
|
2897
|
+
const { detectProvider: detectProvider2 } = await import("./provider-YIPU5K42.js");
|
|
2898
|
+
for (const rt of runtimes) {
|
|
2899
|
+
if (rt.metadata.mode === "appium" && rt.metadata.provider) {
|
|
2900
|
+
const provider = detectProvider2(appiumUrl);
|
|
2901
|
+
if (provider) {
|
|
2902
|
+
try {
|
|
2903
|
+
const meta = {};
|
|
2904
|
+
provider.extractMeta(rt.metadata.sessionId, rt.metadata.sessionCaps ?? {}, meta);
|
|
2905
|
+
await provider.reportResult(appiumUrl, meta, {
|
|
2906
|
+
passed: result.failed === 0,
|
|
2907
|
+
name: `spana ${platforms.join(",")}`
|
|
2908
|
+
});
|
|
2909
|
+
} catch (e) {
|
|
2910
|
+
console.log(
|
|
2911
|
+
`Warning: Failed to report to ${rt.metadata.provider}: ${e instanceof Error ? e.message : e}`
|
|
2912
|
+
);
|
|
2913
|
+
}
|
|
2914
|
+
}
|
|
2915
|
+
}
|
|
2916
|
+
}
|
|
2917
|
+
}
|
|
2918
|
+
async function runTestCommandOnce(opts) {
|
|
2919
|
+
const validationError = validateOptions(opts);
|
|
2920
|
+
if (validationError) {
|
|
2921
|
+
console.log(validationError);
|
|
2922
|
+
return { success: false, watchRoots: [] };
|
|
2923
|
+
}
|
|
2924
|
+
const ctxResult = await resolveExecutionContext(opts);
|
|
2925
|
+
if (!ctxResult.ok) return { success: ctxResult.success, watchRoots: [] };
|
|
2926
|
+
const { config, configPath, executionMode, resolveFromConfig } = ctxResult.context;
|
|
2927
|
+
const platforms = opts.platforms.length > 0 ? opts.platforms : config.platforms && config.platforms.length > 0 ? config.platforms : ["web"];
|
|
2928
|
+
const flowDir = opts.flowPath ?? resolveFromConfig(config.flowDir ?? "./flows");
|
|
2929
|
+
let targetDevice = null;
|
|
2930
|
+
if (opts.device) {
|
|
2931
|
+
const deviceResult = await resolveTargetDevice(opts.device, platforms, opts.platforms);
|
|
2932
|
+
if (!deviceResult.ok) {
|
|
2933
|
+
return {
|
|
2934
|
+
success: deviceResult.success,
|
|
2935
|
+
watchRoots: collectWatchRoots(flowDir, configPath)
|
|
2936
|
+
};
|
|
2937
|
+
}
|
|
2938
|
+
targetDevice = deviceResult.device;
|
|
2939
|
+
platforms.length = 0;
|
|
2940
|
+
platforms.push(...deviceResult.platforms);
|
|
2941
|
+
}
|
|
2942
|
+
const reporterNames = opts.reporter?.trim() ? opts.reporter : config.reporters && config.reporters.length > 0 ? config.reporters.join(",") : "console";
|
|
2943
|
+
const outputDir = config.artifacts?.outputDir ?? resolveFromConfig("./spana-output");
|
|
2944
|
+
const flowResult = await discoverAndFilterFlows({
|
|
2945
|
+
flowDir,
|
|
2946
|
+
configPath,
|
|
2947
|
+
tags: opts.tags,
|
|
2948
|
+
grep: opts.grep,
|
|
2949
|
+
platforms,
|
|
2950
|
+
shard: opts.shard,
|
|
2951
|
+
lastFailed: opts.lastFailed,
|
|
2952
|
+
changed: opts.changed,
|
|
2953
|
+
outputDir
|
|
2954
|
+
});
|
|
2955
|
+
if (!flowResult.ok) return { success: flowResult.success, watchRoots: flowResult.watchRoots };
|
|
2956
|
+
const { selectedLoadedFlows, selectedFlows, watchRoots } = flowResult;
|
|
2606
2957
|
console.log(`Running ${selectedFlows.length} flow(s) on ${platforms.join(", ")}...
|
|
2607
2958
|
`);
|
|
2608
2959
|
const runtimes = [];
|
|
@@ -2626,14 +2977,26 @@ async function runTestCommandOnce(opts) {
|
|
|
2626
2977
|
process.on("SIGINT", handleSignal);
|
|
2627
2978
|
process.on("SIGTERM", handleSignal);
|
|
2628
2979
|
try {
|
|
2629
|
-
const appiumUrl = opts.appiumUrl ?? config.execution?.appium?.serverUrl;
|
|
2630
2980
|
const appiumConfig = config.execution?.appium ?? {};
|
|
2981
|
+
const wantAutoStart = executionMode === "appium" && (opts.appiumAutoStart ?? appiumConfig.autoStart ?? false);
|
|
2982
|
+
let appiumUrl = opts.appiumUrl ?? process.env.SPANA_APPIUM_URL ?? config.execution?.appium?.serverUrl;
|
|
2983
|
+
if (wantAutoStart) {
|
|
2984
|
+
if (opts.appiumUrl || process.env.SPANA_APPIUM_URL || appiumConfig.serverUrl) {
|
|
2985
|
+
console.log(
|
|
2986
|
+
"Appium auto-start is enabled; ignoring --appium-url / SPANA_APPIUM_URL / execution.appium.serverUrl."
|
|
2987
|
+
);
|
|
2988
|
+
}
|
|
2989
|
+
const { startLocalAppium } = await import("./appium-server-66GVUL24.js");
|
|
2990
|
+
const started = await startLocalAppium({
|
|
2991
|
+
binary: appiumConfig.autoStartBinary,
|
|
2992
|
+
extraArgs: appiumConfig.autoStartArgs,
|
|
2993
|
+
log: (line) => console.log(line)
|
|
2994
|
+
});
|
|
2995
|
+
appiumUrl = started.url;
|
|
2996
|
+
runCleanups.push(() => started.stop());
|
|
2997
|
+
}
|
|
2631
2998
|
const shouldReportToProvider = !opts.noProviderReporting && appiumConfig.reportToProvider !== false;
|
|
2632
2999
|
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
3000
|
if (cloudHelper) {
|
|
2638
3001
|
runCleanups.push(() => cloudHelper.cleanup());
|
|
2639
3002
|
}
|
|
@@ -2656,7 +3019,7 @@ async function runTestCommandOnce(opts) {
|
|
|
2656
3019
|
runtimes,
|
|
2657
3020
|
executionMode,
|
|
2658
3021
|
appiumUrl,
|
|
2659
|
-
|
|
3022
|
+
appiumConfig,
|
|
2660
3023
|
cloudHelper,
|
|
2661
3024
|
targetDevice,
|
|
2662
3025
|
resolveFromConfig
|
|
@@ -2699,51 +3062,18 @@ async function runTestCommandOnce(opts) {
|
|
|
2699
3062
|
};
|
|
2700
3063
|
const retries = opts.retries ?? config.defaults?.retries ?? 0;
|
|
2701
3064
|
const retryDelay = config.defaults?.retryDelay ?? 0;
|
|
3065
|
+
const onResult = createResultHandler(reporters, redactResult, redactor, opts);
|
|
2702
3066
|
const result = await orchestrate(selectedFlows, platformConfigs, {
|
|
2703
3067
|
retries,
|
|
2704
3068
|
retryDelay,
|
|
2705
3069
|
bail: opts.bail,
|
|
2706
|
-
parallelPlatforms: opts.parallel || !!opts.workers || !!opts.devices,
|
|
3070
|
+
parallelPlatforms: opts.parallel || config.parallelPlatforms || !!opts.workers || !!opts.devices,
|
|
2707
3071
|
onFlowStart(name, platform, workerName) {
|
|
2708
3072
|
for (const reporter of reporters) {
|
|
2709
3073
|
reporter.onFlowStart?.(name, platform, workerName);
|
|
2710
3074
|
}
|
|
2711
3075
|
},
|
|
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
|
-
}
|
|
3076
|
+
onResult
|
|
2747
3077
|
});
|
|
2748
3078
|
const redactedResults = result.results.map(redactResult);
|
|
2749
3079
|
for (const reporter of reporters) {
|
|
@@ -2764,9 +3094,7 @@ ${redacted.error.stack.split("\n").map((l) => ` ${l}`).join("\n")}`
|
|
|
2764
3094
|
const sourcePathsByFlowName = new Map(
|
|
2765
3095
|
selectedLoadedFlows.map((loaded) => [loaded.flow.name, loaded.sourcePath])
|
|
2766
3096
|
);
|
|
2767
|
-
const iterationStatePath = createLastRunStatePath(
|
|
2768
|
-
config.artifacts?.outputDir ?? resolveFromConfig("./spana-output")
|
|
2769
|
-
);
|
|
3097
|
+
const iterationStatePath = createLastRunStatePath(outputDir);
|
|
2770
3098
|
try {
|
|
2771
3099
|
await writeLastRunState(
|
|
2772
3100
|
iterationStatePath,
|
|
@@ -2783,26 +3111,7 @@ ${redacted.error.stack.split("\n").map((l) => ` ${l}`).join("\n")}`
|
|
|
2783
3111
|
);
|
|
2784
3112
|
}
|
|
2785
3113
|
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
|
-
}
|
|
3114
|
+
await reportToCloudProvider(runtimes, appiumUrl, result, platforms);
|
|
2806
3115
|
}
|
|
2807
3116
|
return { success: result.failed === 0, watchRoots };
|
|
2808
3117
|
} finally {
|
|
@@ -2849,4 +3158,4 @@ export {
|
|
|
2849
3158
|
loadCustomReporter,
|
|
2850
3159
|
runTestCommand
|
|
2851
3160
|
};
|
|
2852
|
-
//# sourceMappingURL=test-command-
|
|
3161
|
+
//# sourceMappingURL=test-command-2PXTHASW.js.map
|