spana-test 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -12
- package/dist/accessibility-audit-RS3VIWRT.js +140 -0
- package/dist/accessibility-audit-RS3VIWRT.js.map +1 -0
- package/dist/agent/index.d.ts +8 -26
- package/dist/agent/index.js +12 -15
- package/dist/{allure-PTTVORQ6.js → allure-RNMEYTXS.js} +42 -2
- package/dist/allure-RNMEYTXS.js.map +1 -0
- package/dist/{android-PAPJJWVN.js → android-GFW6OXPQ.js} +16 -2
- package/dist/appium-server-66GVUL24.js +119 -0
- package/dist/appium-server-66GVUL24.js.map +1 -0
- package/dist/baseline-manager-5TIUCNP5.js +38 -0
- package/dist/baseline-manager-5TIUCNP5.js.map +1 -0
- package/dist/chunk-3J4NG7JU.js +80 -0
- package/dist/chunk-3J4NG7JU.js.map +1 -0
- package/dist/{chunk-MRH7SK52.js → chunk-3TRMQCUT.js} +3 -2
- package/dist/chunk-3TRMQCUT.js.map +1 -0
- package/dist/chunk-5245YBLL.js +127 -0
- package/dist/chunk-5245YBLL.js.map +1 -0
- package/dist/{chunk-L7MFJF46.js → chunk-7VOWF42B.js} +29 -5
- package/dist/chunk-7VOWF42B.js.map +1 -0
- package/dist/{chunk-GZK22EIE.js → chunk-EWIR2GVV.js} +54 -1
- package/dist/chunk-EWIR2GVV.js.map +1 -0
- package/dist/{chunk-P7JQRLP4.js → chunk-FJAJ4YNC.js} +14 -2
- package/dist/chunk-FJAJ4YNC.js.map +1 -0
- package/dist/chunk-IHVZKQQW.js +24 -0
- package/dist/chunk-IHVZKQQW.js.map +1 -0
- package/dist/{chunk-S4R4OR7T.js → chunk-KYPLYRKW.js} +67 -72
- package/dist/chunk-KYPLYRKW.js.map +1 -0
- package/dist/{chunk-YBZCOQXJ.js → chunk-LC3QJIHY.js} +196 -67
- package/dist/chunk-LC3QJIHY.js.map +1 -0
- package/dist/{chunk-WQ4GXUUE.js → chunk-MCT4DYDK.js} +353 -84
- package/dist/chunk-MCT4DYDK.js.map +1 -0
- package/dist/chunk-OBCFACUW.js +28 -0
- package/dist/chunk-OBCFACUW.js.map +1 -0
- package/dist/{chunk-AEKDFFPJ.js → chunk-PZYZ4O6D.js} +16 -5
- package/dist/chunk-PZYZ4O6D.js.map +1 -0
- package/dist/{chunk-SFBRFB2N.js → chunk-S5JNNDXS.js} +62 -12
- package/dist/chunk-S5JNNDXS.js.map +1 -0
- package/dist/{chunk-VNYF5BHX.js → chunk-X2TJP7LB.js} +1 -3
- package/dist/{chunk-S2XNAKSO.js → chunk-YAV6KBSW.js} +564 -333
- package/dist/chunk-YAV6KBSW.js.map +1 -0
- package/dist/{chunk-3YR4GUGE.js → chunk-YGHDMA6D.js} +65 -70
- package/dist/chunk-YGHDMA6D.js.map +1 -0
- package/dist/cli.js +40 -25
- package/dist/cli.js.map +1 -1
- package/dist/{compiler-74VGKZO6.js → compiler-X6WTFMYF.js} +15 -7
- package/dist/compiler-X6WTFMYF.js.map +1 -0
- package/dist/config-loader-QM72GKEL.js +9 -0
- package/dist/{console-XWKUTP3D.js → console-7UW7VROK.js} +71 -1
- package/dist/console-7UW7VROK.js.map +1 -0
- package/dist/{discover-KZKXHZZA.js → discover-CAQY6EG6.js} +5 -4
- package/dist/doctor-command-YGQPO7GH.js +71 -0
- package/dist/doctor-command-YGQPO7GH.js.map +1 -0
- package/dist/flow-thjUxXXx.d.ts +168 -0
- package/dist/gherkin/steps.d.ts +2 -2
- package/dist/{html-GE6Q4DCG.js → html-F3X3XPSX.js} +78 -7
- package/dist/html-F3X3XPSX.js.map +1 -0
- package/dist/index.d.ts +4 -8
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/{init-command-GVMRXIMY.js → init-command-U66XCM66.js} +19 -34
- package/dist/init-command-U66XCM66.js.map +1 -0
- package/dist/init-flow-command-PR7J5FBM.js +37 -0
- package/dist/init-flow-command-PR7J5FBM.js.map +1 -0
- package/dist/{installer-YZJ4DV3F.js → installer-PVBSX7UC.js} +3 -4
- package/dist/{ios-ZW6XVNLG.js → ios-JPK43TFZ.js} +11 -4
- package/dist/json-JMRPUVY2.js +20 -0
- package/dist/json-JMRPUVY2.js.map +1 -0
- package/dist/machine-6H25TRTU.js +16 -0
- package/dist/{provider-A57C3MU6.js → provider-YIPU5K42.js} +2 -2
- package/dist/{runner-UXNHVVGG.js → runner-6HK62Q7B.js} +2 -2
- package/dist/screenshot-compare-JFHH2WR4.js +75 -0
- package/dist/screenshot-compare-JFHH2WR4.js.map +1 -0
- package/dist/{server-W7OA3DDN.js → server-PZBRGU7P.js} +362 -55
- package/dist/server-PZBRGU7P.js.map +1 -0
- package/dist/session-2MZVGYAC.js +17 -0
- package/dist/{coordinator-BbUjvvnX.d.ts → storybook-pBOPe_1D.d.ts} +101 -33
- package/dist/{studio-command-6VHTHDUK.js → studio-command-YDWQOMRX.js} +2 -2
- package/dist/{test-command-AHMOZLV4.js → test-command-B2VLWGDK.js} +945 -565
- package/dist/test-command-B2VLWGDK.js.map +1 -0
- package/dist/{validator-35624P7S.js → validator-HZ2A3NEI.js} +3 -6
- package/dist/validator-HZ2A3NEI.js.map +1 -0
- package/package.json +6 -1
- package/studio-dist/assets/index-C-Io44gy.js +193 -0
- package/studio-dist/assets/index-DfM9lK4p.css +1 -0
- package/studio-dist/index.html +2 -2
- package/dist/allure-PTTVORQ6.js.map +0 -1
- package/dist/chunk-3YR4GUGE.js.map +0 -1
- package/dist/chunk-AEKDFFPJ.js.map +0 -1
- package/dist/chunk-BF37W5EG.js +0 -125
- package/dist/chunk-BF37W5EG.js.map +0 -1
- package/dist/chunk-EXLUY7KT.js +0 -21
- package/dist/chunk-EXLUY7KT.js.map +0 -1
- package/dist/chunk-FNDOEMOL.js +0 -62
- package/dist/chunk-FNDOEMOL.js.map +0 -1
- package/dist/chunk-GZK22EIE.js.map +0 -1
- package/dist/chunk-HWFDXIXR.js +0 -183
- package/dist/chunk-HWFDXIXR.js.map +0 -1
- package/dist/chunk-IJIASIX5.js +0 -314
- package/dist/chunk-IJIASIX5.js.map +0 -1
- package/dist/chunk-L7MFJF46.js.map +0 -1
- package/dist/chunk-MRH7SK52.js.map +0 -1
- package/dist/chunk-P7JQRLP4.js.map +0 -1
- package/dist/chunk-S2XNAKSO.js.map +0 -1
- package/dist/chunk-S4R4OR7T.js.map +0 -1
- package/dist/chunk-SFBRFB2N.js.map +0 -1
- package/dist/chunk-WBU34APM.js +0 -38
- package/dist/chunk-WBU34APM.js.map +0 -1
- package/dist/chunk-WQ4GXUUE.js.map +0 -1
- package/dist/chunk-YBZCOQXJ.js.map +0 -1
- package/dist/compiler-74VGKZO6.js.map +0 -1
- package/dist/config-loader-BJJ3IJJ7.js +0 -9
- package/dist/console-XWKUTP3D.js.map +0 -1
- package/dist/doctor-command-T2UX5RV5.js +0 -732
- package/dist/doctor-command-T2UX5RV5.js.map +0 -1
- package/dist/flow-BUC9Mf8W.d.ts +0 -128
- package/dist/html-GE6Q4DCG.js.map +0 -1
- package/dist/init-command-GVMRXIMY.js.map +0 -1
- package/dist/init-flow-command-R76AXF4Z.js +0 -34
- package/dist/init-flow-command-R76AXF4Z.js.map +0 -1
- package/dist/json-KS67BZYU.js +0 -39
- package/dist/json-KS67BZYU.js.map +0 -1
- package/dist/server-W7OA3DDN.js.map +0 -1
- package/dist/session-TMNOKYLG.js +0 -17
- package/dist/test-command-AHMOZLV4.js.map +0 -1
- package/studio-dist/assets/index-DC6DIXfl.js +0 -188
- package/studio-dist/assets/index-DDKsnBwD.css +0 -1
- /package/dist/{android-PAPJJWVN.js.map → android-GFW6OXPQ.js.map} +0 -0
- /package/dist/{chunk-VNYF5BHX.js.map → chunk-X2TJP7LB.js.map} +0 -0
- /package/dist/{config-loader-BJJ3IJJ7.js.map → config-loader-QM72GKEL.js.map} +0 -0
- /package/dist/{discover-KZKXHZZA.js.map → discover-CAQY6EG6.js.map} +0 -0
- /package/dist/{installer-YZJ4DV3F.js.map → installer-PVBSX7UC.js.map} +0 -0
- /package/dist/{ios-ZW6XVNLG.js.map → ios-JPK43TFZ.js.map} +0 -0
- /package/dist/{provider-A57C3MU6.js.map → machine-6H25TRTU.js.map} +0 -0
- /package/dist/{runner-UXNHVVGG.js.map → provider-YIPU5K42.js.map} +0 -0
- /package/dist/{session-TMNOKYLG.js.map → runner-6HK62Q7B.js.map} +0 -0
- /package/dist/{validator-35624P7S.js.map → session-2MZVGYAC.js.map} +0 -0
- /package/dist/{studio-command-6VHTHDUK.js.map → studio-command-YDWQOMRX.js.map} +0 -0
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
connect
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-KYPLYRKW.js";
|
|
4
|
+
import "./chunk-MCT4DYDK.js";
|
|
5
|
+
import "./chunk-YGHDMA6D.js";
|
|
6
6
|
import {
|
|
7
7
|
discoverDevices
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-PZYZ4O6D.js";
|
|
9
|
+
import "./chunk-EWIR2GVV.js";
|
|
10
|
+
import "./chunk-S5JNNDXS.js";
|
|
11
|
+
import "./chunk-OBCFACUW.js";
|
|
9
12
|
import {
|
|
10
13
|
discoverFlows,
|
|
11
14
|
discoverStepFiles,
|
|
12
15
|
filterFlows,
|
|
13
16
|
loadStepFiles,
|
|
14
17
|
loadTestSource
|
|
15
|
-
} from "./chunk-
|
|
16
|
-
import "./chunk-
|
|
17
|
-
import "./chunk-GZK22EIE.js";
|
|
18
|
-
import "./chunk-SFBRFB2N.js";
|
|
19
|
-
import "./chunk-3YR4GUGE.js";
|
|
18
|
+
} from "./chunk-3TRMQCUT.js";
|
|
19
|
+
import "./chunk-YAV6KBSW.js";
|
|
20
20
|
import {
|
|
21
21
|
__require
|
|
22
22
|
} from "./chunk-DGUM43GV.js";
|
|
@@ -65,7 +65,6 @@ function connectOptsFromConfig(platform, config, deviceId) {
|
|
|
65
65
|
opts.baseUrl = config.apps?.web?.url ?? "http://localhost:3000";
|
|
66
66
|
opts.browser = config.execution?.web?.browser;
|
|
67
67
|
opts.storageState = config.execution?.web?.storageState;
|
|
68
|
-
opts.verboseLogging = config.execution?.web?.verboseLogging;
|
|
69
68
|
opts.headless = false;
|
|
70
69
|
} else if (platform === "android") {
|
|
71
70
|
opts.packageName = config.apps?.android?.packageName ?? "";
|
|
@@ -83,39 +82,332 @@ async function getOrCreateSession(platform, config, deviceId) {
|
|
|
83
82
|
sessions.set(key, session);
|
|
84
83
|
return session;
|
|
85
84
|
}
|
|
85
|
+
async function disconnectSession(platform, deviceId) {
|
|
86
|
+
const key = sessionKey(platform, deviceId);
|
|
87
|
+
const session = sessions.get(key);
|
|
88
|
+
sessions.delete(key);
|
|
89
|
+
if (session) {
|
|
90
|
+
await session.disconnect();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
async function runWithRecoveredSession(action, resetSession) {
|
|
94
|
+
try {
|
|
95
|
+
return await action();
|
|
96
|
+
} catch {
|
|
97
|
+
await resetSession();
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
return await action();
|
|
101
|
+
} catch (error) {
|
|
102
|
+
await resetSession();
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
86
106
|
var inspectorInput = z2.object({
|
|
87
107
|
platform: z2.enum(["web", "android", "ios"]),
|
|
88
108
|
deviceId: z2.string().optional()
|
|
89
109
|
});
|
|
90
110
|
var inspectorRouter = {
|
|
91
111
|
screenshot: publicProcedure.input(inspectorInput).handler(async ({ input, context }) => {
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
112
|
+
const data = await runWithRecoveredSession(
|
|
113
|
+
async () => {
|
|
114
|
+
const session = await getOrCreateSession(input.platform, context.config, input.deviceId);
|
|
115
|
+
return session.screenshot();
|
|
116
|
+
},
|
|
117
|
+
() => disconnectSession(input.platform, input.deviceId)
|
|
118
|
+
);
|
|
119
|
+
return { image: Buffer.from(data).toString("base64") };
|
|
96
120
|
}),
|
|
97
121
|
hierarchy: publicProcedure.input(inspectorInput).handler(async ({ input, context }) => {
|
|
98
|
-
|
|
99
|
-
|
|
122
|
+
return runWithRecoveredSession(
|
|
123
|
+
async () => {
|
|
124
|
+
const session = await getOrCreateSession(input.platform, context.config, input.deviceId);
|
|
125
|
+
return session.hierarchy();
|
|
126
|
+
},
|
|
127
|
+
() => disconnectSession(input.platform, input.deviceId)
|
|
128
|
+
);
|
|
100
129
|
}),
|
|
101
130
|
selectors: publicProcedure.input(inspectorInput).handler(async ({ input, context }) => {
|
|
102
|
-
|
|
103
|
-
|
|
131
|
+
return runWithRecoveredSession(
|
|
132
|
+
async () => {
|
|
133
|
+
const session = await getOrCreateSession(input.platform, context.config, input.deviceId);
|
|
134
|
+
return session.selectors();
|
|
135
|
+
},
|
|
136
|
+
() => disconnectSession(input.platform, input.deviceId)
|
|
137
|
+
);
|
|
104
138
|
}),
|
|
105
139
|
disconnect: publicProcedure.input(inspectorInput).handler(async ({ input }) => {
|
|
106
|
-
|
|
107
|
-
const session = sessions.get(key);
|
|
108
|
-
if (session) {
|
|
109
|
-
await session.disconnect();
|
|
110
|
-
sessions.delete(key);
|
|
111
|
-
}
|
|
140
|
+
await disconnectSession(input.platform, input.deviceId);
|
|
112
141
|
return { disconnected: true };
|
|
113
142
|
})
|
|
114
143
|
};
|
|
115
144
|
|
|
116
|
-
// src/studio/routers/
|
|
145
|
+
// src/studio/routers/recording.ts
|
|
117
146
|
import { z as z3 } from "zod";
|
|
118
|
-
import
|
|
147
|
+
import * as fs from "fs/promises";
|
|
148
|
+
import * as path from "path";
|
|
149
|
+
|
|
150
|
+
// src/studio/recording-session.ts
|
|
151
|
+
var _idCounter = 0;
|
|
152
|
+
function generateId(prefix) {
|
|
153
|
+
return `${prefix}-${Date.now()}-${++_idCounter}`;
|
|
154
|
+
}
|
|
155
|
+
var RecordingSessionStore = class {
|
|
156
|
+
sessions = /* @__PURE__ */ new Map();
|
|
157
|
+
start(platform) {
|
|
158
|
+
const session = {
|
|
159
|
+
id: generateId("session"),
|
|
160
|
+
platform,
|
|
161
|
+
status: "recording",
|
|
162
|
+
actions: []
|
|
163
|
+
};
|
|
164
|
+
this.sessions.set(session.id, session);
|
|
165
|
+
return session;
|
|
166
|
+
}
|
|
167
|
+
get(sessionId) {
|
|
168
|
+
return this.sessions.get(sessionId);
|
|
169
|
+
}
|
|
170
|
+
stop(sessionId) {
|
|
171
|
+
const session = this.sessions.get(sessionId);
|
|
172
|
+
if (!session) return void 0;
|
|
173
|
+
session.status = "stopped";
|
|
174
|
+
return session;
|
|
175
|
+
}
|
|
176
|
+
addAction(sessionId, input) {
|
|
177
|
+
const session = this.sessions.get(sessionId);
|
|
178
|
+
if (!session) return void 0;
|
|
179
|
+
const action = { id: generateId("action"), ...input };
|
|
180
|
+
session.actions.push(action);
|
|
181
|
+
return action;
|
|
182
|
+
}
|
|
183
|
+
deleteAction(sessionId, actionId) {
|
|
184
|
+
const session = this.sessions.get(sessionId);
|
|
185
|
+
if (!session) return void 0;
|
|
186
|
+
session.actions = session.actions.filter((a) => a.id !== actionId);
|
|
187
|
+
return session;
|
|
188
|
+
}
|
|
189
|
+
reorderActions(sessionId, orderedIds) {
|
|
190
|
+
const session = this.sessions.get(sessionId);
|
|
191
|
+
if (!session) return void 0;
|
|
192
|
+
const byId = new Map(session.actions.map((a) => [a.id, a]));
|
|
193
|
+
session.actions = orderedIds.flatMap((id) => {
|
|
194
|
+
const action = byId.get(id);
|
|
195
|
+
return action ? [action] : [];
|
|
196
|
+
});
|
|
197
|
+
return session;
|
|
198
|
+
}
|
|
199
|
+
updateSelector(sessionId, actionId, selector) {
|
|
200
|
+
const session = this.sessions.get(sessionId);
|
|
201
|
+
if (!session) return void 0;
|
|
202
|
+
const action = session.actions.find((a) => a.id === actionId);
|
|
203
|
+
if (!action) return void 0;
|
|
204
|
+
action.selector = selector;
|
|
205
|
+
return session;
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
// src/core/flow-generator.ts
|
|
210
|
+
function formatSelector(selector) {
|
|
211
|
+
if (typeof selector === "string") {
|
|
212
|
+
return `"${selector}"`;
|
|
213
|
+
}
|
|
214
|
+
if ("testID" in selector) {
|
|
215
|
+
return `{ testID: "${selector.testID}" }`;
|
|
216
|
+
}
|
|
217
|
+
if ("text" in selector) {
|
|
218
|
+
return `{ text: "${selector.text}" }`;
|
|
219
|
+
}
|
|
220
|
+
if ("accessibilityLabel" in selector) {
|
|
221
|
+
return `{ accessibilityLabel: "${selector.accessibilityLabel}" }`;
|
|
222
|
+
}
|
|
223
|
+
if ("point" in selector) {
|
|
224
|
+
return `{ point: { x: ${selector.point.x}, y: ${selector.point.y} } }`;
|
|
225
|
+
}
|
|
226
|
+
return JSON.stringify(selector);
|
|
227
|
+
}
|
|
228
|
+
function generateActionLine(action) {
|
|
229
|
+
const { type, selector, params } = action;
|
|
230
|
+
if (type === "expect.toBeVisible") {
|
|
231
|
+
const sel = selector ? formatSelector(selector) : "undefined";
|
|
232
|
+
return `await expect(${sel}).toBeVisible();`;
|
|
233
|
+
}
|
|
234
|
+
if (type === "expect.toHaveText") {
|
|
235
|
+
const sel = selector ? formatSelector(selector) : "undefined";
|
|
236
|
+
const expected = typeof params.expected === "string" ? params.expected : String(params.expected);
|
|
237
|
+
return `await expect(${sel}).toHaveText("${expected}");`;
|
|
238
|
+
}
|
|
239
|
+
if (type === "back") {
|
|
240
|
+
return `await app.back();`;
|
|
241
|
+
}
|
|
242
|
+
if (type === "pressKey") {
|
|
243
|
+
const key = typeof params.key === "string" ? params.key : String(params.key);
|
|
244
|
+
return `await app.pressKey("${key}");`;
|
|
245
|
+
}
|
|
246
|
+
if (type === "inputText") {
|
|
247
|
+
const text = typeof params.text === "string" ? params.text : String(params.text);
|
|
248
|
+
if (selector) {
|
|
249
|
+
return `await app.inputText("${text}", ${formatSelector(selector)});`;
|
|
250
|
+
}
|
|
251
|
+
return `await app.inputText("${text}");`;
|
|
252
|
+
}
|
|
253
|
+
if (type === "scroll" || type === "swipe") {
|
|
254
|
+
const direction = typeof params.direction === "string" ? params.direction : String(params.direction);
|
|
255
|
+
if (selector) {
|
|
256
|
+
return `await app.${type}("${direction}", ${formatSelector(selector)});`;
|
|
257
|
+
}
|
|
258
|
+
return `await app.${type}("${direction}");`;
|
|
259
|
+
}
|
|
260
|
+
if (selector) {
|
|
261
|
+
return `await app.${type}(${formatSelector(selector)});`;
|
|
262
|
+
}
|
|
263
|
+
return `await app.${type}();`;
|
|
264
|
+
}
|
|
265
|
+
function generateFlowCode(flowName, actions) {
|
|
266
|
+
const lines = actions.map((action) => ` ${generateActionLine(action)}`);
|
|
267
|
+
const body = lines.length > 0 ? `
|
|
268
|
+
${lines.join("\n")}
|
|
269
|
+
` : "\n";
|
|
270
|
+
return `import { flow } from "spana-test";
|
|
271
|
+
|
|
272
|
+
export default flow("${flowName}", async ({ app, expect }) => {${body}});`;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// src/studio/routers/recording.ts
|
|
276
|
+
var store = new RecordingSessionStore();
|
|
277
|
+
var selectorSchema = z3.union([
|
|
278
|
+
z3.string(),
|
|
279
|
+
z3.object({ testID: z3.string() }),
|
|
280
|
+
z3.object({ text: z3.string() }),
|
|
281
|
+
z3.object({ accessibilityLabel: z3.string() }),
|
|
282
|
+
z3.object({ point: z3.object({ x: z3.number(), y: z3.number() }) })
|
|
283
|
+
]);
|
|
284
|
+
var platformEnum = z3.enum(["web", "android", "ios"]);
|
|
285
|
+
var recordingRouter = {
|
|
286
|
+
start: publicProcedure.input(
|
|
287
|
+
z3.object({
|
|
288
|
+
platform: platformEnum,
|
|
289
|
+
deviceId: z3.string().optional()
|
|
290
|
+
})
|
|
291
|
+
).handler(async ({ input }) => {
|
|
292
|
+
const session = store.start(input.platform);
|
|
293
|
+
return { sessionId: session.id };
|
|
294
|
+
}),
|
|
295
|
+
stop: publicProcedure.input(z3.object({ sessionId: z3.string() })).handler(async ({ input }) => {
|
|
296
|
+
store.stop(input.sessionId);
|
|
297
|
+
}),
|
|
298
|
+
addAction: publicProcedure.input(
|
|
299
|
+
z3.object({
|
|
300
|
+
sessionId: z3.string(),
|
|
301
|
+
action: z3.object({
|
|
302
|
+
type: z3.string(),
|
|
303
|
+
selector: selectorSchema.optional(),
|
|
304
|
+
selectorAlternatives: z3.array(selectorSchema).default([]),
|
|
305
|
+
params: z3.record(z3.string(), z3.unknown()).default({}),
|
|
306
|
+
timestamp: z3.number(),
|
|
307
|
+
screenshotPath: z3.string().optional()
|
|
308
|
+
})
|
|
309
|
+
})
|
|
310
|
+
).handler(async ({ input }) => {
|
|
311
|
+
const action = store.addAction(input.sessionId, input.action);
|
|
312
|
+
if (!action) throw new Error(`Session not found: ${input.sessionId}`);
|
|
313
|
+
return { actionId: action.id };
|
|
314
|
+
}),
|
|
315
|
+
deleteAction: publicProcedure.input(z3.object({ sessionId: z3.string(), actionId: z3.string() })).handler(async ({ input }) => {
|
|
316
|
+
store.deleteAction(input.sessionId, input.actionId);
|
|
317
|
+
}),
|
|
318
|
+
reorderActions: publicProcedure.input(z3.object({ sessionId: z3.string(), actionIds: z3.array(z3.string()) })).handler(async ({ input }) => {
|
|
319
|
+
store.reorderActions(input.sessionId, input.actionIds);
|
|
320
|
+
}),
|
|
321
|
+
updateSelector: publicProcedure.input(
|
|
322
|
+
z3.object({
|
|
323
|
+
sessionId: z3.string(),
|
|
324
|
+
actionId: z3.string(),
|
|
325
|
+
selector: selectorSchema
|
|
326
|
+
})
|
|
327
|
+
).handler(async ({ input }) => {
|
|
328
|
+
store.updateSelector(input.sessionId, input.actionId, input.selector);
|
|
329
|
+
}),
|
|
330
|
+
getSession: publicProcedure.input(z3.object({ sessionId: z3.string() })).handler(async ({ input }) => {
|
|
331
|
+
const session = store.get(input.sessionId);
|
|
332
|
+
if (!session) throw new Error(`Session not found: ${input.sessionId}`);
|
|
333
|
+
return session;
|
|
334
|
+
}),
|
|
335
|
+
generateCode: publicProcedure.input(z3.object({ sessionId: z3.string(), flowName: z3.string() })).handler(async ({ input }) => {
|
|
336
|
+
const session = store.get(input.sessionId);
|
|
337
|
+
if (!session) throw new Error(`Session not found: ${input.sessionId}`);
|
|
338
|
+
const code = generateFlowCode(input.flowName, session.actions);
|
|
339
|
+
return { code };
|
|
340
|
+
}),
|
|
341
|
+
save: publicProcedure.input(
|
|
342
|
+
z3.object({
|
|
343
|
+
sessionId: z3.string(),
|
|
344
|
+
flowName: z3.string(),
|
|
345
|
+
flowDir: z3.string().optional()
|
|
346
|
+
})
|
|
347
|
+
).handler(async ({ input, context }) => {
|
|
348
|
+
const session = store.get(input.sessionId);
|
|
349
|
+
if (!session) throw new Error(`Session not found: ${input.sessionId}`);
|
|
350
|
+
const code = generateFlowCode(input.flowName, session.actions);
|
|
351
|
+
const dir = input.flowDir ?? context.config.flowDir ?? "flows";
|
|
352
|
+
const fileName = `${input.flowName}.ts`;
|
|
353
|
+
const filePath = path.resolve(dir, fileName);
|
|
354
|
+
await fs.mkdir(dir, { recursive: true });
|
|
355
|
+
await fs.writeFile(filePath, code, "utf8");
|
|
356
|
+
return { filePath, code };
|
|
357
|
+
}),
|
|
358
|
+
executeAction: publicProcedure.input(
|
|
359
|
+
z3.object({
|
|
360
|
+
sessionId: z3.string(),
|
|
361
|
+
platform: platformEnum,
|
|
362
|
+
deviceId: z3.string().optional(),
|
|
363
|
+
actionType: z3.string(),
|
|
364
|
+
selector: selectorSchema.optional(),
|
|
365
|
+
params: z3.record(z3.string(), z3.unknown()).optional()
|
|
366
|
+
})
|
|
367
|
+
).handler(async ({ input, context }) => {
|
|
368
|
+
const agentSession = await getOrCreateSession(input.platform, context.config, input.deviceId);
|
|
369
|
+
const sel = input.selector;
|
|
370
|
+
const params = input.params ?? {};
|
|
371
|
+
switch (input.actionType) {
|
|
372
|
+
case "tap":
|
|
373
|
+
if (sel) await agentSession.tap(sel);
|
|
374
|
+
break;
|
|
375
|
+
case "doubleTap":
|
|
376
|
+
if (sel) await agentSession.doubleTap(sel);
|
|
377
|
+
break;
|
|
378
|
+
case "longPress":
|
|
379
|
+
if (sel) await agentSession.longPress(sel);
|
|
380
|
+
break;
|
|
381
|
+
case "inputText":
|
|
382
|
+
await agentSession.inputText(String(params.text ?? ""));
|
|
383
|
+
break;
|
|
384
|
+
case "scroll":
|
|
385
|
+
await agentSession.scroll(
|
|
386
|
+
String(params.direction ?? "down")
|
|
387
|
+
);
|
|
388
|
+
break;
|
|
389
|
+
case "swipe":
|
|
390
|
+
await agentSession.swipe(
|
|
391
|
+
String(params.direction ?? "left")
|
|
392
|
+
);
|
|
393
|
+
break;
|
|
394
|
+
case "pressKey":
|
|
395
|
+
await agentSession.pressKey(String(params.key ?? ""));
|
|
396
|
+
break;
|
|
397
|
+
case "back":
|
|
398
|
+
await agentSession.back();
|
|
399
|
+
break;
|
|
400
|
+
default:
|
|
401
|
+
break;
|
|
402
|
+
}
|
|
403
|
+
const selectorAlternatives = await agentSession.selectors();
|
|
404
|
+
return { selectorAlternatives };
|
|
405
|
+
})
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
// src/studio/routers/tests.ts
|
|
409
|
+
import { z as z4 } from "zod";
|
|
410
|
+
import { resolve as resolve2 } from "path";
|
|
119
411
|
var mapAttachments = (atts) => atts?.filter((a) => a.contentType === "image/png").map((a) => {
|
|
120
412
|
const match = a.path.match(/spana-output\/(.+)$/);
|
|
121
413
|
const relativePath = match ? match[1] : a.path;
|
|
@@ -139,13 +431,29 @@ function nextRunId() {
|
|
|
139
431
|
runCounter += 1;
|
|
140
432
|
return `run-${Date.now()}-${runCounter}`;
|
|
141
433
|
}
|
|
142
|
-
var
|
|
434
|
+
var platformEnum2 = z4.enum(["web", "android", "ios"]);
|
|
435
|
+
function buildDeviceSelectionArgs(devices) {
|
|
436
|
+
if (!devices || devices.length === 0) {
|
|
437
|
+
return [];
|
|
438
|
+
}
|
|
439
|
+
const selectedPlatforms = new Set(devices.map((device) => device.platform));
|
|
440
|
+
const explicitlyTargeted = devices.filter(
|
|
441
|
+
(device) => Boolean(device.deviceId)
|
|
442
|
+
);
|
|
443
|
+
const explicitPlatforms = new Set(explicitlyTargeted.map((device) => device.platform));
|
|
444
|
+
const explicitDeviceIds = [...new Set(explicitlyTargeted.map((device) => device.deviceId))];
|
|
445
|
+
if (explicitDeviceIds.length === 0) {
|
|
446
|
+
return [];
|
|
447
|
+
}
|
|
448
|
+
const canUseSingleDeviceFlag = explicitDeviceIds.length === 1 && explicitPlatforms.size === 1 && selectedPlatforms.size === explicitPlatforms.size;
|
|
449
|
+
return canUseSingleDeviceFlag ? ["--device", explicitDeviceIds[0]] : ["--devices", explicitDeviceIds.join(",")];
|
|
450
|
+
}
|
|
143
451
|
async function discoverAndLoad(flowDir) {
|
|
144
|
-
const dir =
|
|
452
|
+
const dir = resolve2(flowDir);
|
|
145
453
|
try {
|
|
146
454
|
const { execSync } = await import("child_process");
|
|
147
455
|
const script = `
|
|
148
|
-
import { discoverFlows, loadTestSource } from '${
|
|
456
|
+
import { discoverFlows, loadTestSource } from '${resolve2(dir, "../../src/core/runner.ts")}';
|
|
149
457
|
const paths = await discoverFlows('${dir}');
|
|
150
458
|
const flows = [];
|
|
151
459
|
for (const p of paths) {
|
|
@@ -188,11 +496,11 @@ async function discoverAndLoad(flowDir) {
|
|
|
188
496
|
var testsRouter = {
|
|
189
497
|
/** Discover flows and return metadata */
|
|
190
498
|
listFlows: publicProcedure.input(
|
|
191
|
-
|
|
192
|
-
flowDir:
|
|
193
|
-
tags:
|
|
194
|
-
platforms:
|
|
195
|
-
grep:
|
|
499
|
+
z4.object({
|
|
500
|
+
flowDir: z4.string().optional(),
|
|
501
|
+
tags: z4.array(z4.string()).optional(),
|
|
502
|
+
platforms: z4.array(platformEnum2).optional(),
|
|
503
|
+
grep: z4.string().optional()
|
|
196
504
|
}).optional()
|
|
197
505
|
).handler(async ({ input, context }) => {
|
|
198
506
|
const flowDir = input?.flowDir ?? context.config.flowDir ?? "./flows";
|
|
@@ -219,14 +527,14 @@ var testsRouter = {
|
|
|
219
527
|
}),
|
|
220
528
|
/** Start a test run in the background, return a run ID */
|
|
221
529
|
run: publicProcedure.input(
|
|
222
|
-
|
|
223
|
-
platforms:
|
|
224
|
-
flowDir:
|
|
225
|
-
tags:
|
|
226
|
-
grep:
|
|
227
|
-
captureScreenshots:
|
|
228
|
-
captureSteps:
|
|
229
|
-
devices:
|
|
530
|
+
z4.object({
|
|
531
|
+
platforms: z4.array(platformEnum2).min(1),
|
|
532
|
+
flowDir: z4.string().optional(),
|
|
533
|
+
tags: z4.array(z4.string()).optional(),
|
|
534
|
+
grep: z4.string().optional(),
|
|
535
|
+
captureScreenshots: z4.boolean().optional(),
|
|
536
|
+
captureSteps: z4.boolean().optional(),
|
|
537
|
+
devices: z4.array(z4.object({ platform: platformEnum2, deviceId: z4.string().optional() })).optional()
|
|
230
538
|
})
|
|
231
539
|
).handler(async ({ input, context }) => {
|
|
232
540
|
const runId = nextRunId();
|
|
@@ -252,7 +560,7 @@ var testsRouter = {
|
|
|
252
560
|
const flowDir = input.flowDir ?? context.config.flowDir ?? "./flows";
|
|
253
561
|
try {
|
|
254
562
|
const { spawn } = await import("child_process");
|
|
255
|
-
const cliPath =
|
|
563
|
+
const cliPath = resolve2(process.argv[1]);
|
|
256
564
|
const args = [
|
|
257
565
|
cliPath,
|
|
258
566
|
"test",
|
|
@@ -268,18 +576,16 @@ var testsRouter = {
|
|
|
268
576
|
if (input.tags && input.tags.length > 0) {
|
|
269
577
|
args.push("--tag", input.tags.join(","));
|
|
270
578
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
}
|
|
277
|
-
}
|
|
579
|
+
args.push(
|
|
580
|
+
...buildDeviceSelectionArgs(
|
|
581
|
+
input.devices
|
|
582
|
+
)
|
|
583
|
+
);
|
|
278
584
|
let tmpConfig;
|
|
279
585
|
if (input.captureScreenshots || input.captureSteps) {
|
|
280
586
|
const { writeFileSync } = await import("fs");
|
|
281
587
|
const { tmpdir } = await import("os");
|
|
282
|
-
tmpConfig =
|
|
588
|
+
tmpConfig = resolve2(tmpdir(), `spana-studio-${runId}.config.js`);
|
|
283
589
|
const originalConfig = context.config;
|
|
284
590
|
const configObj = {
|
|
285
591
|
...originalConfig,
|
|
@@ -296,7 +602,7 @@ var testsRouter = {
|
|
|
296
602
|
args.push("--config", tmpConfig);
|
|
297
603
|
}
|
|
298
604
|
const child = spawn("bun", args, {
|
|
299
|
-
cwd:
|
|
605
|
+
cwd: resolve2("."),
|
|
300
606
|
stdio: ["ignore", "pipe", "pipe"]
|
|
301
607
|
});
|
|
302
608
|
activeChildren.add(child);
|
|
@@ -387,7 +693,7 @@ var testsRouter = {
|
|
|
387
693
|
return { runId };
|
|
388
694
|
}),
|
|
389
695
|
/** Poll for run progress */
|
|
390
|
-
status: publicProcedure.input(
|
|
696
|
+
status: publicProcedure.input(z4.object({ runId: z4.string() })).handler(({ input }) => {
|
|
391
697
|
const run = activeRuns.get(input.runId);
|
|
392
698
|
if (!run) {
|
|
393
699
|
return { status: "not_found", results: [], progress: {} };
|
|
@@ -407,7 +713,7 @@ var testsRouter = {
|
|
|
407
713
|
};
|
|
408
714
|
}),
|
|
409
715
|
/** Get final results for a completed run */
|
|
410
|
-
results: publicProcedure.input(
|
|
716
|
+
results: publicProcedure.input(z4.object({ runId: z4.string() })).handler(({ input }) => {
|
|
411
717
|
const run = activeRuns.get(input.runId);
|
|
412
718
|
if (!run || run.status !== "completed") {
|
|
413
719
|
return null;
|
|
@@ -420,6 +726,7 @@ var testsRouter = {
|
|
|
420
726
|
var studioRouter = {
|
|
421
727
|
devices: devicesRouter,
|
|
422
728
|
inspector: inspectorRouter,
|
|
729
|
+
recording: recordingRouter,
|
|
423
730
|
tests: testsRouter
|
|
424
731
|
};
|
|
425
732
|
|
|
@@ -527,4 +834,4 @@ async function startStudio(options) {
|
|
|
527
834
|
export {
|
|
528
835
|
startStudio
|
|
529
836
|
};
|
|
530
|
-
//# sourceMappingURL=server-
|
|
837
|
+
//# sourceMappingURL=server-PZBRGU7P.js.map
|