spana-test 0.0.1
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/LICENSE +201 -0
- package/dist/chunk-HKDZMXD7.js +221 -0
- package/dist/chunk-HKDZMXD7.js.map +1 -0
- package/dist/chunk-PF7V37UD.js +1781 -0
- package/dist/chunk-PF7V37UD.js.map +1 -0
- package/dist/chunk-Y7MNYLGH.js +64 -0
- package/dist/chunk-Y7MNYLGH.js.map +1 -0
- package/dist/cli.js +115 -0
- package/dist/cli.js.map +1 -0
- package/dist/console-ZH3SUKUO.js +71 -0
- package/dist/console-ZH3SUKUO.js.map +1 -0
- package/dist/discover-4EZKZ5RO.js +53 -0
- package/dist/discover-4EZKZ5RO.js.map +1 -0
- package/dist/html-OGRQ5NIX.js +164 -0
- package/dist/html-OGRQ5NIX.js.map +1 -0
- package/dist/index.d.ts +157 -0
- package/dist/index.js +188 -0
- package/dist/index.js.map +1 -0
- package/dist/json-3TZD6FI5.js +20 -0
- package/dist/json-3TZD6FI5.js.map +1 -0
- package/dist/junit-ES66OYVX.js +87 -0
- package/dist/junit-ES66OYVX.js.map +1 -0
- package/dist/runner-NGLCXD2E.js +12 -0
- package/dist/runner-NGLCXD2E.js.map +1 -0
- package/dist/session-NWNZWWNI.js +122 -0
- package/dist/session-NWNZWWNI.js.map +1 -0
- package/dist/test-command-F3AEHF2E.js +636 -0
- package/dist/test-command-F3AEHF2E.js.map +1 -0
- package/dist/validator-LHN66ZH7.js +33 -0
- package/dist/validator-LHN66ZH7.js.map +1 -0
- package/package.json +61 -0
|
@@ -0,0 +1,636 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import {
|
|
3
|
+
discoverFlows,
|
|
4
|
+
filterFlows,
|
|
5
|
+
loadFlowFile
|
|
6
|
+
} from "./chunk-Y7MNYLGH.js";
|
|
7
|
+
import {
|
|
8
|
+
ElementNotFoundError,
|
|
9
|
+
TextMismatchError,
|
|
10
|
+
WaitTimeoutError,
|
|
11
|
+
centerOf,
|
|
12
|
+
createUiAutomator2Driver,
|
|
13
|
+
createWDADriver,
|
|
14
|
+
findElement,
|
|
15
|
+
makePlaywrightDriver,
|
|
16
|
+
parseAndroidHierarchy,
|
|
17
|
+
parseIOSHierarchy,
|
|
18
|
+
parseWebHierarchy,
|
|
19
|
+
setupUiAutomator2,
|
|
20
|
+
setupWDA
|
|
21
|
+
} from "./chunk-PF7V37UD.js";
|
|
22
|
+
import {
|
|
23
|
+
bootSimulator,
|
|
24
|
+
firstAndroidDevice,
|
|
25
|
+
firstIOSSimulatorWithApp
|
|
26
|
+
} from "./chunk-HKDZMXD7.js";
|
|
27
|
+
|
|
28
|
+
// src/cli/test-command.ts
|
|
29
|
+
import { resolve, dirname } from "path";
|
|
30
|
+
import { Effect as Effect6 } from "effect";
|
|
31
|
+
|
|
32
|
+
// src/api/app.ts
|
|
33
|
+
import { Effect as Effect3 } from "effect";
|
|
34
|
+
|
|
35
|
+
// src/smart/coordinator.ts
|
|
36
|
+
import { Effect as Effect2 } from "effect";
|
|
37
|
+
|
|
38
|
+
// src/smart/auto-wait.ts
|
|
39
|
+
import { Duration, Effect } from "effect";
|
|
40
|
+
var DEFAULT_TIMEOUT = 5e3;
|
|
41
|
+
var DEFAULT_POLL_INTERVAL = 200;
|
|
42
|
+
function waitForElement(driver, selector, parse, opts) {
|
|
43
|
+
const timeout = opts?.timeout ?? DEFAULT_TIMEOUT;
|
|
44
|
+
const pollInterval = opts?.pollInterval ?? DEFAULT_POLL_INTERVAL;
|
|
45
|
+
return Effect.gen(function* () {
|
|
46
|
+
const start = Date.now();
|
|
47
|
+
while (Date.now() - start < timeout) {
|
|
48
|
+
const raw = yield* driver.dumpHierarchy();
|
|
49
|
+
const root = parse(raw);
|
|
50
|
+
const element = findElement(root, selector);
|
|
51
|
+
if (element) return element;
|
|
52
|
+
yield* Effect.sleep(Duration.millis(pollInterval));
|
|
53
|
+
}
|
|
54
|
+
return yield* new ElementNotFoundError({
|
|
55
|
+
message: `Element not found within ${timeout}ms`,
|
|
56
|
+
selector,
|
|
57
|
+
timeoutMs: timeout
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function waitForNotVisible(driver, selector, parse, opts) {
|
|
62
|
+
const timeout = opts?.timeout ?? DEFAULT_TIMEOUT;
|
|
63
|
+
const pollInterval = opts?.pollInterval ?? DEFAULT_POLL_INTERVAL;
|
|
64
|
+
return Effect.gen(function* () {
|
|
65
|
+
const start = Date.now();
|
|
66
|
+
while (Date.now() - start < timeout) {
|
|
67
|
+
const raw = yield* driver.dumpHierarchy();
|
|
68
|
+
const root = parse(raw);
|
|
69
|
+
const element = findElement(root, selector);
|
|
70
|
+
if (!element) return;
|
|
71
|
+
yield* Effect.sleep(Duration.millis(pollInterval));
|
|
72
|
+
}
|
|
73
|
+
return yield* new WaitTimeoutError({
|
|
74
|
+
message: `Element still visible after ${timeout}ms`,
|
|
75
|
+
selector,
|
|
76
|
+
timeoutMs: timeout
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// src/smart/coordinator.ts
|
|
82
|
+
function createCoordinator(driver, config) {
|
|
83
|
+
const { parse, defaults } = config;
|
|
84
|
+
return {
|
|
85
|
+
tap: (selector, opts) => Effect2.gen(function* () {
|
|
86
|
+
const element = yield* waitForElement(driver, selector, parse, { ...defaults, ...opts });
|
|
87
|
+
const { x, y } = centerOf(element);
|
|
88
|
+
yield* driver.tapAtCoordinate(x, y);
|
|
89
|
+
}),
|
|
90
|
+
tapXY: (x, y) => driver.tapAtCoordinate(x, y),
|
|
91
|
+
doubleTap: (selector, opts) => Effect2.gen(function* () {
|
|
92
|
+
const element = yield* waitForElement(driver, selector, parse, { ...defaults, ...opts });
|
|
93
|
+
const { x, y } = centerOf(element);
|
|
94
|
+
yield* driver.doubleTapAtCoordinate(x, y);
|
|
95
|
+
}),
|
|
96
|
+
longPress: (selector, duration = 1e3, opts) => Effect2.gen(function* () {
|
|
97
|
+
const element = yield* waitForElement(driver, selector, parse, { ...defaults, ...opts });
|
|
98
|
+
const { x, y } = centerOf(element);
|
|
99
|
+
yield* driver.longPressAtCoordinate(x, y, duration);
|
|
100
|
+
}),
|
|
101
|
+
longPressXY: (x, y, duration = 1e3) => driver.longPressAtCoordinate(x, y, duration),
|
|
102
|
+
inputText: (text) => driver.inputText(text),
|
|
103
|
+
pressKey: (key) => driver.pressKey(key),
|
|
104
|
+
hideKeyboard: () => driver.hideKeyboard(),
|
|
105
|
+
swipe: (direction, opts) => Effect2.gen(function* () {
|
|
106
|
+
const w = config.screenWidth ?? 1080;
|
|
107
|
+
const h = config.screenHeight ?? 1920;
|
|
108
|
+
const cx = w / 2;
|
|
109
|
+
const cy = h / 2;
|
|
110
|
+
const dur = opts?.duration ?? 300;
|
|
111
|
+
const dist = Math.min(w, h) * 0.4;
|
|
112
|
+
const coords = {
|
|
113
|
+
up: { startX: cx, startY: cy + dist / 2, endX: cx, endY: cy - dist / 2 },
|
|
114
|
+
down: { startX: cx, startY: cy - dist / 2, endX: cx, endY: cy + dist / 2 },
|
|
115
|
+
left: { startX: cx + dist / 2, startY: cy, endX: cx - dist / 2, endY: cy },
|
|
116
|
+
right: { startX: cx - dist / 2, startY: cy, endX: cx + dist / 2, endY: cy }
|
|
117
|
+
}[direction];
|
|
118
|
+
yield* driver.swipe(coords.startX, coords.startY, coords.endX, coords.endY, dur);
|
|
119
|
+
}),
|
|
120
|
+
scroll: (direction) => Effect2.gen(function* () {
|
|
121
|
+
const w = config.screenWidth ?? 1080;
|
|
122
|
+
const h = config.screenHeight ?? 1920;
|
|
123
|
+
const cx = w / 2;
|
|
124
|
+
const cy = h / 2;
|
|
125
|
+
const dist = Math.min(w, h) * 0.3;
|
|
126
|
+
const coords = {
|
|
127
|
+
up: { startX: cx, startY: cy + dist, endX: cx, endY: cy - dist },
|
|
128
|
+
down: { startX: cx, startY: cy - dist, endX: cx, endY: cy + dist },
|
|
129
|
+
left: { startX: cx + dist, startY: cy, endX: cx - dist, endY: cy },
|
|
130
|
+
right: { startX: cx - dist, startY: cy, endX: cx + dist, endY: cy }
|
|
131
|
+
}[direction];
|
|
132
|
+
yield* driver.swipe(coords.startX, coords.startY, coords.endX, coords.endY, 500);
|
|
133
|
+
}),
|
|
134
|
+
assertVisible: (selector, opts) => waitForElement(driver, selector, parse, { ...defaults, ...opts }),
|
|
135
|
+
assertHidden: (selector, opts) => waitForNotVisible(driver, selector, parse, { ...defaults, ...opts }),
|
|
136
|
+
assertText: (selector, expected, opts) => Effect2.gen(function* () {
|
|
137
|
+
const element = yield* waitForElement(driver, selector, parse, { ...defaults, ...opts });
|
|
138
|
+
if (element.text !== expected) {
|
|
139
|
+
return yield* new TextMismatchError({
|
|
140
|
+
message: `Expected text "${expected}" but got "${element.text ?? "(no text)"}"`,
|
|
141
|
+
expected,
|
|
142
|
+
actual: element.text,
|
|
143
|
+
selector
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
})
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// src/api/app.ts
|
|
151
|
+
function createPromiseApp(driver, appId, config, recorder) {
|
|
152
|
+
const coord = createCoordinator(driver, config);
|
|
153
|
+
const run = (effect) => Effect3.runPromise(effect);
|
|
154
|
+
const runStep = (command, action, opts) => recorder ? recorder.runStep(command, action, opts) : action();
|
|
155
|
+
const runScreenshotStep = (command, action, opts) => recorder ? recorder.runScreenshotStep(command, action, opts) : action();
|
|
156
|
+
return {
|
|
157
|
+
tap: (selector, opts) => runStep("tap", () => run(coord.tap(selector, opts)), { selector, captureScreenshot: true }),
|
|
158
|
+
tapXY: (x, y) => runStep("tapXY", () => run(coord.tapXY(x, y)), {
|
|
159
|
+
selector: { point: { x, y } },
|
|
160
|
+
captureScreenshot: true
|
|
161
|
+
}),
|
|
162
|
+
doubleTap: (selector, opts) => runStep("doubleTap", () => run(coord.doubleTap(selector, opts)), { selector, captureScreenshot: true }),
|
|
163
|
+
longPress: (selector, opts) => runStep("longPress", () => run(coord.longPress(selector, opts?.duration, opts)), { selector, captureScreenshot: true }),
|
|
164
|
+
longPressXY: (x, y, opts) => runStep("longPressXY", () => run(coord.longPressXY(x, y, opts?.duration)), {
|
|
165
|
+
selector: { point: { x, y } },
|
|
166
|
+
captureScreenshot: true
|
|
167
|
+
}),
|
|
168
|
+
inputText: (text) => runStep("inputText", () => run(driver.inputText(text)), { captureScreenshot: true }),
|
|
169
|
+
pressKey: (key) => runStep(`pressKey(${key})`, () => run(driver.pressKey(key)), { captureScreenshot: true }),
|
|
170
|
+
hideKeyboard: () => runStep("hideKeyboard", () => run(driver.hideKeyboard()), { captureScreenshot: true }),
|
|
171
|
+
swipe: (direction, opts) => runStep(`swipe(${direction})`, () => run(coord.swipe(direction, opts)), { captureScreenshot: true }),
|
|
172
|
+
scroll: (direction) => runStep(`scroll(${direction})`, () => run(coord.scroll(direction)), { captureScreenshot: true }),
|
|
173
|
+
launch: (opts) => runStep("launch", () => run(driver.launchApp(appId, opts)), {
|
|
174
|
+
selector: opts,
|
|
175
|
+
captureScreenshot: true
|
|
176
|
+
}),
|
|
177
|
+
stop: () => runStep("stop", () => run(driver.stopApp(appId)), { captureScreenshot: true }),
|
|
178
|
+
kill: () => runStep("kill", () => run(driver.killApp(appId)), { captureScreenshot: true }),
|
|
179
|
+
clearState: () => runStep("clearState", () => run(driver.clearAppState(appId)), { captureScreenshot: true }),
|
|
180
|
+
openLink: (url) => runStep("openLink", () => run(driver.openLink(url)), {
|
|
181
|
+
selector: { url },
|
|
182
|
+
captureScreenshot: true
|
|
183
|
+
}),
|
|
184
|
+
back: () => runStep("back", () => run(driver.back()), { captureScreenshot: true }),
|
|
185
|
+
takeScreenshot: (name) => runScreenshotStep(
|
|
186
|
+
name ? `takeScreenshot(${name})` : "takeScreenshot",
|
|
187
|
+
() => run(driver.takeScreenshot()),
|
|
188
|
+
{ name }
|
|
189
|
+
)
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// src/api/expect.ts
|
|
194
|
+
import { Effect as Effect4 } from "effect";
|
|
195
|
+
function createPromiseExpect(driver, config, recorder) {
|
|
196
|
+
const coord = createCoordinator(driver, config);
|
|
197
|
+
const run = (effect) => Effect4.runPromise(effect);
|
|
198
|
+
const runStep = (command, selector, action) => recorder ? recorder.runStep(command, action, { selector, captureScreenshot: false }) : action();
|
|
199
|
+
return (selector) => ({
|
|
200
|
+
toBeVisible: (opts) => runStep("expect.toBeVisible", selector, () => run(coord.assertVisible(selector, opts)).then(() => {
|
|
201
|
+
})),
|
|
202
|
+
toBeHidden: (opts) => runStep("expect.toBeHidden", selector, () => run(coord.assertHidden(selector, opts))),
|
|
203
|
+
toHaveText: (expected, opts) => runStep(`expect.toHaveText(${JSON.stringify(expected)})`, selector, () => run(coord.assertText(selector, expected, opts)))
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// src/core/artifacts.ts
|
|
208
|
+
import { writeFileSync, mkdirSync } from "fs";
|
|
209
|
+
import { join } from "path";
|
|
210
|
+
import { Effect as Effect5 } from "effect";
|
|
211
|
+
var DEFAULT_ARTIFACT_CONFIG = {
|
|
212
|
+
outputDir: "./spana-output",
|
|
213
|
+
captureOnFailure: true,
|
|
214
|
+
captureOnSuccess: false,
|
|
215
|
+
captureSteps: false,
|
|
216
|
+
screenshot: true,
|
|
217
|
+
uiHierarchy: true
|
|
218
|
+
};
|
|
219
|
+
function safeName(value) {
|
|
220
|
+
return value.replace(/[^a-zA-Z0-9-_]/g, "_").replace(/_+/g, "_").replace(/^_+|_+$/g, "").slice(0, 80) || "artifact";
|
|
221
|
+
}
|
|
222
|
+
function flowArtifactDir(config, flowName, platform) {
|
|
223
|
+
const dir = join(config.outputDir, `${safeName(flowName)}-${platform}`);
|
|
224
|
+
mkdirSync(dir, { recursive: true });
|
|
225
|
+
return dir;
|
|
226
|
+
}
|
|
227
|
+
function createAttachment(name, contentType, path) {
|
|
228
|
+
return { name, contentType, path };
|
|
229
|
+
}
|
|
230
|
+
function resolveArtifactConfig(...configs) {
|
|
231
|
+
return configs.reduce(
|
|
232
|
+
(resolved, config) => ({
|
|
233
|
+
...resolved,
|
|
234
|
+
...config
|
|
235
|
+
}),
|
|
236
|
+
{ ...DEFAULT_ARTIFACT_CONFIG }
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
async function captureArtifacts(driver, config, flowName, platform, status) {
|
|
240
|
+
const shouldCapture = status === "failed" && config.captureOnFailure || status === "passed" && config.captureOnSuccess;
|
|
241
|
+
if (!shouldCapture) return [];
|
|
242
|
+
const attachments = [];
|
|
243
|
+
const dir = flowArtifactDir(config, flowName, platform);
|
|
244
|
+
if (config.screenshot) {
|
|
245
|
+
try {
|
|
246
|
+
const screenshot = await Effect5.runPromise(Effect5.orDie(driver.takeScreenshot()));
|
|
247
|
+
const path = join(dir, "screenshot.png");
|
|
248
|
+
writeFileSync(path, screenshot);
|
|
249
|
+
attachments.push(createAttachment(`${status}-screenshot`, "image/png", path));
|
|
250
|
+
} catch {
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (config.uiHierarchy) {
|
|
254
|
+
try {
|
|
255
|
+
const hierarchy = await Effect5.runPromise(Effect5.orDie(driver.dumpHierarchy()));
|
|
256
|
+
const path = join(dir, "hierarchy.json");
|
|
257
|
+
writeFileSync(path, hierarchy, "utf-8");
|
|
258
|
+
attachments.push(createAttachment(`${status}-hierarchy`, "application/json", path));
|
|
259
|
+
} catch {
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return attachments;
|
|
263
|
+
}
|
|
264
|
+
async function captureStepScreenshot(driver, config, flowName, platform, stepIndex, stepName, screenshot) {
|
|
265
|
+
if (!config.screenshot) return void 0;
|
|
266
|
+
try {
|
|
267
|
+
const dir = join(flowArtifactDir(config, flowName, platform), "steps");
|
|
268
|
+
mkdirSync(dir, { recursive: true });
|
|
269
|
+
const fileName = `${String(stepIndex).padStart(3, "0")}-${safeName(stepName)}.png`;
|
|
270
|
+
const path = join(dir, fileName);
|
|
271
|
+
const bytes = screenshot ?? await Effect5.runPromise(Effect5.orDie(driver.takeScreenshot()));
|
|
272
|
+
writeFileSync(path, bytes);
|
|
273
|
+
return createAttachment(stepName, "image/png", path);
|
|
274
|
+
} catch {
|
|
275
|
+
return void 0;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// src/core/step-recorder.ts
|
|
280
|
+
function errorMessage(error) {
|
|
281
|
+
return error instanceof Error ? error.message : String(error);
|
|
282
|
+
}
|
|
283
|
+
function createStepResult(command, durationMs, status, selector, error, attachments) {
|
|
284
|
+
return {
|
|
285
|
+
command,
|
|
286
|
+
selector,
|
|
287
|
+
status,
|
|
288
|
+
durationMs,
|
|
289
|
+
error,
|
|
290
|
+
attachments: attachments && attachments.length > 0 ? attachments : void 0
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
function createStepRecorder(driver, artifactConfig, flowName, platform) {
|
|
294
|
+
const steps = [];
|
|
295
|
+
return {
|
|
296
|
+
async runStep(command, action, opts) {
|
|
297
|
+
const startedAt = Date.now();
|
|
298
|
+
try {
|
|
299
|
+
const result = await action();
|
|
300
|
+
const attachments = [];
|
|
301
|
+
if (opts?.captureScreenshot && artifactConfig.captureSteps) {
|
|
302
|
+
const attachment = await captureStepScreenshot(
|
|
303
|
+
driver,
|
|
304
|
+
artifactConfig,
|
|
305
|
+
flowName,
|
|
306
|
+
platform,
|
|
307
|
+
steps.length + 1,
|
|
308
|
+
command
|
|
309
|
+
);
|
|
310
|
+
if (attachment) attachments.push(attachment);
|
|
311
|
+
}
|
|
312
|
+
steps.push(
|
|
313
|
+
createStepResult(
|
|
314
|
+
command,
|
|
315
|
+
Date.now() - startedAt,
|
|
316
|
+
"passed",
|
|
317
|
+
opts?.selector,
|
|
318
|
+
void 0,
|
|
319
|
+
attachments
|
|
320
|
+
)
|
|
321
|
+
);
|
|
322
|
+
return result;
|
|
323
|
+
} catch (error) {
|
|
324
|
+
steps.push(
|
|
325
|
+
createStepResult(
|
|
326
|
+
command,
|
|
327
|
+
Date.now() - startedAt,
|
|
328
|
+
"failed",
|
|
329
|
+
opts?.selector,
|
|
330
|
+
errorMessage(error)
|
|
331
|
+
)
|
|
332
|
+
);
|
|
333
|
+
throw error;
|
|
334
|
+
}
|
|
335
|
+
},
|
|
336
|
+
async runScreenshotStep(command, action, opts) {
|
|
337
|
+
const startedAt = Date.now();
|
|
338
|
+
try {
|
|
339
|
+
const screenshot = await action();
|
|
340
|
+
const attachment = await captureStepScreenshot(
|
|
341
|
+
driver,
|
|
342
|
+
artifactConfig,
|
|
343
|
+
flowName,
|
|
344
|
+
platform,
|
|
345
|
+
steps.length + 1,
|
|
346
|
+
opts?.name ?? command,
|
|
347
|
+
screenshot
|
|
348
|
+
);
|
|
349
|
+
steps.push(
|
|
350
|
+
createStepResult(
|
|
351
|
+
command,
|
|
352
|
+
Date.now() - startedAt,
|
|
353
|
+
"passed",
|
|
354
|
+
opts?.selector,
|
|
355
|
+
void 0,
|
|
356
|
+
attachment ? [attachment] : void 0
|
|
357
|
+
)
|
|
358
|
+
);
|
|
359
|
+
return screenshot;
|
|
360
|
+
} catch (error) {
|
|
361
|
+
steps.push(
|
|
362
|
+
createStepResult(
|
|
363
|
+
command,
|
|
364
|
+
Date.now() - startedAt,
|
|
365
|
+
"failed",
|
|
366
|
+
opts?.selector,
|
|
367
|
+
errorMessage(error)
|
|
368
|
+
)
|
|
369
|
+
);
|
|
370
|
+
throw error;
|
|
371
|
+
}
|
|
372
|
+
},
|
|
373
|
+
getSteps() {
|
|
374
|
+
return steps;
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// src/core/engine.ts
|
|
380
|
+
async function executeFlow(flow, driver, config) {
|
|
381
|
+
const start = Date.now();
|
|
382
|
+
const { platform, coordinatorConfig, appId } = config;
|
|
383
|
+
const autoLaunch = flow.config.autoLaunch ?? config.autoLaunch ?? true;
|
|
384
|
+
const timeout = flow.config.timeout ?? config.flowTimeout ?? 6e4;
|
|
385
|
+
const artifactConfig = resolveArtifactConfig(config.artifactConfig, flow.config.artifacts);
|
|
386
|
+
const stepRecorder = createStepRecorder(driver, artifactConfig, flow.name, platform);
|
|
387
|
+
try {
|
|
388
|
+
const app = createPromiseApp(driver, appId, coordinatorConfig, stepRecorder);
|
|
389
|
+
const expect = createPromiseExpect(driver, coordinatorConfig, stepRecorder);
|
|
390
|
+
if (autoLaunch) {
|
|
391
|
+
await app.launch();
|
|
392
|
+
}
|
|
393
|
+
await Promise.race([
|
|
394
|
+
flow.fn({ app, expect, platform }),
|
|
395
|
+
new Promise(
|
|
396
|
+
(_, reject) => setTimeout(() => reject(new Error(`Flow "${flow.name}" timed out after ${timeout}ms`)), timeout)
|
|
397
|
+
)
|
|
398
|
+
]);
|
|
399
|
+
const attachments = await captureArtifacts(driver, artifactConfig, flow.name, platform, "passed");
|
|
400
|
+
return {
|
|
401
|
+
name: flow.name,
|
|
402
|
+
platform,
|
|
403
|
+
status: "passed",
|
|
404
|
+
durationMs: Date.now() - start,
|
|
405
|
+
attachments,
|
|
406
|
+
steps: stepRecorder.getSteps()
|
|
407
|
+
};
|
|
408
|
+
} catch (error) {
|
|
409
|
+
const attachments = await captureArtifacts(driver, artifactConfig, flow.name, platform, "failed");
|
|
410
|
+
return {
|
|
411
|
+
name: flow.name,
|
|
412
|
+
platform,
|
|
413
|
+
status: "failed",
|
|
414
|
+
durationMs: Date.now() - start,
|
|
415
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
416
|
+
attachments,
|
|
417
|
+
steps: stepRecorder.getSteps()
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// src/core/orchestrator.ts
|
|
423
|
+
async function orchestrate(flows, platforms) {
|
|
424
|
+
const start = Date.now();
|
|
425
|
+
const platformResults = await Promise.all(
|
|
426
|
+
platforms.map(async ({ platform, driver, engineConfig }) => {
|
|
427
|
+
const results = [];
|
|
428
|
+
const platformFlows = flows.filter((f) => {
|
|
429
|
+
const fp = f.config.platforms;
|
|
430
|
+
return !fp || fp.includes(platform);
|
|
431
|
+
});
|
|
432
|
+
for (const flow of platformFlows) {
|
|
433
|
+
const result = await executeFlow(flow, driver, engineConfig);
|
|
434
|
+
results.push(result);
|
|
435
|
+
}
|
|
436
|
+
return results;
|
|
437
|
+
})
|
|
438
|
+
);
|
|
439
|
+
const allResults = platformResults.flat();
|
|
440
|
+
return {
|
|
441
|
+
results: allResults,
|
|
442
|
+
totalDurationMs: Date.now() - start,
|
|
443
|
+
passed: allResults.filter((r) => r.status === "passed").length,
|
|
444
|
+
failed: allResults.filter((r) => r.status === "failed").length,
|
|
445
|
+
skipped: allResults.filter((r) => r.status === "skipped").length
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// src/cli/test-command.ts
|
|
450
|
+
async function runTestCommand(opts) {
|
|
451
|
+
let config = {};
|
|
452
|
+
const configPath = resolve(opts.configPath ?? "spana.config.ts");
|
|
453
|
+
const configDir = dirname(configPath);
|
|
454
|
+
try {
|
|
455
|
+
const mod = await import(configPath);
|
|
456
|
+
config = mod.default ?? {};
|
|
457
|
+
} catch {
|
|
458
|
+
}
|
|
459
|
+
const resolveFromConfig = (p) => resolve(configDir, p);
|
|
460
|
+
if (config.artifacts?.outputDir) {
|
|
461
|
+
config.artifacts.outputDir = resolveFromConfig(config.artifacts.outputDir);
|
|
462
|
+
}
|
|
463
|
+
const platforms = opts.platforms.length > 0 ? opts.platforms : config.platforms && config.platforms.length > 0 ? config.platforms : ["web"];
|
|
464
|
+
const reporterNames = opts.reporter?.trim() ? opts.reporter : config.reporters && config.reporters.length > 0 ? config.reporters.join(",") : "console";
|
|
465
|
+
const flowDir = opts.flowPath ?? resolveFromConfig(config.flowDir ?? "./flows");
|
|
466
|
+
const flowPaths = await discoverFlows(flowDir);
|
|
467
|
+
if (flowPaths.length === 0) {
|
|
468
|
+
console.log("No flow files found.");
|
|
469
|
+
return true;
|
|
470
|
+
}
|
|
471
|
+
const flows = [];
|
|
472
|
+
for (const p of flowPaths) {
|
|
473
|
+
flows.push(await loadFlowFile(p));
|
|
474
|
+
}
|
|
475
|
+
const filtered = filterFlows(flows, {
|
|
476
|
+
tags: opts.tags,
|
|
477
|
+
grep: opts.grep,
|
|
478
|
+
platforms
|
|
479
|
+
});
|
|
480
|
+
if (filtered.length === 0) {
|
|
481
|
+
console.log("No flows match the given filters.");
|
|
482
|
+
return true;
|
|
483
|
+
}
|
|
484
|
+
console.log(`Running ${filtered.length} flow(s) on ${platforms.join(", ")}...
|
|
485
|
+
`);
|
|
486
|
+
const platformConfigs = [];
|
|
487
|
+
for (const platform of platforms) {
|
|
488
|
+
if (platform === "web") {
|
|
489
|
+
const webUrl = config.apps?.web?.url ?? "http://localhost:3000";
|
|
490
|
+
const driver = await Effect6.runPromise(
|
|
491
|
+
makePlaywrightDriver({ headless: true, baseUrl: webUrl })
|
|
492
|
+
);
|
|
493
|
+
const engineConfig = {
|
|
494
|
+
appId: webUrl,
|
|
495
|
+
platform: "web",
|
|
496
|
+
coordinatorConfig: {
|
|
497
|
+
parse: parseWebHierarchy,
|
|
498
|
+
defaults: {
|
|
499
|
+
timeout: config.defaults?.waitTimeout,
|
|
500
|
+
pollInterval: config.defaults?.pollInterval
|
|
501
|
+
}
|
|
502
|
+
},
|
|
503
|
+
autoLaunch: true,
|
|
504
|
+
flowTimeout: config.defaults?.waitTimeout ? config.defaults.waitTimeout * 10 : 6e4,
|
|
505
|
+
artifactConfig: config.artifacts
|
|
506
|
+
};
|
|
507
|
+
platformConfigs.push({ platform, driver, engineConfig });
|
|
508
|
+
}
|
|
509
|
+
if (platform === "android") {
|
|
510
|
+
const device = firstAndroidDevice();
|
|
511
|
+
if (!device) {
|
|
512
|
+
console.log("No Android device/emulator connected. Skipping android platform.");
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
515
|
+
const packageName = config.apps?.android?.packageName ?? "";
|
|
516
|
+
const hostPort = 8200 + Math.floor(Math.random() * 100);
|
|
517
|
+
try {
|
|
518
|
+
const conn = await setupUiAutomator2(device.serial, hostPort);
|
|
519
|
+
const driver = await Effect6.runPromise(
|
|
520
|
+
createUiAutomator2Driver(conn.host, conn.port, device.serial, packageName)
|
|
521
|
+
);
|
|
522
|
+
const engineConfig = {
|
|
523
|
+
appId: packageName,
|
|
524
|
+
platform: "android",
|
|
525
|
+
coordinatorConfig: {
|
|
526
|
+
parse: parseAndroidHierarchy,
|
|
527
|
+
defaults: {
|
|
528
|
+
timeout: config.defaults?.waitTimeout,
|
|
529
|
+
pollInterval: config.defaults?.pollInterval
|
|
530
|
+
}
|
|
531
|
+
},
|
|
532
|
+
autoLaunch: true,
|
|
533
|
+
flowTimeout: config.defaults?.waitTimeout ? config.defaults.waitTimeout * 10 : 6e4,
|
|
534
|
+
artifactConfig: config.artifacts
|
|
535
|
+
};
|
|
536
|
+
platformConfigs.push({ platform, driver, engineConfig });
|
|
537
|
+
} catch (e) {
|
|
538
|
+
console.log(
|
|
539
|
+
`Android setup failed on ${device.serial}: ${e instanceof Error ? e.message : e}`
|
|
540
|
+
);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
if (platform === "ios") {
|
|
544
|
+
const bundleId = config.apps?.ios?.bundleId ?? "";
|
|
545
|
+
const simulator = firstIOSSimulatorWithApp(bundleId);
|
|
546
|
+
if (!simulator) {
|
|
547
|
+
console.log("No iOS simulator available. Skipping ios platform.");
|
|
548
|
+
continue;
|
|
549
|
+
}
|
|
550
|
+
if (simulator.state !== "Booted") {
|
|
551
|
+
console.log(`Booting simulator ${simulator.name}...`);
|
|
552
|
+
bootSimulator(simulator.udid);
|
|
553
|
+
}
|
|
554
|
+
const wdaPort = 8100 + Math.floor(Math.random() * 100);
|
|
555
|
+
try {
|
|
556
|
+
const conn = await setupWDA(simulator.udid, wdaPort);
|
|
557
|
+
const driver = await Effect6.runPromise(
|
|
558
|
+
createWDADriver(conn.host, conn.port, bundleId, simulator.udid)
|
|
559
|
+
);
|
|
560
|
+
const engineConfig = {
|
|
561
|
+
appId: bundleId,
|
|
562
|
+
platform: "ios",
|
|
563
|
+
coordinatorConfig: {
|
|
564
|
+
parse: parseIOSHierarchy,
|
|
565
|
+
defaults: {
|
|
566
|
+
timeout: config.defaults?.waitTimeout,
|
|
567
|
+
pollInterval: config.defaults?.pollInterval
|
|
568
|
+
}
|
|
569
|
+
},
|
|
570
|
+
autoLaunch: true,
|
|
571
|
+
flowTimeout: config.defaults?.waitTimeout ? config.defaults.waitTimeout * 10 : 6e4,
|
|
572
|
+
artifactConfig: config.artifacts
|
|
573
|
+
};
|
|
574
|
+
platformConfigs.push({ platform, driver, engineConfig });
|
|
575
|
+
} catch (e) {
|
|
576
|
+
console.log(`iOS setup failed on ${simulator.name}: ${e instanceof Error ? e.message : e}`);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
const result = await orchestrate(filtered, platformConfigs);
|
|
581
|
+
const { createConsoleReporter } = await import("./console-ZH3SUKUO.js");
|
|
582
|
+
const { createJsonReporter } = await import("./json-3TZD6FI5.js");
|
|
583
|
+
const { createJUnitReporter } = await import("./junit-ES66OYVX.js");
|
|
584
|
+
const { createHtmlReporter } = await import("./html-OGRQ5NIX.js");
|
|
585
|
+
const resolvedOutputDir = config.artifacts?.outputDir ?? resolveFromConfig("./spana-output");
|
|
586
|
+
const reporters = reporterNames.split(",").map((r) => {
|
|
587
|
+
switch (r.trim()) {
|
|
588
|
+
case "json":
|
|
589
|
+
return createJsonReporter();
|
|
590
|
+
case "junit":
|
|
591
|
+
return createJUnitReporter(resolvedOutputDir);
|
|
592
|
+
case "html":
|
|
593
|
+
return createHtmlReporter(resolvedOutputDir);
|
|
594
|
+
default:
|
|
595
|
+
return createConsoleReporter();
|
|
596
|
+
}
|
|
597
|
+
});
|
|
598
|
+
for (const r of result.results) {
|
|
599
|
+
const flowResult = {
|
|
600
|
+
...r,
|
|
601
|
+
error: r.error ? { message: r.error.message, stack: r.error.stack } : void 0
|
|
602
|
+
};
|
|
603
|
+
for (const reporter of reporters) {
|
|
604
|
+
if (r.status === "passed") {
|
|
605
|
+
reporter.onFlowPass?.(flowResult);
|
|
606
|
+
} else if (r.status === "failed") {
|
|
607
|
+
reporter.onFlowFail?.(flowResult);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
for (const reporter of reporters) {
|
|
612
|
+
reporter.onRunComplete({
|
|
613
|
+
total: result.results.length,
|
|
614
|
+
passed: result.passed,
|
|
615
|
+
failed: result.failed,
|
|
616
|
+
skipped: result.skipped,
|
|
617
|
+
durationMs: result.totalDurationMs,
|
|
618
|
+
results: result.results.map((r) => ({
|
|
619
|
+
...r,
|
|
620
|
+
error: r.error ? { message: r.error.message, stack: r.error.stack } : void 0
|
|
621
|
+
})),
|
|
622
|
+
platforms
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
for (const pc of platformConfigs) {
|
|
626
|
+
try {
|
|
627
|
+
await Effect6.runPromise(pc.driver.killApp(""));
|
|
628
|
+
} catch {
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
return result.failed === 0;
|
|
632
|
+
}
|
|
633
|
+
export {
|
|
634
|
+
runTestCommand
|
|
635
|
+
};
|
|
636
|
+
//# sourceMappingURL=test-command-F3AEHF2E.js.map
|