spana-test 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/skills/spana-testing/SKILL.md +301 -0
- package/README.md +276 -0
- package/dist/agent/index.d.ts +81 -0
- package/dist/agent/index.js +21 -0
- package/dist/allure-PTTVORQ6.js +124 -0
- package/dist/allure-PTTVORQ6.js.map +1 -0
- package/dist/android-PAPJJWVN.js +34 -0
- package/dist/android-PAPJJWVN.js.map +1 -0
- package/dist/chunk-3FSZNKEF.js +62 -0
- package/dist/chunk-3FSZNKEF.js.map +1 -0
- package/dist/chunk-53MUJUJY.js +113 -0
- package/dist/chunk-53MUJUJY.js.map +1 -0
- package/dist/chunk-5XO6S7AI.js +134 -0
- package/dist/chunk-5XO6S7AI.js.map +1 -0
- package/dist/chunk-BZRLA4Z3.js +82 -0
- package/dist/chunk-BZRLA4Z3.js.map +1 -0
- package/dist/{chunk-PF7V37UD.js → chunk-CKJQX73M.js} +897 -845
- package/dist/chunk-CKJQX73M.js.map +1 -0
- package/dist/chunk-DGUM43GV.js +11 -0
- package/dist/chunk-DGUM43GV.js.map +1 -0
- package/dist/{chunk-HKDZMXD7.js → chunk-GZK22EIE.js} +76 -102
- package/dist/chunk-GZK22EIE.js.map +1 -0
- package/dist/chunk-PANFRTIU.js +310 -0
- package/dist/chunk-PANFRTIU.js.map +1 -0
- package/dist/chunk-PWEOJKUF.js +473 -0
- package/dist/chunk-PWEOJKUF.js.map +1 -0
- package/dist/chunk-RJ5VPHVX.js +127 -0
- package/dist/chunk-RJ5VPHVX.js.map +1 -0
- package/dist/chunk-RK4Z6C7M.js +248 -0
- package/dist/chunk-RK4Z6C7M.js.map +1 -0
- package/dist/chunk-U564GCO2.js +259 -0
- package/dist/chunk-U564GCO2.js.map +1 -0
- package/dist/chunk-V62HFH6E.js +269 -0
- package/dist/chunk-V62HFH6E.js.map +1 -0
- package/dist/chunk-VDWWIVM6.js +303 -0
- package/dist/chunk-VDWWIVM6.js.map +1 -0
- package/dist/{discover-4EZKZ5RO.js → chunk-WIJYK22K.js} +12 -5
- package/dist/{discover-4EZKZ5RO.js.map → chunk-WIJYK22K.js.map} +1 -1
- package/dist/cli.js +135 -17
- package/dist/cli.js.map +1 -1
- package/dist/compiler-G75RIIYS.js +312 -0
- package/dist/compiler-G75RIIYS.js.map +1 -0
- package/dist/config-Dg9O0rcQ.d.ts +219 -0
- package/dist/config-loader-JJ5RPP53.js +9 -0
- package/dist/config-loader-JJ5RPP53.js.map +1 -0
- package/dist/console-FV4RJPO4.js +132 -0
- package/dist/console-FV4RJPO4.js.map +1 -0
- package/dist/discover-RWBKI5IB.js +14 -0
- package/dist/discover-RWBKI5IB.js.map +1 -0
- package/dist/element-CGteXiXB.d.ts +23 -0
- package/dist/flow-D-_tlLpp.d.ts +99 -0
- package/dist/gherkin/steps.d.ts +32 -0
- package/dist/gherkin/steps.js +39 -0
- package/dist/gherkin/steps.js.map +1 -0
- package/dist/{html-OGRQ5NIX.js → html-JP2HBIJQ.js} +54 -20
- package/dist/html-JP2HBIJQ.js.map +1 -0
- package/dist/index.d.ts +4 -157
- package/dist/index.js +36 -165
- package/dist/index.js.map +1 -1
- package/dist/init-command-CELKL2CX.js +105 -0
- package/dist/init-command-CELKL2CX.js.map +1 -0
- package/dist/installer-R6NX7BYQ.js +20 -0
- package/dist/installer-R6NX7BYQ.js.map +1 -0
- package/dist/ios-ZZU6DHH7.js +48 -0
- package/dist/ios-ZZU6DHH7.js.map +1 -0
- package/dist/{json-3TZD6FI5.js → json-JMRPUVY2.js} +2 -2
- package/dist/{junit-ES66OYVX.js → junit-UDY5JG22.js} +14 -3
- package/dist/junit-UDY5JG22.js.map +1 -0
- package/dist/provider-CUWPULGC.js +10 -0
- package/dist/provider-CUWPULGC.js.map +1 -0
- package/dist/redact-IDA3C4UH.js +77 -0
- package/dist/redact-IDA3C4UH.js.map +1 -0
- package/dist/runner-QEF6PJOE.js +20 -0
- package/dist/runner-QEF6PJOE.js.map +1 -0
- package/dist/server-MMK7PZIH.js +505 -0
- package/dist/server-MMK7PZIH.js.map +1 -0
- package/dist/session-FBJABNXL.js +16 -0
- package/dist/session-FBJABNXL.js.map +1 -0
- package/dist/studio-command-CDVPREMG.js +24 -0
- package/dist/studio-command-CDVPREMG.js.map +1 -0
- package/dist/test-command-SB5KYPQI.js +1929 -0
- package/dist/test-command-SB5KYPQI.js.map +1 -0
- package/dist/validator-CFQ55NUQ.js +13 -0
- package/dist/validator-CFQ55NUQ.js.map +1 -0
- package/package.json +43 -5
- package/studio-dist/assets/index-CPdpC9i-.css +1 -0
- package/studio-dist/assets/index-L1Wd0vop.js +183 -0
- package/studio-dist/index.html +13 -0
- package/dist/chunk-HKDZMXD7.js.map +0 -1
- package/dist/chunk-PF7V37UD.js.map +0 -1
- package/dist/chunk-Y7MNYLGH.js +0 -64
- package/dist/chunk-Y7MNYLGH.js.map +0 -1
- package/dist/console-ZH3SUKUO.js +0 -71
- package/dist/console-ZH3SUKUO.js.map +0 -1
- package/dist/html-OGRQ5NIX.js.map +0 -1
- package/dist/junit-ES66OYVX.js.map +0 -1
- package/dist/runner-NGLCXD2E.js +0 -12
- package/dist/session-NWNZWWNI.js +0 -122
- package/dist/session-NWNZWWNI.js.map +0 -1
- package/dist/test-command-F3AEHF2E.js +0 -636
- package/dist/test-command-F3AEHF2E.js.map +0 -1
- package/dist/validator-LHN66ZH7.js +0 -33
- package/dist/validator-LHN66ZH7.js.map +0 -1
- /package/dist/{runner-NGLCXD2E.js.map → agent/index.js.map} +0 -0
- /package/dist/{json-3TZD6FI5.js.map → json-JMRPUVY2.js.map} +0 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import "./chunk-DGUM43GV.js";
|
|
2
|
+
|
|
3
|
+
// src/report/allure.ts
|
|
4
|
+
import { randomUUID, createHash } from "crypto";
|
|
5
|
+
import { writeFileSync, mkdirSync, copyFileSync, existsSync } from "fs";
|
|
6
|
+
import { join } from "path";
|
|
7
|
+
function historyId(name, platform) {
|
|
8
|
+
return createHash("md5").update(`${name}:${platform}`).digest("hex");
|
|
9
|
+
}
|
|
10
|
+
function allureStatus(status) {
|
|
11
|
+
if (status === "passed") return "passed";
|
|
12
|
+
if (status === "failed") return "failed";
|
|
13
|
+
if (status === "skipped") return "skipped";
|
|
14
|
+
return "broken";
|
|
15
|
+
}
|
|
16
|
+
function mapSteps(steps, startTime) {
|
|
17
|
+
let time = startTime;
|
|
18
|
+
return steps.map((step) => {
|
|
19
|
+
const stepStart = time;
|
|
20
|
+
const stepStop = time + step.durationMs;
|
|
21
|
+
time = stepStop;
|
|
22
|
+
return {
|
|
23
|
+
name: step.selector ? `${step.command} ${JSON.stringify(step.selector)}` : step.command,
|
|
24
|
+
status: allureStatus(step.status),
|
|
25
|
+
start: stepStart,
|
|
26
|
+
stop: stepStop,
|
|
27
|
+
steps: [],
|
|
28
|
+
...step.error ? { statusDetails: { message: step.error } } : {}
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function copyAttachments(result, outputDir) {
|
|
33
|
+
const allureAttachments = [];
|
|
34
|
+
for (const att of result.attachments ?? []) {
|
|
35
|
+
if (att.path && existsSync(att.path)) {
|
|
36
|
+
const ext = att.contentType === "image/png" ? ".png" : ".json";
|
|
37
|
+
const filename = `${randomUUID()}-attachment${ext}`;
|
|
38
|
+
copyFileSync(att.path, join(outputDir, filename));
|
|
39
|
+
allureAttachments.push({
|
|
40
|
+
name: att.name,
|
|
41
|
+
source: filename,
|
|
42
|
+
type: att.contentType
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
for (const step of result.steps ?? []) {
|
|
47
|
+
for (const att of step.attachments ?? []) {
|
|
48
|
+
if (att.path && existsSync(att.path)) {
|
|
49
|
+
const ext = att.contentType === "image/png" ? ".png" : ".json";
|
|
50
|
+
const filename = `${randomUUID()}-attachment${ext}`;
|
|
51
|
+
copyFileSync(att.path, join(outputDir, filename));
|
|
52
|
+
allureAttachments.push({
|
|
53
|
+
name: att.name,
|
|
54
|
+
source: filename,
|
|
55
|
+
type: att.contentType
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return allureAttachments;
|
|
61
|
+
}
|
|
62
|
+
function writeResult(result, outputDir) {
|
|
63
|
+
const uuid = randomUUID();
|
|
64
|
+
const now = Date.now();
|
|
65
|
+
const startTime = now - result.durationMs;
|
|
66
|
+
const labels = [
|
|
67
|
+
{ name: "suite", value: result.platform },
|
|
68
|
+
{ name: "framework", value: "spana" }
|
|
69
|
+
];
|
|
70
|
+
if (result.flaky) {
|
|
71
|
+
labels.push({ name: "tag", value: "flaky" });
|
|
72
|
+
}
|
|
73
|
+
const allureResult = {
|
|
74
|
+
uuid,
|
|
75
|
+
historyId: historyId(result.name, result.platform),
|
|
76
|
+
name: result.name,
|
|
77
|
+
fullName: `[${result.platform}] ${result.name}`,
|
|
78
|
+
status: result.flaky ? "passed" : allureStatus(result.status),
|
|
79
|
+
stage: "finished",
|
|
80
|
+
start: startTime,
|
|
81
|
+
stop: now,
|
|
82
|
+
labels,
|
|
83
|
+
steps: result.steps ? mapSteps(result.steps, startTime) : [],
|
|
84
|
+
attachments: copyAttachments(result, outputDir)
|
|
85
|
+
};
|
|
86
|
+
if (result.error) {
|
|
87
|
+
allureResult.statusDetails = {
|
|
88
|
+
message: result.error.message,
|
|
89
|
+
trace: result.error.stack
|
|
90
|
+
};
|
|
91
|
+
} else if (result.flaky) {
|
|
92
|
+
allureResult.statusDetails = {
|
|
93
|
+
message: `Flaky: passed on attempt ${result.attempts}`
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
writeFileSync(join(outputDir, `${uuid}-result.json`), JSON.stringify(allureResult, null, 2));
|
|
97
|
+
}
|
|
98
|
+
function createAllureReporter(outputDir = "allure-results") {
|
|
99
|
+
mkdirSync(outputDir, { recursive: true });
|
|
100
|
+
return {
|
|
101
|
+
onFlowPass(result) {
|
|
102
|
+
writeResult(result, outputDir);
|
|
103
|
+
},
|
|
104
|
+
onFlowFail(result) {
|
|
105
|
+
writeResult(result, outputDir);
|
|
106
|
+
},
|
|
107
|
+
onRunComplete(summary) {
|
|
108
|
+
const envContent = [
|
|
109
|
+
`Platform=${summary.platforms.join(", ")}`,
|
|
110
|
+
`Framework=spana`,
|
|
111
|
+
`Total=${summary.total}`,
|
|
112
|
+
`Passed=${summary.passed}`,
|
|
113
|
+
`Failed=${summary.failed}`
|
|
114
|
+
].join("\n");
|
|
115
|
+
writeFileSync(join(outputDir, "environment.properties"), envContent);
|
|
116
|
+
console.log(`Allure results written to ${outputDir}/`);
|
|
117
|
+
console.log(`Run: npx allure generate ${outputDir} --clean -o allure-report`);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
export {
|
|
122
|
+
createAllureReporter
|
|
123
|
+
};
|
|
124
|
+
//# sourceMappingURL=allure-PTTVORQ6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/report/allure.ts"],"sourcesContent":["import { randomUUID, createHash } from \"node:crypto\";\nimport { writeFileSync, mkdirSync, copyFileSync, existsSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport type { Reporter, FlowResult, StepResult } from \"./types.js\";\n\nfunction historyId(name: string, platform: string): string {\n return createHash(\"md5\").update(`${name}:${platform}`).digest(\"hex\");\n}\n\nfunction allureStatus(status: string): string {\n if (status === \"passed\") return \"passed\";\n if (status === \"failed\") return \"failed\";\n if (status === \"skipped\") return \"skipped\";\n return \"broken\";\n}\n\nfunction mapSteps(steps: StepResult[], startTime: number): unknown[] {\n let time = startTime;\n return steps.map((step) => {\n const stepStart = time;\n const stepStop = time + step.durationMs;\n time = stepStop;\n return {\n name: step.selector ? `${step.command} ${JSON.stringify(step.selector)}` : step.command,\n status: allureStatus(step.status),\n start: stepStart,\n stop: stepStop,\n steps: [],\n ...(step.error ? { statusDetails: { message: step.error } } : {}),\n };\n });\n}\n\nfunction copyAttachments(result: FlowResult, outputDir: string): unknown[] {\n const allureAttachments: unknown[] = [];\n\n // Flow-level attachments\n for (const att of result.attachments ?? []) {\n if (att.path && existsSync(att.path)) {\n const ext = att.contentType === \"image/png\" ? \".png\" : \".json\";\n const filename = `${randomUUID()}-attachment${ext}`;\n copyFileSync(att.path, join(outputDir, filename));\n allureAttachments.push({\n name: att.name,\n source: filename,\n type: att.contentType,\n });\n }\n }\n\n // Step-level attachments\n for (const step of result.steps ?? []) {\n for (const att of step.attachments ?? []) {\n if (att.path && existsSync(att.path)) {\n const ext = att.contentType === \"image/png\" ? \".png\" : \".json\";\n const filename = `${randomUUID()}-attachment${ext}`;\n copyFileSync(att.path, join(outputDir, filename));\n allureAttachments.push({\n name: att.name,\n source: filename,\n type: att.contentType,\n });\n }\n }\n }\n\n return allureAttachments;\n}\n\nfunction writeResult(result: FlowResult, outputDir: string): void {\n const uuid = randomUUID();\n const now = Date.now();\n const startTime = now - result.durationMs;\n\n const labels: { name: string; value: string }[] = [\n { name: \"suite\", value: result.platform },\n { name: \"framework\", value: \"spana\" },\n ];\n\n if (result.flaky) {\n labels.push({ name: \"tag\", value: \"flaky\" });\n }\n\n const allureResult: Record<string, unknown> = {\n uuid,\n historyId: historyId(result.name, result.platform),\n name: result.name,\n fullName: `[${result.platform}] ${result.name}`,\n status: result.flaky ? \"passed\" : allureStatus(result.status),\n stage: \"finished\",\n start: startTime,\n stop: now,\n labels,\n steps: result.steps ? mapSteps(result.steps, startTime) : [],\n attachments: copyAttachments(result, outputDir),\n };\n\n if (result.error) {\n allureResult.statusDetails = {\n message: result.error.message,\n trace: result.error.stack,\n };\n } else if (result.flaky) {\n allureResult.statusDetails = {\n message: `Flaky: passed on attempt ${result.attempts}`,\n };\n }\n\n writeFileSync(join(outputDir, `${uuid}-result.json`), JSON.stringify(allureResult, null, 2));\n}\n\nexport function createAllureReporter(outputDir: string = \"allure-results\"): Reporter {\n mkdirSync(outputDir, { recursive: true });\n\n return {\n onFlowPass(result: FlowResult) {\n writeResult(result, outputDir);\n },\n\n onFlowFail(result: FlowResult) {\n writeResult(result, outputDir);\n },\n\n onRunComplete(summary) {\n const envContent = [\n `Platform=${summary.platforms.join(\", \")}`,\n `Framework=spana`,\n `Total=${summary.total}`,\n `Passed=${summary.passed}`,\n `Failed=${summary.failed}`,\n ].join(\"\\n\");\n writeFileSync(join(outputDir, \"environment.properties\"), envContent);\n\n console.log(`Allure results written to ${outputDir}/`);\n console.log(`Run: npx allure generate ${outputDir} --clean -o allure-report`);\n },\n };\n}\n"],"mappings":";;;AAAA,SAAS,YAAY,kBAAkB;AACvC,SAAS,eAAe,WAAW,cAAc,kBAAkB;AACnE,SAAS,YAAY;AAGrB,SAAS,UAAU,MAAc,UAA0B;AACzD,SAAO,WAAW,KAAK,EAAE,OAAO,GAAG,IAAI,IAAI,QAAQ,EAAE,EAAE,OAAO,KAAK;AACrE;AAEA,SAAS,aAAa,QAAwB;AAC5C,MAAI,WAAW,SAAU,QAAO;AAChC,MAAI,WAAW,SAAU,QAAO;AAChC,MAAI,WAAW,UAAW,QAAO;AACjC,SAAO;AACT;AAEA,SAAS,SAAS,OAAqB,WAA8B;AACnE,MAAI,OAAO;AACX,SAAO,MAAM,IAAI,CAAC,SAAS;AACzB,UAAM,YAAY;AAClB,UAAM,WAAW,OAAO,KAAK;AAC7B,WAAO;AACP,WAAO;AAAA,MACL,MAAM,KAAK,WAAW,GAAG,KAAK,OAAO,IAAI,KAAK,UAAU,KAAK,QAAQ,CAAC,KAAK,KAAK;AAAA,MAChF,QAAQ,aAAa,KAAK,MAAM;AAAA,MAChC,OAAO;AAAA,MACP,MAAM;AAAA,MACN,OAAO,CAAC;AAAA,MACR,GAAI,KAAK,QAAQ,EAAE,eAAe,EAAE,SAAS,KAAK,MAAM,EAAE,IAAI,CAAC;AAAA,IACjE;AAAA,EACF,CAAC;AACH;AAEA,SAAS,gBAAgB,QAAoB,WAA8B;AACzE,QAAM,oBAA+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;","names":[]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
adbClearApp,
|
|
3
|
+
adbForceStop,
|
|
4
|
+
adbForward,
|
|
5
|
+
adbInstall,
|
|
6
|
+
adbLaunchApp,
|
|
7
|
+
adbOpenLink,
|
|
8
|
+
adbShell,
|
|
9
|
+
ensureAndroidDevice,
|
|
10
|
+
findADB,
|
|
11
|
+
findEmulator,
|
|
12
|
+
firstAndroidDevice,
|
|
13
|
+
listAVDs,
|
|
14
|
+
listAndroidDevices,
|
|
15
|
+
startEmulator
|
|
16
|
+
} from "./chunk-GZK22EIE.js";
|
|
17
|
+
import "./chunk-DGUM43GV.js";
|
|
18
|
+
export {
|
|
19
|
+
adbClearApp,
|
|
20
|
+
adbForceStop,
|
|
21
|
+
adbForward,
|
|
22
|
+
adbInstall,
|
|
23
|
+
adbLaunchApp,
|
|
24
|
+
adbOpenLink,
|
|
25
|
+
adbShell,
|
|
26
|
+
ensureAndroidDevice,
|
|
27
|
+
findADB,
|
|
28
|
+
findEmulator,
|
|
29
|
+
firstAndroidDevice,
|
|
30
|
+
listAVDs,
|
|
31
|
+
listAndroidDevices,
|
|
32
|
+
startEmulator
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=android-PAPJJWVN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// src/gherkin/registry.ts
|
|
2
|
+
var StepRegistry = class {
|
|
3
|
+
steps = [];
|
|
4
|
+
hooks = [];
|
|
5
|
+
registerStep(keyword, pattern, fn) {
|
|
6
|
+
const patternStr = pattern instanceof RegExp ? pattern.source : pattern;
|
|
7
|
+
const existing = this.steps.find(
|
|
8
|
+
(s) => (s.pattern instanceof RegExp ? s.pattern.source : s.pattern) === patternStr
|
|
9
|
+
);
|
|
10
|
+
if (existing) {
|
|
11
|
+
throw new Error(
|
|
12
|
+
`Duplicate step definition: "${patternStr}" is already registered as a ${existing.keyword} step`
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
this.steps.push({ keyword, pattern, fn });
|
|
16
|
+
}
|
|
17
|
+
registerHook(keyword, fnOrTag, maybeFn) {
|
|
18
|
+
if (typeof fnOrTag === "string") {
|
|
19
|
+
this.hooks.push({ keyword, tagExpression: fnOrTag, fn: maybeFn });
|
|
20
|
+
} else {
|
|
21
|
+
this.hooks.push({ keyword, fn: fnOrTag });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
getSteps() {
|
|
25
|
+
return this.steps;
|
|
26
|
+
}
|
|
27
|
+
getHooks(keyword) {
|
|
28
|
+
return this.hooks.filter((h) => h.keyword === keyword);
|
|
29
|
+
}
|
|
30
|
+
clear() {
|
|
31
|
+
this.steps = [];
|
|
32
|
+
this.hooks = [];
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var globalRegistry = new StepRegistry();
|
|
36
|
+
|
|
37
|
+
// src/gherkin/world.ts
|
|
38
|
+
var currentWorldFactory;
|
|
39
|
+
function defineWorld(definition) {
|
|
40
|
+
const factory = {
|
|
41
|
+
instantiate(flowCtx, state) {
|
|
42
|
+
const worldState = definition.create();
|
|
43
|
+
const combined = Object.assign({}, flowCtx, { state }, worldState);
|
|
44
|
+
if (definition.methods) {
|
|
45
|
+
Object.assign(combined, definition.methods(combined));
|
|
46
|
+
}
|
|
47
|
+
return combined;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
currentWorldFactory = factory;
|
|
51
|
+
return factory;
|
|
52
|
+
}
|
|
53
|
+
function getWorldFactory() {
|
|
54
|
+
return currentWorldFactory;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export {
|
|
58
|
+
globalRegistry,
|
|
59
|
+
defineWorld,
|
|
60
|
+
getWorldFactory
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=chunk-3FSZNKEF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/gherkin/registry.ts","../src/gherkin/world.ts"],"sourcesContent":["import type { ScenarioStepKeyword } from \"../report/types.js\";\nimport type { FlowContext } from \"../api/flow.js\";\n\nexport interface StepHandler<W = unknown> {\n keyword: ScenarioStepKeyword;\n pattern: string | RegExp;\n fn: StepFn<W>;\n}\n\nexport type StepContext<W = unknown> = FlowContext & {\n state: Map<string, unknown>;\n} & (W extends Record<string, unknown> ? W : {});\n\nexport type StepFn<W = unknown> = (ctx: StepContext<W>, ...args: unknown[]) => Promise<void>;\n\nexport interface HookHandler<W = unknown> {\n keyword: \"Before\" | \"After\";\n tagExpression?: string;\n fn: StepFn<W>;\n}\n\nclass StepRegistry {\n private steps: StepHandler[] = [];\n private hooks: HookHandler[] = [];\n\n registerStep(keyword: ScenarioStepKeyword, pattern: string | RegExp, fn: StepFn): void {\n const patternStr = pattern instanceof RegExp ? pattern.source : pattern;\n const existing = this.steps.find(\n (s) => (s.pattern instanceof RegExp ? s.pattern.source : s.pattern) === patternStr,\n );\n if (existing) {\n throw new Error(\n `Duplicate step definition: \"${patternStr}\" is already registered as a ${existing.keyword} step`,\n );\n }\n this.steps.push({ keyword, pattern, fn });\n }\n\n registerHook(keyword: \"Before\" | \"After\", fnOrTag: StepFn | string, maybeFn?: StepFn): void {\n if (typeof fnOrTag === \"string\") {\n this.hooks.push({ keyword, tagExpression: fnOrTag, fn: maybeFn! });\n } else {\n this.hooks.push({ keyword, fn: fnOrTag });\n }\n }\n\n getSteps(): readonly StepHandler[] {\n return this.steps;\n }\n\n getHooks(keyword: \"Before\" | \"After\"): readonly HookHandler[] {\n return this.hooks.filter((h) => h.keyword === keyword);\n }\n\n clear(): void {\n this.steps = [];\n this.hooks = [];\n }\n}\n\nexport const globalRegistry = new StepRegistry();\n","import type { FlowContext } from \"../api/flow.js\";\n\nexport interface WorldDefinition<\n S extends Record<string, unknown>,\n M extends Record<string, unknown>,\n> {\n create: () => S;\n methods?: (ctx: FlowContext & { state: Map<string, unknown> } & S) => M;\n}\n\nexport interface WorldFactory<\n S extends Record<string, unknown>,\n M extends Record<string, unknown>,\n> {\n /** Create a fresh world instance for a scenario run. */\n instantiate(flowCtx: FlowContext, state: Map<string, unknown>): S & M;\n}\n\nlet currentWorldFactory: WorldFactory<any, any> | undefined;\n\nexport function defineWorld<\n S extends Record<string, unknown>,\n M extends Record<string, unknown> = {},\n>(definition: WorldDefinition<S, M>): WorldFactory<S, M> {\n const factory: WorldFactory<S, M> = {\n instantiate(flowCtx, state) {\n const worldState = definition.create();\n // Build a single shared object so methods can mutate state properties directly\n const combined = Object.assign({}, flowCtx, { state }, worldState) as FlowContext & {\n state: Map<string, unknown>;\n } & S &\n M;\n if (definition.methods) {\n Object.assign(combined, definition.methods(combined));\n }\n return combined;\n },\n };\n currentWorldFactory = factory;\n return factory;\n}\n\nexport function getWorldFactory(): WorldFactory<any, any> | undefined {\n return currentWorldFactory;\n}\n\nexport function clearWorldFactory(): void {\n currentWorldFactory = undefined;\n}\n"],"mappings":";AAqBA,IAAM,eAAN,MAAmB;AAAA,EACT,QAAuB,CAAC;AAAA,EACxB,QAAuB,CAAC;AAAA,EAEhC,aAAa,SAA8B,SAA0B,IAAkB;AACrF,UAAM,aAAa,mBAAmB,SAAS,QAAQ,SAAS;AAChE,UAAM,WAAW,KAAK,MAAM;AAAA,MAC1B,CAAC,OAAO,EAAE,mBAAmB,SAAS,EAAE,QAAQ,SAAS,EAAE,aAAa;AAAA,IAC1E;AACA,QAAI,UAAU;AACZ,YAAM,IAAI;AAAA,QACR,+BAA+B,UAAU,gCAAgC,SAAS,OAAO;AAAA,MAC3F;AAAA,IACF;AACA,SAAK,MAAM,KAAK,EAAE,SAAS,SAAS,GAAG,CAAC;AAAA,EAC1C;AAAA,EAEA,aAAa,SAA6B,SAA0B,SAAwB;AAC1F,QAAI,OAAO,YAAY,UAAU;AAC/B,WAAK,MAAM,KAAK,EAAE,SAAS,eAAe,SAAS,IAAI,QAAS,CAAC;AAAA,IACnE,OAAO;AACL,WAAK,MAAM,KAAK,EAAE,SAAS,IAAI,QAAQ,CAAC;AAAA,IAC1C;AAAA,EACF;AAAA,EAEA,WAAmC;AACjC,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,SAAS,SAAqD;AAC5D,WAAO,KAAK,MAAM,OAAO,CAAC,MAAM,EAAE,YAAY,OAAO;AAAA,EACvD;AAAA,EAEA,QAAc;AACZ,SAAK,QAAQ,CAAC;AACd,SAAK,QAAQ,CAAC;AAAA,EAChB;AACF;AAEO,IAAM,iBAAiB,IAAI,aAAa;;;AC1C/C,IAAI;AAEG,SAAS,YAGd,YAAuD;AACvD,QAAM,UAA8B;AAAA,IAClC,YAAY,SAAS,OAAO;AAC1B,YAAM,aAAa,WAAW,OAAO;AAErC,YAAM,WAAW,OAAO,OAAO,CAAC,GAAG,SAAS,EAAE,MAAM,GAAG,UAAU;AAIjE,UAAI,WAAW,SAAS;AACtB,eAAO,OAAO,UAAU,WAAW,QAAQ,QAAQ,CAAC;AAAA,MACtD;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACA,wBAAsB;AACtB,SAAO;AACT;AAEO,SAAS,kBAAsD;AACpE,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import {
|
|
2
|
+
formatConfigValidationError,
|
|
3
|
+
validateConfig
|
|
4
|
+
} from "./chunk-RJ5VPHVX.js";
|
|
5
|
+
|
|
6
|
+
// src/cli/config-loader.ts
|
|
7
|
+
import { existsSync } from "fs";
|
|
8
|
+
import { dirname, isAbsolute, resolve } from "path";
|
|
9
|
+
import { pathToFileURL } from "url";
|
|
10
|
+
import { ZodError } from "zod";
|
|
11
|
+
var DEFAULT_CONFIG_CANDIDATES = ["spana.config.ts", "packages/spana/spana.config.ts"];
|
|
12
|
+
function resolveIfRelative(baseDir, value) {
|
|
13
|
+
if (!value) {
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
return isAbsolute(value) ? value : resolve(baseDir, value);
|
|
17
|
+
}
|
|
18
|
+
function resolveConfigPaths(config, configPath) {
|
|
19
|
+
const configDir = dirname(configPath);
|
|
20
|
+
if (config.flowDir) {
|
|
21
|
+
config.flowDir = resolveIfRelative(configDir, config.flowDir);
|
|
22
|
+
}
|
|
23
|
+
if (config.artifacts?.outputDir) {
|
|
24
|
+
config.artifacts.outputDir = resolveIfRelative(configDir, config.artifacts.outputDir);
|
|
25
|
+
}
|
|
26
|
+
if (config.apps?.web?.appPath) {
|
|
27
|
+
config.apps.web.appPath = resolveIfRelative(configDir, config.apps.web.appPath);
|
|
28
|
+
}
|
|
29
|
+
if (config.apps?.android?.appPath) {
|
|
30
|
+
config.apps.android.appPath = resolveIfRelative(configDir, config.apps.android.appPath);
|
|
31
|
+
}
|
|
32
|
+
if (config.apps?.ios?.appPath) {
|
|
33
|
+
config.apps.ios.appPath = resolveIfRelative(configDir, config.apps.ios.appPath);
|
|
34
|
+
}
|
|
35
|
+
if (config.execution?.appium?.capabilitiesFile) {
|
|
36
|
+
config.execution.appium.capabilitiesFile = resolveIfRelative(
|
|
37
|
+
configDir,
|
|
38
|
+
config.execution.appium.capabilitiesFile
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
if (config.execution?.web?.storageState) {
|
|
42
|
+
config.execution.web.storageState = resolveIfRelative(
|
|
43
|
+
configDir,
|
|
44
|
+
config.execution.web.storageState
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
if (config.execution?.appium?.browserstack?.app?.path) {
|
|
48
|
+
config.execution.appium.browserstack.app.path = resolveIfRelative(
|
|
49
|
+
configDir,
|
|
50
|
+
config.execution.appium.browserstack.app.path
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
if (config.execution?.appium?.browserstack?.local?.binary) {
|
|
54
|
+
config.execution.appium.browserstack.local.binary = resolveIfRelative(
|
|
55
|
+
configDir,
|
|
56
|
+
config.execution.appium.browserstack.local.binary
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
if (config.execution?.appium?.saucelabs?.app?.path) {
|
|
60
|
+
config.execution.appium.saucelabs.app.path = resolveIfRelative(
|
|
61
|
+
configDir,
|
|
62
|
+
config.execution.appium.saucelabs.app.path
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
if (config.execution?.appium?.saucelabs?.connect?.binary) {
|
|
66
|
+
config.execution.appium.saucelabs.connect.binary = resolveIfRelative(
|
|
67
|
+
configDir,
|
|
68
|
+
config.execution.appium.saucelabs.connect.binary
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
return config;
|
|
72
|
+
}
|
|
73
|
+
async function loadConfig(options = {}) {
|
|
74
|
+
const candidates = options.configPath ? [resolve(options.configPath)] : DEFAULT_CONFIG_CANDIDATES.map((candidate) => resolve(candidate));
|
|
75
|
+
const foundPath = candidates.find((candidate) => existsSync(candidate));
|
|
76
|
+
if (!foundPath) {
|
|
77
|
+
if (options.allowMissing && !options.configPath) {
|
|
78
|
+
return { config: {} };
|
|
79
|
+
}
|
|
80
|
+
if (options.configPath) {
|
|
81
|
+
throw new Error(`Config file not found: ${resolve(options.configPath)}`);
|
|
82
|
+
}
|
|
83
|
+
throw new Error(`No config file found. Looked in: ${candidates.join(", ")}`);
|
|
84
|
+
}
|
|
85
|
+
let moduleValue;
|
|
86
|
+
try {
|
|
87
|
+
moduleValue = await import(pathToFileURL(foundPath).href);
|
|
88
|
+
} catch (error) {
|
|
89
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
90
|
+
throw new Error(`Failed to load config at ${foundPath}: ${message}`);
|
|
91
|
+
}
|
|
92
|
+
const rawConfig = "default" in moduleValue ? moduleValue.default : moduleValue;
|
|
93
|
+
try {
|
|
94
|
+
const config = validateConfig(rawConfig);
|
|
95
|
+
return {
|
|
96
|
+
config: resolveConfigPaths(config, foundPath),
|
|
97
|
+
configPath: foundPath
|
|
98
|
+
};
|
|
99
|
+
} catch (error) {
|
|
100
|
+
if (error instanceof ZodError) {
|
|
101
|
+
throw new Error(
|
|
102
|
+
`Config validation failed for ${foundPath}:
|
|
103
|
+
${formatConfigValidationError(error)}`
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export {
|
|
111
|
+
loadConfig
|
|
112
|
+
};
|
|
113
|
+
//# sourceMappingURL=chunk-53MUJUJY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cli/config-loader.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport { dirname, isAbsolute, resolve } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { ZodError } from \"zod\";\nimport { formatConfigValidationError, validateConfig, type ProvConfig } from \"../schemas/config.js\";\n\nconst DEFAULT_CONFIG_CANDIDATES = [\"spana.config.ts\", \"packages/spana/spana.config.ts\"];\n\nexport interface LoadConfigOptions {\n configPath?: string;\n allowMissing?: boolean;\n}\n\nexport interface LoadedConfig {\n config: ProvConfig;\n configPath?: string;\n}\n\nfunction resolveIfRelative(baseDir: string, value?: string): string | undefined {\n if (!value) {\n return value;\n }\n\n return isAbsolute(value) ? value : resolve(baseDir, value);\n}\n\nfunction resolveConfigPaths(config: ProvConfig, configPath: string): ProvConfig {\n const configDir = dirname(configPath);\n\n if (config.flowDir) {\n config.flowDir = resolveIfRelative(configDir, config.flowDir);\n }\n\n if (config.artifacts?.outputDir) {\n config.artifacts.outputDir = resolveIfRelative(configDir, config.artifacts.outputDir);\n }\n\n if (config.apps?.web?.appPath) {\n config.apps.web.appPath = resolveIfRelative(configDir, config.apps.web.appPath);\n }\n\n if (config.apps?.android?.appPath) {\n config.apps.android.appPath = resolveIfRelative(configDir, config.apps.android.appPath);\n }\n\n if (config.apps?.ios?.appPath) {\n config.apps.ios.appPath = resolveIfRelative(configDir, config.apps.ios.appPath);\n }\n\n if (config.execution?.appium?.capabilitiesFile) {\n config.execution.appium.capabilitiesFile = resolveIfRelative(\n configDir,\n config.execution.appium.capabilitiesFile,\n );\n }\n\n if (config.execution?.web?.storageState) {\n config.execution.web.storageState = resolveIfRelative(\n configDir,\n config.execution.web.storageState,\n );\n }\n\n if (config.execution?.appium?.browserstack?.app?.path) {\n config.execution.appium.browserstack.app.path = resolveIfRelative(\n configDir,\n config.execution.appium.browserstack.app.path,\n );\n }\n\n if (config.execution?.appium?.browserstack?.local?.binary) {\n config.execution.appium.browserstack.local.binary = resolveIfRelative(\n configDir,\n config.execution.appium.browserstack.local.binary,\n );\n }\n\n if (config.execution?.appium?.saucelabs?.app?.path) {\n config.execution.appium.saucelabs.app.path = resolveIfRelative(\n configDir,\n config.execution.appium.saucelabs.app.path,\n );\n }\n\n if (config.execution?.appium?.saucelabs?.connect?.binary) {\n config.execution.appium.saucelabs.connect.binary = resolveIfRelative(\n configDir,\n config.execution.appium.saucelabs.connect.binary,\n );\n }\n\n return config;\n}\n\nexport async function loadConfig(options: LoadConfigOptions = {}): Promise<LoadedConfig> {\n const candidates = options.configPath\n ? [resolve(options.configPath)]\n : DEFAULT_CONFIG_CANDIDATES.map((candidate) => resolve(candidate));\n const foundPath = candidates.find((candidate) => existsSync(candidate));\n\n if (!foundPath) {\n if (options.allowMissing && !options.configPath) {\n return { config: {} };\n }\n\n if (options.configPath) {\n throw new Error(`Config file not found: ${resolve(options.configPath)}`);\n }\n\n throw new Error(`No config file found. Looked in: ${candidates.join(\", \")}`);\n }\n\n let moduleValue: Record<string, unknown>;\n try {\n moduleValue = (await import(pathToFileURL(foundPath).href)) as Record<string, unknown>;\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n throw new Error(`Failed to load config at ${foundPath}: ${message}`);\n }\n\n const rawConfig = (\"default\" in moduleValue ? moduleValue.default : moduleValue) as unknown;\n\n try {\n const config = validateConfig(rawConfig);\n return {\n config: resolveConfigPaths(config, foundPath),\n configPath: foundPath,\n };\n } catch (error) {\n if (error instanceof ZodError) {\n throw new Error(\n `Config validation failed for ${foundPath}:\\n${formatConfigValid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OAAO,cAAc,SAAS,EAAE;AAAA,EACvD,SAAS,OAAO;AACd,UAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AACrE,UAAM,IAAI,MAAM,4BAA4B,SAAS,KAAK,OAAO,EAAE;AAAA,EACrE;AAEA,QAAM,YAAa,aAAa,cAAc,YAAY,UAAU;AAEpE,MAAI;AACF,UAAM,SAAS,eAAe,SAAS;AACvC,WAAO;AAAA,MACL,QAAQ,mBAAmB,QAAQ,SAAS;AAAA,MAC5C,YAAY;AAAA,IACd;AAAA,EACF,SAAS,OAAO;AACd,QAAI,iBAAiB,UAAU;AAC7B,YAAM,IAAI;AAAA,QACR,gCAAgC,SAAS;AAAA,EAAM,4BAA4B,KAAK,CAAC;AAAA,MACnF;AAAA,IACF;AACA,UAAM;AAAA,EACR;AACF;","names":[]}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// src/core/runner.ts
|
|
2
|
+
import { readdir, readFile, stat } from "fs/promises";
|
|
3
|
+
import { join, resolve } from "path";
|
|
4
|
+
async function loadFlowFile(filePath) {
|
|
5
|
+
const absolutePath = resolve(filePath);
|
|
6
|
+
const mod = await import(absolutePath);
|
|
7
|
+
if (!mod.default) {
|
|
8
|
+
throw new Error(`No default export found in ${filePath}`);
|
|
9
|
+
}
|
|
10
|
+
const flowDef = mod.default;
|
|
11
|
+
if (!flowDef.name || typeof flowDef.fn !== "function") {
|
|
12
|
+
throw new Error(`Invalid flow definition in ${filePath}`);
|
|
13
|
+
}
|
|
14
|
+
if (mod.settings) {
|
|
15
|
+
Object.assign(flowDef.config, mod.settings);
|
|
16
|
+
}
|
|
17
|
+
return flowDef;
|
|
18
|
+
}
|
|
19
|
+
async function loadTestSource(filePath) {
|
|
20
|
+
const absolutePath = resolve(filePath);
|
|
21
|
+
if (absolutePath.endsWith(".feature")) {
|
|
22
|
+
return loadFeatureFile(absolutePath);
|
|
23
|
+
}
|
|
24
|
+
const flow = await loadFlowFile(absolutePath);
|
|
25
|
+
return [flow];
|
|
26
|
+
}
|
|
27
|
+
async function loadFeatureFile(filePath) {
|
|
28
|
+
let compileFeature;
|
|
29
|
+
try {
|
|
30
|
+
const mod = await import("./compiler-G75RIIYS.js");
|
|
31
|
+
compileFeature = mod.compileFeature;
|
|
32
|
+
} catch {
|
|
33
|
+
throw new Error(
|
|
34
|
+
`Cannot load .feature files: install @cucumber/gherkin, @cucumber/messages, and @cucumber/cucumber-expressions as dependencies.`
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
const source = await readFile(filePath, "utf-8");
|
|
38
|
+
return compileFeature(source, filePath);
|
|
39
|
+
}
|
|
40
|
+
async function loadStepFiles(paths) {
|
|
41
|
+
for (const p of paths) {
|
|
42
|
+
await import(resolve(p));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async function discoverFlows(pathOrDir) {
|
|
46
|
+
const absolute = resolve(pathOrDir);
|
|
47
|
+
const stats = await stat(absolute);
|
|
48
|
+
if (!stats.isDirectory()) {
|
|
49
|
+
return [absolute];
|
|
50
|
+
}
|
|
51
|
+
const results = [];
|
|
52
|
+
async function walk(dir) {
|
|
53
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
54
|
+
for (const entry of entries) {
|
|
55
|
+
const fullPath = join(dir, entry.name);
|
|
56
|
+
if (entry.isDirectory()) {
|
|
57
|
+
await walk(fullPath);
|
|
58
|
+
} else if (entry.name.endsWith(".flow.ts") || entry.name.endsWith(".test.ts") || entry.name.endsWith(".feature")) {
|
|
59
|
+
results.push(fullPath);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
await walk(absolute);
|
|
64
|
+
return results.sort();
|
|
65
|
+
}
|
|
66
|
+
async function discoverStepFiles(pathOrDir) {
|
|
67
|
+
const absolute = resolve(pathOrDir);
|
|
68
|
+
const stats = await stat(absolute).catch(() => null);
|
|
69
|
+
if (!stats?.isDirectory()) return [];
|
|
70
|
+
const results = [];
|
|
71
|
+
async function walk(dir) {
|
|
72
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
73
|
+
for (const entry of entries) {
|
|
74
|
+
const fullPath = join(dir, entry.name);
|
|
75
|
+
if (entry.isDirectory()) {
|
|
76
|
+
await walk(fullPath);
|
|
77
|
+
} else if (entry.name.endsWith(".steps.ts") || dir.includes("/steps")) {
|
|
78
|
+
if (entry.name.endsWith(".ts")) {
|
|
79
|
+
results.push(fullPath);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
await walk(absolute);
|
|
85
|
+
return results.sort();
|
|
86
|
+
}
|
|
87
|
+
function filterFlows(flows, opts) {
|
|
88
|
+
return flows.filter((flow) => {
|
|
89
|
+
if (opts.tags && opts.tags.length > 0) {
|
|
90
|
+
const flowTags = flow.config.tags ?? [];
|
|
91
|
+
if (!opts.tags.some((t) => flowTags.includes(t))) return false;
|
|
92
|
+
}
|
|
93
|
+
if (opts.grep) {
|
|
94
|
+
if (!flow.name.toLowerCase().includes(opts.grep.toLowerCase())) return false;
|
|
95
|
+
}
|
|
96
|
+
if (opts.platforms && opts.platforms.length > 0) {
|
|
97
|
+
const flowPlatforms = flow.config.platforms;
|
|
98
|
+
if (flowPlatforms && !opts.platforms.some((p) => flowPlatforms.includes(p))) return false;
|
|
99
|
+
}
|
|
100
|
+
if (flow.config.when) {
|
|
101
|
+
const when = flow.config.when;
|
|
102
|
+
if (when.platform) {
|
|
103
|
+
const allowedPlatforms = Array.isArray(when.platform) ? when.platform : [when.platform];
|
|
104
|
+
if (opts.platforms && opts.platforms.length > 0) {
|
|
105
|
+
if (!opts.platforms.some((p) => allowedPlatforms.includes(p))) return false;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (when.env && !process.env[when.env]) {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return true;
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
function applyShard(items, shard) {
|
|
116
|
+
if (!shard || shard.total === 1 || items.length === 0) {
|
|
117
|
+
return items;
|
|
118
|
+
}
|
|
119
|
+
const itemsPerShard = Math.max(Math.ceil(items.length / shard.total), 1);
|
|
120
|
+
const start = (shard.current - 1) * itemsPerShard;
|
|
121
|
+
const end = shard.current === shard.total ? items.length : Math.min(start + itemsPerShard, items.length);
|
|
122
|
+
return items.slice(start, end);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export {
|
|
126
|
+
loadFlowFile,
|
|
127
|
+
loadTestSource,
|
|
128
|
+
loadStepFiles,
|
|
129
|
+
discoverFlows,
|
|
130
|
+
discoverStepFiles,
|
|
131
|
+
filterFlows,
|
|
132
|
+
applyShard
|
|
133
|
+
};
|
|
134
|
+
//# sourceMappingURL=chunk-5XO6S7AI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/runner.ts"],"sourcesContent":["import { readdir, readFile, stat } from \"node:fs/promises\";\nimport { join, resolve } from \"node:path\";\nimport type { FlowDefinition, FlowConfig } from \"../api/flow.js\";\nimport type { Platform } from \"../schemas/selector.js\";\n\nexport interface DiscoverOptions {\n tags?: string[];\n grep?: string;\n platforms?: Platform[];\n /** Glob patterns for step definition files (relative to flowDir). */\n stepFiles?: string[];\n}\n\nexport interface ShardOptions {\n current: number;\n total: number;\n}\n\nexport async function loadFlowFile(filePath: string): Promise<FlowDefinition> {\n const absolutePath = resolve(filePath);\n const mod = await import(absolutePath);\n\n if (!mod.default) {\n throw new Error(`No default export found in ${filePath}`);\n }\n\n const flowDef = mod.default as FlowDefinition;\n if (!flowDef.name || typeof flowDef.fn !== \"function\") {\n throw new Error(`Invalid flow definition in ${filePath}`);\n }\n\n // Merge exported settings if present\n if (mod.settings) {\n Object.assign(flowDef.config, mod.settings as FlowConfig);\n }\n\n return flowDef;\n}\n\n/**\n * Load a test source file and return one or more FlowDefinitions.\n * Handles both native .flow.ts/.test.ts files and .feature files.\n */\nexport async function loadTestSource(filePath: string): Promise<FlowDefinition[]> {\n const absolutePath = resolve(filePath);\n\n if (absolutePath.endsWith(\".feature\")) {\n return loadFeatureFile(absolutePath);\n }\n\n const flow = await loadFlowFile(absolutePath);\n return [flow];\n}\n\nasync function loadFeatureFile(filePath: string): Promise<FlowDefinition[]> {\n let compileFeature: typeof import(\"../gherkin/compiler.js\").compileFeature;\n try {\n const mod = await import(\"../gherkin/compiler.js\");\n compileFeature = mod.compileFeature;\n } catch {\n throw new Error(\n `Cannot load .feature files: install @cucumber/gherkin, @cucumber/messages, and @cucumber/cucumber-expressions as dependencies.`,\n );\n }\n\n const source = await readFile(filePath, \"utf-8\");\n return compileFeature(source, filePath);\n}\n\n/**\n * Load step definition files so their Given/When/Then registrations\n * are available before feature compilation.\n */\nexport async function loadStepFiles(paths: string[]): Promise<void> {\n for (const p of paths) {\n await import(resolve(p));\n }\n}\n\nexport async function discoverFlows(pathOrDir: string): Promise<string[]> {\n const absolute = resolve(pathOrDir);\n const stats = await stat(absolute);\n\n if (!stats.isDirectory()) {\n return [absolute];\n }\n\n const results: string[] = [];\n\n async function walk(dir: string): Promise<void> {\n const entries = await readdir(dir, { withFileTypes: true });\n for (const entry of entries) {\n const fullPath = join(dir, entry.name);\n if (entry.isDirectory()) {\n await walk(fullPath);\n } else if (\n entry.name.endsWith(\".flow.ts\") ||\n entry.name.endsWith(\".test.ts\") ||\n entry.name.endsWith(\".feature\")\n ) {\n results.push(fullPath);\n }\n }\n }\n\n await walk(absolute);\n return results.sort();\n}\n\n/**\n * Discover step definition files within a directory.\n * Looks for files in steps/ directories or matching *.steps.ts pattern.\n */\nexport async function discoverStepFiles(pathOrDir: string): Promise<string[]> {\n const absolute = resolve(pathOrDir);\n const stats = await stat(absolute).catch(() => null);\n if (!stats?.isDirectory()) return [];\n\n const results: string[] = [];\n\n async function walk(dir: string): Promise<void> {\n const entries = await readdir(dir, { withFileTypes: true });\n for (const entry of entries) {\n const fullPath = join(dir, entry.name);\n if (entry.isDirectory()) {\n await walk(fullPath);\n } else if (entry.name.endsWith(\".steps.ts\") || dir.includes(\"/steps\")) {\n if (entry.name.endsWith(\".ts\")) {\n results.push(fullPath);\n }\n }\n }\n }\n\n await walk(absolute);\n return results.sort();\n}\n\nexport function filterFlows(flows: FlowDefinition[], opts: DiscoverOptions): FlowDefinition[] {\n return flows.filter((flow) => {\n if (opts.tags && opts.tags.length > 0) {\n const flowTags = flow.config.tags ?? [];\n if (!opts.tags.some((t) => flowTags.includes(t))) return false;\n }\n if (opts.grep) {\n if (!flow.name.toLowerCase().includes(opts.grep.toLowerCase())) return false;\n }\n if (opts.platforms && opts.platforms.length > 0) {\n const flowPlatforms = flow.config.platforms;\n if (flowPlatforms && !opts.platforms.some((p) => flowPlatforms.includes(p))) return false;\n }\n // Evaluate when conditions\n if (flow.config.when) {\n const when = flow.config.when;\n\n if (when.platform) {\n const allowedPlatforms = Array.isArray(when.platform) ? when.platform : [when.platform];\n if (opts.platforms && opts.platforms.length > 0) {\n if (!opts.platforms.some((p) => allowedPlatforms.includes(p))) return false;\n }\n }\n\n if (when.env && !process.env[when.env]) {\n return false;\n }\n }\n return true;\n });\n}\n\nexport function applyShard<T>(items: T[], shard?: ShardOptions): T[] {\n if (!shard || shard.total === 1 || items.length === 0) {\n return items;\n }\n\n const itemsPerShard = Math.max(Math.ceil(items.length / shard.total), 1);\n const start = (shard.current - 1) * itemsPerShard;\n const end =\n shard.current === shard.total ? items.length : Math.min(start + itemsPerShard, items.length);\n\n return items.slice(start, end);\n}\n"],"mappings":";AAAA,SAAS,SAAS,UAAU,YAAY;AACxC,SAAS,MAAM,eAAe;AAiB9B,eAAsB,aAAa,UAA2C;AAC5E,QAAM,eAAe,QAAQ,QAAQ;AACrC,QAAM,MAAM,MAAM,OAAO;AAEzB,MAAI,CAAC,IAAI,SAAS;AAChB,UAAM,IAAI,MAAM,8BAA8B,QAAQ,EAAE;AAAA,EAC1D;AAEA,QAAM,UAAU,IAAI;AACpB,MAAI,CAAC,QAAQ,QAAQ,OAAO,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C,YAAM,gBAAgB,KAAK,OAAO;AAClC,UAAI,iBAAiB,CAAC,KAAK,UAAU,KAAK,CAAC,MAAM,cAAc,SAAS,CAAC,CAAC,EAAG,QAAO;AAAA,IACtF;AAEA,QAAI,KAAK,OAAO,MAAM;AACpB,YAAM,OAAO,KAAK,OAAO;AAEzB,UAAI,KAAK,UAAU;AACjB,cAAM,mBAAmB,MAAM,QAAQ,KAAK,QAAQ,IAAI,KAAK,WAAW,CAAC,KAAK,QAAQ;AACtF,YAAI,KAAK,aAAa,KAAK,UAAU,SAAS,GAAG;AAC/C,cAAI,CAAC,KAAK,UAAU,KAAK,CAAC,MAAM,iBAAiB,SAAS,CAAC,CAAC,EAAG,QAAO;AAAA,QACxE;AAAA,MACF;AAEA,UAAI,KAAK,OAAO,CAAC,QAAQ,IAAI,KAAK,GAAG,GAAG;AACtC,eAAO;AAAA,MACT;AAAA,IACF;AACA,WAAO;AAAA,EACT,CAAC;AACH;AAEO,SAAS,WAAc,OAAY,OAA2B;AACnE,MAAI,CAAC,SAAS,MAAM,UAAU,KAAK,MAAM,WAAW,GAAG;AACrD,WAAO;AAAA,EACT;AAEA,QAAM,gBAAgB,KAAK,IAAI,KAAK,KAAK,MAAM,SAAS,MAAM,KAAK,GAAG,CAAC;AACvE,QAAM,SAAS,MAAM,UAAU,KAAK;AACpC,QAAM,MACJ,MAAM,YAAY,MAAM,QAAQ,MAAM,SAAS,KAAK,IAAI,QAAQ,eAAe,MAAM,MAAM;AAE7F,SAAO,MAAM,MAAM,OAAO,GAAG;AAC/B;","names":[]}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import {
|
|
2
|
+
discoverFlows
|
|
3
|
+
} from "./chunk-5XO6S7AI.js";
|
|
4
|
+
|
|
5
|
+
// src/core/validator.ts
|
|
6
|
+
import { resolve } from "path";
|
|
7
|
+
async function validateFlowFile(filePath) {
|
|
8
|
+
try {
|
|
9
|
+
const absolutePath = resolve(filePath);
|
|
10
|
+
const mod = await import(absolutePath);
|
|
11
|
+
if (!mod.default) {
|
|
12
|
+
return { file: filePath, error: "No default export found" };
|
|
13
|
+
}
|
|
14
|
+
const def = mod.default;
|
|
15
|
+
if (!def.name || typeof def.fn !== "function") {
|
|
16
|
+
return { file: filePath, error: "Invalid flow definition: missing name or fn" };
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
} catch (e) {
|
|
20
|
+
return {
|
|
21
|
+
file: filePath,
|
|
22
|
+
error: `Failed to import: ${e instanceof Error ? e.message : String(e)}`
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async function validateFlows(paths) {
|
|
27
|
+
const errors = [];
|
|
28
|
+
for (const path of paths) {
|
|
29
|
+
const err = await validateFlowFile(path);
|
|
30
|
+
if (err) errors.push(err);
|
|
31
|
+
}
|
|
32
|
+
return errors;
|
|
33
|
+
}
|
|
34
|
+
var VALID_PLATFORMS = /* @__PURE__ */ new Set(["web", "android", "ios"]);
|
|
35
|
+
async function validateProject(flowDir) {
|
|
36
|
+
const errors = [];
|
|
37
|
+
let paths;
|
|
38
|
+
try {
|
|
39
|
+
paths = await discoverFlows(flowDir);
|
|
40
|
+
} catch {
|
|
41
|
+
errors.push({ file: flowDir, error: "Flow directory does not exist" });
|
|
42
|
+
return errors;
|
|
43
|
+
}
|
|
44
|
+
if (paths.length === 0) {
|
|
45
|
+
errors.push({ file: flowDir, error: "No flow files found" });
|
|
46
|
+
return errors;
|
|
47
|
+
}
|
|
48
|
+
errors.push(...await validateFlows(paths));
|
|
49
|
+
const flowNames = /* @__PURE__ */ new Map();
|
|
50
|
+
for (const p of paths) {
|
|
51
|
+
try {
|
|
52
|
+
const mod = await import(resolve(p));
|
|
53
|
+
const def = mod.default;
|
|
54
|
+
if (!def?.name) continue;
|
|
55
|
+
const existing = flowNames.get(def.name);
|
|
56
|
+
if (existing) {
|
|
57
|
+
errors.push({ file: p, error: `Duplicate flow name "${def.name}" (also in ${existing})` });
|
|
58
|
+
} else {
|
|
59
|
+
flowNames.set(def.name, p);
|
|
60
|
+
}
|
|
61
|
+
if (def.config?.platforms) {
|
|
62
|
+
for (const plat of def.config.platforms) {
|
|
63
|
+
if (!VALID_PLATFORMS.has(plat)) {
|
|
64
|
+
errors.push({
|
|
65
|
+
file: p,
|
|
66
|
+
error: `Invalid platform "${plat}" \u2014 must be web, android, or ios`
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
} catch {
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return errors;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export {
|
|
78
|
+
validateFlowFile,
|
|
79
|
+
validateFlows,
|
|
80
|
+
validateProject
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=chunk-BZRLA4Z3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/validator.ts"],"sourcesContent":["import { resolve } from \"node:path\";\nimport { discoverFlows } from \"./runner.js\";\n\nexport interface ValidationError {\n file: string;\n error: string;\n}\n\nexport async function validateFlowFile(filePath: string): Promise<ValidationError | null> {\n try {\n const absolutePath = resolve(filePath);\n const mod = await import(absolutePath);\n if (!mod.default) {\n return { file: filePath, error: \"No default export found\" };\n }\n const def = mod.default;\n if (!def.name || typeof def.fn !== \"function\") {\n return { file: filePath, error: \"Invalid flow definition: missing name or fn\" };\n }\n return null;\n } catch (e) {\n return {\n file: filePath,\n error: `Failed to import: ${e instanceof Error ? e.message : String(e)}`,\n };\n }\n}\n\nexport async function validateFlows(paths: string[]): Promise<ValidationError[]> {\n const errors: ValidationError[] = [];\n for (const path of paths) {\n const err = await validateFlowFile(path);\n if (err) errors.push(err);\n }\n return errors;\n}\n\nconst VALID_PLATFORMS = new Set([\"web\", \"android\", \"ios\"]);\n\nexport async function validateProject(flowDir: string): Promise<ValidationError[]> {\n const errors: ValidationError[] = [];\n\n // Check flow directory exists and has flows\n let paths: string[];\n try {\n paths = await discoverFlows(flowDir);\n } catch {\n errors.push({ file: flowDir, error: \"Flow directory does not exist\" });\n return errors;\n }\n\n if (paths.length === 0) {\n errors.push({ file: flowDir, error: \"No flow files found\" });\n return errors;\n }\n\n // Validate individual flow files (structure check)\n errors.push(...(await validateFlows(paths)));\n\n // Load flows and check for duplicates + invalid platforms\n const flowNames = new Map<string, string>(); // name -> file\n\n for (const p of paths) {\n try {\n const mod = await import(resolve(p));\n const def = mod.default;\n if (!def?.name) continue;\n\n // Duplicate name check\n const existing = flowNames.get(def.name);\n if (existing) {\n errors.push({ file: p, error: `Duplicate flow name \"${def.name}\" (also in ${existing})` });\n } else {\n flowNames.set(def.name, p);\n }\n\n // Platform validation\n if (def.config?.platforms) {\n for (const plat of def.config.platforms) {\n if (!VALID_PLATFORMS.has(plat)) {\n errors.push({\n file: p,\n error: `Invalid platform \"${plat}\" — must be web, android, or ios`,\n });\n }\n }\n }\n } catch {\n // Already caught by validateFlows\n }\n }\n\n return errors;\n}\n"],"mappings":";;;;;AAAA,SAAS,eAAe;AAQxB,eAAsB,iBAAiB,UAAmD;AACxF,MAAI;AACF,UAAM,eAAe,QAAQ,QAAQ;AACrC,UAAM,MAAM,MAAM,OAAO;AACzB,QAAI,CAAC,IAAI,SAAS;AAChB,aAAO,EAAE,MAAM,UAAU,OAAO,0BAA0B;AAAA,IAC5D;AACA,UAAM,MAAM,IAAI;AAChB,QAAI,CAAC,IAAI,QAAQ,OAAO,IAAI,OAAO,YAAY;AAC7C,aAAO,EAAE,MAAM,UAAU,OAAO,8CAA8C;AAAA,IAChF;AACA,WAAO;AAAA,EACT,SAAS,GAAG;AACV,WAAO;AAAA,MACL,MAAM;AAAA,MACN,OAAO,qBAAqB,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,CAAC;AAAA,IACxE;AAAA,EACF;AACF;AAEA,eAAsB,cAAc,OAA6C;AAC/E,QAAM,SAA4B,CAAC;AACnC,aAAW,QAAQ,OAAO;AACxB,UAAM,MAAM,MAAM,i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